reth::blockchain_tree

Trait BlockchainTreeEngine

Source
pub trait BlockchainTreeEngine:
    BlockchainTreeViewer
    + Send
    + Sync {
    // Required methods
    fn buffer_block(
        &self,
        block: SealedBlockWithSenders,
    ) -> Result<(), InsertBlockError>;
    fn insert_block(
        &self,
        block: SealedBlockWithSenders,
        validation_kind: BlockValidationKind,
    ) -> Result<InsertPayloadOk, InsertBlockError>;
    fn finalize_block(&self, finalized_block: u64) -> Result<(), ProviderError>;
    fn connect_buffered_blocks_to_canonical_hashes_and_finalize(
        &self,
        last_finalized_block: u64,
    ) -> Result<(), CanonicalError>;
    fn update_block_hashes_and_clear_buffered(
        &self,
    ) -> Result<BTreeMap<u64, FixedBytes<32>>, CanonicalError>;
    fn connect_buffered_blocks_to_canonical_hashes(
        &self,
    ) -> Result<(), CanonicalError>;
    fn make_canonical(
        &self,
        block_hash: FixedBytes<32>,
    ) -> Result<CanonicalOutcome, CanonicalError>;

    // Provided methods
    fn insert_block_without_senders(
        &self,
        block: SealedBlock,
        validation_kind: BlockValidationKind,
    ) -> Result<InsertPayloadOk, InsertBlockError> { ... }
    fn buffer_block_without_senders(
        &self,
        block: SealedBlock,
    ) -> Result<(), InsertBlockError> { ... }
}
Expand description

Required Methods§

Source

fn buffer_block( &self, block: SealedBlockWithSenders, ) -> Result<(), InsertBlockError>

Buffer block with senders

Source

fn insert_block( &self, block: SealedBlockWithSenders, validation_kind: BlockValidationKind, ) -> Result<InsertPayloadOk, InsertBlockError>

Inserts block with senders

The validation_kind parameter controls which validation checks are performed.

Caution: If the block was received from the consensus layer, this should always be called with BlockValidationKind::Exhaustive to validate the state root, if possible to adhere to the engine API spec.

Source

fn finalize_block(&self, finalized_block: u64) -> Result<(), ProviderError>

Finalize blocks up until and including finalized_block, and remove them from the tree.

Source

fn connect_buffered_blocks_to_canonical_hashes_and_finalize( &self, last_finalized_block: u64, ) -> Result<(), CanonicalError>

Reads the last N canonical hashes from the database and updates the block indices of the tree by attempting to connect the buffered blocks to canonical hashes.

N is the maximum of max_reorg_depth and the number of block hashes needed to satisfy the BLOCKHASH opcode in the EVM.

§Note

This finalizes last_finalized_block prior to reading the canonical hashes (using BlockchainTreeEngine::finalize_block).

Source

fn update_block_hashes_and_clear_buffered( &self, ) -> Result<BTreeMap<u64, FixedBytes<32>>, CanonicalError>

Update all block hashes. iterate over present and new list of canonical hashes and compare them. Remove all mismatches, disconnect them, removes all chains and clears all buffered blocks before the tip.

Source

fn connect_buffered_blocks_to_canonical_hashes( &self, ) -> Result<(), CanonicalError>

Reads the last N canonical hashes from the database and updates the block indices of the tree by attempting to connect the buffered blocks to canonical hashes.

N is the maximum of max_reorg_depth and the number of block hashes needed to satisfy the BLOCKHASH opcode in the EVM.

Source

fn make_canonical( &self, block_hash: FixedBytes<32>, ) -> Result<CanonicalOutcome, CanonicalError>

Make a block and its parent chain part of the canonical chain by committing it to the database.

§Note

This unwinds the database if necessary, i.e. if parts of the canonical chain have been re-orged.

§Returns

Returns Ok if the blocks were canonicalized, or if the blocks were already canonical.

Provided Methods§

Source

fn insert_block_without_senders( &self, block: SealedBlock, validation_kind: BlockValidationKind, ) -> Result<InsertPayloadOk, InsertBlockError>

Recover senders and call BlockchainTreeEngine::insert_block.

This will recover all senders of the transactions in the block first, and then try to insert the block.

Source

fn buffer_block_without_senders( &self, block: SealedBlock, ) -> Result<(), InsertBlockError>

Recover senders and call BlockchainTreeEngine::buffer_block.

This will recover all senders of the transactions in the block first, and then try to buffer the block.

Implementors§