mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: integrate ExecutorProvider (#7798)
This commit is contained in:
@ -7,6 +7,7 @@ use super::externals::TreeExternals;
|
||||
use crate::BundleStateDataRef;
|
||||
use reth_consensus::{Consensus, ConsensusError};
|
||||
use reth_db::database::Database;
|
||||
use reth_evm::execute::{BlockExecutionOutput, BlockExecutorProvider, Executor};
|
||||
use reth_interfaces::{
|
||||
blockchain_tree::{
|
||||
error::{BlockchainTreeError, InsertBlockErrorKind},
|
||||
@ -15,13 +16,14 @@ use reth_interfaces::{
|
||||
RethResult,
|
||||
};
|
||||
use reth_primitives::{
|
||||
BlockHash, BlockNumber, ForkBlock, GotExpected, SealedBlockWithSenders, SealedHeader, U256,
|
||||
BlockHash, BlockNumber, ForkBlock, GotExpected, Receipts, SealedBlockWithSenders, SealedHeader,
|
||||
U256,
|
||||
};
|
||||
use reth_provider::{
|
||||
providers::{BundleStateProvider, ConsistentDbView},
|
||||
BundleStateDataProvider, BundleStateWithReceipts, Chain, ExecutorFactory, ProviderError,
|
||||
StateRootProvider,
|
||||
BundleStateDataProvider, BundleStateWithReceipts, Chain, ProviderError, StateRootProvider,
|
||||
};
|
||||
use reth_revm::database::StateProviderDatabase;
|
||||
use reth_trie::updates::TrieUpdates;
|
||||
use reth_trie_parallel::parallel_root::ParallelStateRoot;
|
||||
use std::{
|
||||
@ -66,18 +68,18 @@ impl AppendableChain {
|
||||
///
|
||||
/// if [BlockValidationKind::Exhaustive] is specified, the method will verify the state root of
|
||||
/// the block.
|
||||
pub fn new_canonical_fork<DB, EF>(
|
||||
pub fn new_canonical_fork<DB, E>(
|
||||
block: SealedBlockWithSenders,
|
||||
parent_header: &SealedHeader,
|
||||
canonical_block_hashes: &BTreeMap<BlockNumber, BlockHash>,
|
||||
canonical_fork: ForkBlock,
|
||||
externals: &TreeExternals<DB, EF>,
|
||||
externals: &TreeExternals<DB, E>,
|
||||
block_attachment: BlockAttachment,
|
||||
block_validation_kind: BlockValidationKind,
|
||||
) -> Result<Self, InsertBlockErrorKind>
|
||||
where
|
||||
DB: Database + Clone,
|
||||
EF: ExecutorFactory,
|
||||
E: BlockExecutorProvider,
|
||||
{
|
||||
let state = BundleStateWithReceipts::default();
|
||||
let empty = BTreeMap::new();
|
||||
@ -104,18 +106,18 @@ impl AppendableChain {
|
||||
/// Create a new chain that forks off of an existing sidechain.
|
||||
///
|
||||
/// This differs from [AppendableChain::new_canonical_fork] in that this starts a new fork.
|
||||
pub(crate) fn new_chain_fork<DB, EF>(
|
||||
pub(crate) fn new_chain_fork<DB, E>(
|
||||
&self,
|
||||
block: SealedBlockWithSenders,
|
||||
side_chain_block_hashes: BTreeMap<BlockNumber, BlockHash>,
|
||||
canonical_block_hashes: &BTreeMap<BlockNumber, BlockHash>,
|
||||
canonical_fork: ForkBlock,
|
||||
externals: &TreeExternals<DB, EF>,
|
||||
externals: &TreeExternals<DB, E>,
|
||||
block_validation_kind: BlockValidationKind,
|
||||
) -> Result<Self, InsertBlockErrorKind>
|
||||
where
|
||||
DB: Database + Clone,
|
||||
EF: ExecutorFactory,
|
||||
E: BlockExecutorProvider,
|
||||
{
|
||||
let parent_number = block.number - 1;
|
||||
let parent = self.blocks().get(&parent_number).ok_or(
|
||||
@ -166,18 +168,18 @@ impl AppendableChain {
|
||||
/// - [BlockAttachment] represents if the block extends the canonical chain, and thus we can
|
||||
/// cache the trie state updates.
|
||||
/// - [BlockValidationKind] determines if the state root __should__ be validated.
|
||||
fn validate_and_execute<BSDP, DB, EVM>(
|
||||
fn validate_and_execute<BSDP, DB, E>(
|
||||
block: SealedBlockWithSenders,
|
||||
parent_block: &SealedHeader,
|
||||
bundle_state_data_provider: BSDP,
|
||||
externals: &TreeExternals<DB, EVM>,
|
||||
externals: &TreeExternals<DB, E>,
|
||||
block_attachment: BlockAttachment,
|
||||
block_validation_kind: BlockValidationKind,
|
||||
) -> RethResult<(BundleStateWithReceipts, Option<TrieUpdates>)>
|
||||
where
|
||||
BSDP: BundleStateDataProvider,
|
||||
DB: Database + Clone,
|
||||
EVM: ExecutorFactory,
|
||||
E: BlockExecutorProvider,
|
||||
{
|
||||
// some checks are done before blocks comes here.
|
||||
externals.consensus.validate_header_against_parent(&block, parent_block)?;
|
||||
@ -203,11 +205,17 @@ impl AppendableChain {
|
||||
|
||||
let provider = BundleStateProvider::new(state_provider, bundle_state_data_provider);
|
||||
|
||||
let mut executor = externals.executor_factory.with_state(&provider);
|
||||
let db = StateProviderDatabase::new(&provider);
|
||||
let executor = externals.executor_factory.executor(db);
|
||||
let block_hash = block.hash();
|
||||
let block = block.unseal();
|
||||
executor.execute_and_verify_receipt(&block, U256::MAX)?;
|
||||
let bundle_state = executor.take_output_state();
|
||||
let state = executor.execute((&block, U256::MAX).into())?;
|
||||
let BlockExecutionOutput { state, receipts, .. } = state;
|
||||
let bundle_state = BundleStateWithReceipts::new(
|
||||
state,
|
||||
Receipts::from_block_receipt(receipts),
|
||||
block.number,
|
||||
);
|
||||
|
||||
// check state root if the block extends the canonical chain __and__ if state root
|
||||
// validation was requested.
|
||||
@ -259,19 +267,19 @@ impl AppendableChain {
|
||||
/// __not__ the canonical head.
|
||||
#[track_caller]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn append_block<DB, EF>(
|
||||
pub(crate) fn append_block<DB, E>(
|
||||
&mut self,
|
||||
block: SealedBlockWithSenders,
|
||||
side_chain_block_hashes: BTreeMap<BlockNumber, BlockHash>,
|
||||
canonical_block_hashes: &BTreeMap<BlockNumber, BlockHash>,
|
||||
externals: &TreeExternals<DB, EF>,
|
||||
externals: &TreeExternals<DB, E>,
|
||||
canonical_fork: ForkBlock,
|
||||
block_attachment: BlockAttachment,
|
||||
block_validation_kind: BlockValidationKind,
|
||||
) -> Result<(), InsertBlockErrorKind>
|
||||
where
|
||||
DB: Database + Clone,
|
||||
EF: ExecutorFactory,
|
||||
E: BlockExecutorProvider,
|
||||
{
|
||||
let parent_block = self.chain.tip();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user