MockChainAndReorganisationMonitor

Documentation for eth_defi.event_reader.reorganisation_monitor.MockChainAndReorganisationMonitor Python class.

class MockChainAndReorganisationMonitor[source]

A dummy reorganisation monitor for unit testing.

  • Simulate block production and chain reorgs by minor forks, like a real blockchain.

  • We get the explicit control to introduce simulated forks

Attributes summary

check_depth

How many blocks we replay from the blockchain to detect any chain organisations

last_block_read

Last block served by update_chain() in the duty cycle

max_cycle_tries

How many times we try to re-read data from the blockchain in the case of reorganisation.

reorg_wait_seconds

How long we allow our node to catch up in the case there has been a change in the chain tip.

simulated_block_number

Next available block number

Methods summary

__init__([block_number, block_duration_seconds])

add_block(record)

Add new block to header tracking.

check_block_reorg(block_number, block_hash)

Check that newly read block matches our record.

fetch_block_data(start_block, end_block)

Read the new block headers.

figure_reorganisation_and_new_blocks([max_range])

Compare the local block database against the live data from chain.

get_block_by_number(block_number)

Get block header data for a specific block number from our memory buffer.

get_block_timestamp(block_number)

Return UNIX UTC timestamp of a block.

get_block_timestamp_as_pandas(block_number)

Return UNIX UTC timestamp of a block.

get_last_block_live()

Get last block number

get_last_block_read()

Get the number of the last block served by update_chain().

has_data()

Do we have any data available yet.

load(block_map)

load_initial_block_headers([block_count, ...])

Get the initial block buffer filled up.

load_pandas(df)

Load block header data from Pandas data frame.

produce_blocks([block_count])

Populate the fake blocks in mock chain.

produce_fork(block_number[, fork_marker])

Mock a fork int he chain.

restore(block_map)

Restore the chain state from a saved data.

skip_to_block(block_number)

Skip scanning initial chain and directly start from a certain block.

to_pandas([partition_size])

Convert the data to Pandas DataFrame format for storing.

truncate(latest_good_block)

Delete data after a block number because chain reorg happened.

update_chain()

Update the internal memory buffer of block headers from the blockchain node.

__init__(block_number=1, block_duration_seconds=1, **kwargs)[source]
Parameters

block_number (int) –

simulated_block_number

Next available block number

produce_blocks(block_count=1)[source]

Populate the fake blocks in mock chain.

These blocks will be “read” in py:meth:figure_reorganisation_and_new_blocks.

produce_fork(block_number, fork_marker='0x8888')[source]

Mock a fork int he chain.

Parameters

block_number (int) –

get_last_block_live()[source]

Get last block number

fetch_block_data(start_block, end_block)[source]

Read the new block headers.

Parameters
  • start_block – The first block where to read (inclusive)

  • end_block – The block where to read (inclusive)

Return type

Iterable[eth_defi.event_reader.block_header.BlockHeader]