Module find

Source
Expand description

Finding and reading block hashes and headers, in response to peer requests.

In the functions in this module:

The block write task commits blocks to the finalized state before updating chain with a cached copy of the best non-finalized chain from NonFinalizedState.chain_set. Then the block commit task can commit additional blocks to the finalized state after we’ve cloned the chain.

This means that some blocks can be in both:

  • the cached Chain, and
  • the shared finalized ZebraDb reference.

Functions§

best_relevant_chain 🔒
Do a consistency check by checking the finalized tip before and after all other database queries.
best_tip
Returns the tip of the best chain in the non-finalized or finalized state.
block_locator
Create a block locator from chain and db.
block_locator_heights
Get the heights of the blocks for constructing a block_locator list.
calculate_median_time_past 🔒
Returns the median-time-past for the provided relevant_chain.
chain_contains_hash
Return true if hash is in chain or db.
collect_chain_hashes 🔒
Returns a list of block::Hashes in the chain, following the intersection with the chain.
collect_chain_headers 🔒
Returns a list of block::Headers in the chain, following the intersection with the chain.
depth
Return the depth of block hash from the chain tip. Searches chain for hash, then searches db.
finalized_state_contains_block_hash
Returns the location of the block if present in the finalized state. Returns None if the block hash is not found in the finalized state.
find_chain_hashes
Finds the first hash that’s in the peer’s known_blocks and the chain. Returns a list of hashes that follow that intersection, from the chain.
find_chain_headers
Finds the first hash that’s in the peer’s known_blocks and the chain. Returns a list of headers that follow that intersection, from the chain.
find_chain_height_range 🔒
Returns a range of Heights in the chain, starting after the intersection hash on the chain.
find_chain_intersection 🔒
Find the first hash that’s in the peer’s known_blocks, and in chain or db.
hash_by_height
Return the hash for the block at height, if height is in chain or db.
height_by_hash
Return the height for the block at hash, if hash is in chain or db.
next_median_time_past
Returns the median-time-past of the next block to be added to the best chain in non_finalized_state or db.
non_finalized_state_contains_block_hash
Returns the location of the block if present in the non-finalized state. Returns None if the block hash is not found in the non-finalized state.
tip
Returns the tip of chain. If there is no chain, returns the tip of db.
tip_hash
Returns the tip block::Hash of chain. If there is no chain, returns the tip of db.
tip_height
Returns the tip Height of chain. If there is no chain, returns the tip of db.
tip_with_value_balance
Returns the tip of chain with its ValueBalance. If there is no chain, returns the tip of db.