//! [`ExecutionDataProvider`] implementations used by the tree. use reth_primitives::{BlockHash, BlockNumber, ForkBlock}; use reth_provider::{BlockExecutionForkProvider, ExecutionDataProvider, ExecutionOutcome}; use std::collections::BTreeMap; /// Structure that combines references of required data to be a [`ExecutionDataProvider`]. #[derive(Clone, Debug)] pub struct BundleStateDataRef<'a> { /// The execution outcome after execution of one or more transactions and/or blocks. pub execution_outcome: &'a ExecutionOutcome, /// The blocks in the sidechain. pub sidechain_block_hashes: &'a BTreeMap, /// The blocks in the canonical chain. pub canonical_block_hashes: &'a BTreeMap, /// Canonical fork pub canonical_fork: ForkBlock, } impl<'a> ExecutionDataProvider for BundleStateDataRef<'a> { fn execution_outcome(&self) -> &ExecutionOutcome { self.execution_outcome } fn block_hash(&self, block_number: BlockNumber) -> Option { let block_hash = self.sidechain_block_hashes.get(&block_number).cloned(); if block_hash.is_some() { return block_hash } self.canonical_block_hashes.get(&block_number).cloned() } } impl<'a> BlockExecutionForkProvider for BundleStateDataRef<'a> { fn canonical_fork(&self) -> ForkBlock { self.canonical_fork } } /// Structure that owns the relevant data needs to be a [`ExecutionDataProvider`] #[derive(Clone, Debug)] pub struct ExecutionData { /// Execution outcome. pub execution_outcome: ExecutionOutcome, /// Parent block hashes needs for evm BLOCKHASH opcode. /// NOTE: it does not mean that all hashes are there but all until finalized are there. /// Other hashes can be obtained from provider pub parent_block_hashes: BTreeMap, /// Canonical block where state forked from. pub canonical_fork: ForkBlock, } impl ExecutionDataProvider for ExecutionData { fn execution_outcome(&self) -> &ExecutionOutcome { &self.execution_outcome } fn block_hash(&self, block_number: BlockNumber) -> Option { self.parent_block_hashes.get(&block_number).cloned() } } impl BlockExecutionForkProvider for ExecutionData { fn canonical_fork(&self) -> ForkBlock { self.canonical_fork } }