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
BlockchainTreeEngine::insert_block
: Connect block to chain, execute it and if valid insert block inside tree.BlockchainTreeEngine::finalize_block
: Remove chains that join to now finalized block, as chain becomes invalid.BlockchainTreeEngine::make_canonical
: Check if we have the hash of block that we want to finalize and commit it to db. If we don’t have the block, syncing should start to fetch the blocks from p2p. Do reorg in tables if canonical chain if needed.
Required Methods§
sourcefn buffer_block(
&self,
block: SealedBlockWithSenders,
) -> Result<(), InsertBlockError>
fn buffer_block( &self, block: SealedBlockWithSenders, ) -> Result<(), InsertBlockError>
Buffer block with senders
sourcefn insert_block(
&self,
block: SealedBlockWithSenders,
validation_kind: BlockValidationKind,
) -> Result<InsertPayloadOk, InsertBlockError>
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.
sourcefn finalize_block(&self, finalized_block: BlockNumber) -> ProviderResult<()>
fn finalize_block(&self, finalized_block: BlockNumber) -> ProviderResult<()>
Finalize blocks up until and including finalized_block
, and remove them from the tree.
sourcefn connect_buffered_blocks_to_canonical_hashes_and_finalize(
&self,
last_finalized_block: BlockNumber,
) -> Result<(), CanonicalError>
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
).
sourcefn update_block_hashes_and_clear_buffered(
&self,
) -> Result<BTreeMap<BlockNumber, BlockHash>, CanonicalError>
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.
sourcefn connect_buffered_blocks_to_canonical_hashes(
&self,
) -> Result<(), CanonicalError>
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.
sourcefn make_canonical(
&self,
block_hash: BlockHash,
) -> Result<CanonicalOutcome, CanonicalError>
fn make_canonical( &self, block_hash: BlockHash, ) -> Result<CanonicalOutcome, CanonicalError>
Provided Methods§
sourcefn insert_block_without_senders(
&self,
block: SealedBlock,
validation_kind: BlockValidationKind,
) -> Result<InsertPayloadOk, InsertBlockError>
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.
sourcefn buffer_block_without_senders(
&self,
block: SealedBlock,
) -> Result<(), InsertBlockError>
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.