Trait BlockchainTreeEngine
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
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§
fn buffer_block(
&self,
block: SealedBlockWithSenders,
) -> Result<(), InsertBlockError>
fn buffer_block( &self, block: SealedBlockWithSenders, ) -> Result<(), InsertBlockError>
Buffer block with senders
fn 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.
fn finalize_block(&self, finalized_block: u64) -> Result<(), ProviderError>
fn finalize_block(&self, finalized_block: u64) -> Result<(), ProviderError>
Finalize blocks up until and including finalized_block
, and remove them from the tree.
fn connect_buffered_blocks_to_canonical_hashes_and_finalize(
&self,
last_finalized_block: u64,
) -> Result<(), CanonicalError>
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
).
fn update_block_hashes_and_clear_buffered(
&self,
) -> Result<BTreeMap<u64, FixedBytes<32>>, CanonicalError>
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.
fn 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.
fn make_canonical(
&self,
block_hash: FixedBytes<32>,
) -> Result<CanonicalOutcome, 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 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.
fn 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.