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: BlockNumber) -> ProviderResult<()>;
    fn connect_buffered_blocks_to_canonical_hashes_and_finalize(
        &self,
        last_finalized_block: BlockNumber,
    ) -> Result<(), CanonicalError>;
    fn update_block_hashes_and_clear_buffered(
        &self,
    ) -> Result<BTreeMap<BlockNumber, BlockHash>, CanonicalError>;
    fn connect_buffered_blocks_to_canonical_hashes(
        &self,
    ) -> Result<(), CanonicalError>;
    fn make_canonical(
        &self,
        block_hash: BlockHash,
    ) -> 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: BlockNumber) -> ProviderResult<()>

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: BlockNumber, ) -> 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<BlockNumber, BlockHash>, 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: BlockHash, ) -> 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§