Skip to content

Commit

Permalink
feat: integrate ExecutorProvider (paradigmxyz#7798)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored May 3, 2024
1 parent ec45ae6 commit 067b0ff
Show file tree
Hide file tree
Showing 74 changed files with 1,088 additions and 2,028 deletions.
16 changes: 13 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions bin/reth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ reth-primitives = { workspace = true, features = ["arbitrary", "clap"] }
reth-db = { workspace = true, features = ["mdbx"] }
reth-exex.workspace = true
reth-provider = { workspace = true }
reth-evm.workspace = true
reth-revm.workspace = true
reth-stages.workspace = true
reth-interfaces = { workspace = true, features = ["clap"] }
Expand Down
41 changes: 20 additions & 21 deletions bin/reth/src/commands/debug_cmd/build_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{
DatabaseArgs,
},
dirs::{DataDirPath, MaybePlatformPath},
macros::block_executor,
};
use alloy_rlp::Decodable;
use clap::Parser;
Expand All @@ -20,24 +21,24 @@ use reth_blockchain_tree::{
use reth_cli_runner::CliContext;
use reth_consensus::Consensus;
use reth_db::{init_db, DatabaseEnv};
use reth_evm::execute::{BlockExecutionOutput, BlockExecutorProvider, Executor};
use reth_interfaces::RethResult;
use reth_node_api::PayloadBuilderAttributes;
#[cfg(not(feature = "optimism"))]
use reth_node_ethereum::EthEvmConfig;
use reth_payload_builder::database::CachedReads;
use reth_primitives::{
constants::eip4844::{LoadKzgSettingsError, MAINNET_KZG_TRUSTED_SETUP},
fs,
revm_primitives::KzgSettings,
stage::StageId,
Address, BlobTransaction, BlobTransactionSidecar, Bytes, ChainSpec, PooledTransactionsElement,
SealedBlock, SealedBlockWithSenders, Transaction, TransactionSigned, TxEip4844, B256, U256,
Receipts, SealedBlock, SealedBlockWithSenders, Transaction, TransactionSigned, TxEip4844, B256,
U256,
};
use reth_provider::{
providers::BlockchainProvider, BlockHashReader, BlockReader, BlockWriter, ExecutorFactory,
ProviderFactory, StageCheckpointReader, StateProviderFactory,
providers::BlockchainProvider, BlockHashReader, BlockReader, BlockWriter,
BundleStateWithReceipts, ProviderFactory, StageCheckpointReader, StateProviderFactory,
};
use reth_revm::EvmProcessorFactory;
use reth_revm::database::StateProviderDatabase;
#[cfg(feature = "optimism")]
use reth_rpc_types::engine::OptimismPayloadAttributes;
use reth_rpc_types::engine::{BlobsBundleV1, PayloadAttributes};
Expand Down Expand Up @@ -161,18 +162,11 @@ impl Command {

let consensus: Arc<dyn Consensus> = Arc::new(BeaconConsensus::new(Arc::clone(&self.chain)));

#[cfg(feature = "optimism")]
let evm_config = reth_node_optimism::OptimismEvmConfig::default();

#[cfg(not(feature = "optimism"))]
let evm_config = EthEvmConfig::default();
let executor = block_executor!(self.chain.clone());

// configure blockchain tree
let tree_externals = TreeExternals::new(
provider_factory.clone(),
Arc::clone(&consensus),
EvmProcessorFactory::new(self.chain.clone(), evm_config),
);
let tree_externals =
TreeExternals::new(provider_factory.clone(), Arc::clone(&consensus), executor);
let tree = BlockchainTree::new(tree_externals, BlockchainTreeConfig::default(), None)?;
let blockchain_tree = Arc::new(ShareableBlockchainTree::new(tree));

Expand Down Expand Up @@ -309,11 +303,16 @@ impl Command {
let block_with_senders =
SealedBlockWithSenders::new(block.clone(), senders).unwrap();

let executor_factory = EvmProcessorFactory::new(self.chain.clone(), evm_config);
let mut executor = executor_factory.with_state(blockchain_db.latest()?);
executor
.execute_and_verify_receipt(&block_with_senders.clone().unseal(), U256::MAX)?;
let state = executor.take_output_state();
let db = StateProviderDatabase::new(blockchain_db.latest()?);
let executor = block_executor!(self.chain.clone()).executor(db);

let BlockExecutionOutput { state, receipts, .. } =
executor.execute((&block_with_senders.clone().unseal(), U256::MAX).into())?;
let state = BundleStateWithReceipts::new(
state,
Receipts::from_block_receipt(receipts),
block.number,
);
debug!(target: "reth::cli", ?state, "Executed block");

let hashed_state = state.hash_state_slow();
Expand Down
9 changes: 4 additions & 5 deletions bin/reth/src/commands/debug_cmd/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{
DatabaseArgs, NetworkArgs,
},
dirs::{DataDirPath, MaybePlatformPath},
macros::block_executor,
utils::get_single_header,
};
use clap::Parser;
Expand All @@ -25,7 +26,6 @@ use reth_interfaces::p2p::{bodies::client::BodiesClient, headers::client::Header
use reth_network::{NetworkEvents, NetworkHandle};
use reth_network_api::NetworkInfo;
use reth_node_core::init::init_genesis;
use reth_node_ethereum::EthEvmConfig;
use reth_primitives::{
fs, stage::StageId, BlockHashOrNumber, BlockNumber, ChainSpec, PruneModes, B256,
};
Expand Down Expand Up @@ -111,8 +111,7 @@ impl Command {
let stage_conf = &config.stages;

let (tip_tx, tip_rx) = watch::channel(B256::ZERO);
let factory =
reth_revm::EvmProcessorFactory::new(self.chain.clone(), EthEvmConfig::default());
let executor = block_executor!(self.chain.clone());

let header_mode = HeaderSyncMode::Tip(tip_rx);
let pipeline = Pipeline::builder()
Expand All @@ -124,14 +123,14 @@ impl Command {
Arc::clone(&consensus),
header_downloader,
body_downloader,
factory.clone(),
executor.clone(),
stage_conf.etl.clone(),
)
.set(SenderRecoveryStage {
commit_threshold: stage_conf.sender_recovery.commit_threshold,
})
.set(ExecutionStage::new(
factory,
executor,
ExecutionStageThresholds {
max_blocks: None,
max_changes: None,
Expand Down
41 changes: 25 additions & 16 deletions bin/reth/src/commands/debug_cmd/in_memory_merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,25 @@ use crate::{
DatabaseArgs, NetworkArgs,
},
dirs::{DataDirPath, MaybePlatformPath},
macros::block_executor,
utils::{get_single_body, get_single_header},
};
use backon::{ConstantBuilder, Retryable};
use clap::Parser;
use reth_cli_runner::CliContext;
use reth_config::Config;
use reth_db::{init_db, DatabaseEnv};
use reth_evm::execute::{BlockExecutionOutput, BlockExecutorProvider, Executor};
use reth_interfaces::executor::BlockValidationError;
use reth_network::NetworkHandle;
use reth_network_api::NetworkInfo;
use reth_node_ethereum::EthEvmConfig;
use reth_primitives::{fs, stage::StageId, BlockHashOrNumber, ChainSpec};
use reth_primitives::{fs, stage::StageId, BlockHashOrNumber, ChainSpec, Receipts};
use reth_provider::{
AccountExtReader, ExecutorFactory, HashingWriter, HeaderProvider, LatestStateProviderRef,
OriginalValuesKnown, ProviderFactory, StageCheckpointReader, StaticFileProviderFactory,
StorageReader,
AccountExtReader, BundleStateWithReceipts, HashingWriter, HeaderProvider,
LatestStateProviderRef, OriginalValuesKnown, ProviderFactory, StageCheckpointReader,
StaticFileProviderFactory, StorageReader,
};
use reth_revm::database::StateProviderDatabase;
use reth_tasks::TaskExecutor;
use reth_trie::{updates::TrieKey, StateRoot};
use std::{net::SocketAddr, path::PathBuf, sync::Arc};
Expand Down Expand Up @@ -162,24 +164,31 @@ impl Command {
)
.await?;

let executor_factory =
reth_revm::EvmProcessorFactory::new(self.chain.clone(), EthEvmConfig::default());
let mut executor = executor_factory.with_state(LatestStateProviderRef::new(
let db = StateProviderDatabase::new(LatestStateProviderRef::new(
provider.tx_ref(),
factory.static_file_provider(),
));

let executor = block_executor!(self.chain.clone()).executor(db);

let merkle_block_td =
provider.header_td_by_number(merkle_block_number)?.unwrap_or_default();
executor.execute_and_verify_receipt(
&block
.clone()
.unseal()
.with_recovered_senders()
.ok_or(BlockValidationError::SenderRecoveryError)?,
merkle_block_td + block.difficulty,
let BlockExecutionOutput { state, receipts, .. } = executor.execute(
(
&block
.clone()
.unseal()
.with_recovered_senders()
.ok_or(BlockValidationError::SenderRecoveryError)?,
merkle_block_td + block.difficulty,
)
.into(),
)?;
let block_state = executor.take_output_state();
let block_state = BundleStateWithReceipts::new(
state,
Receipts::from_block_receipt(receipts),
block.number,
);

// Unpacked `BundleState::state_root_slow` function
let (in_memory_state_root, in_memory_updates) =
Expand Down
7 changes: 3 additions & 4 deletions bin/reth/src/commands/debug_cmd/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{
DatabaseArgs, NetworkArgs,
},
dirs::{DataDirPath, MaybePlatformPath},
macros::block_executor,
utils::get_single_header,
};
use backon::{ConstantBuilder, Retryable};
Expand All @@ -20,7 +21,6 @@ use reth_exex::ExExManagerHandle;
use reth_interfaces::p2p::full_block::FullBlockClient;
use reth_network::NetworkHandle;
use reth_network_api::NetworkInfo;
use reth_node_ethereum::EthEvmConfig;
use reth_primitives::{
fs,
stage::{StageCheckpoint, StageId},
Expand Down Expand Up @@ -201,10 +201,9 @@ impl Command {
checkpoint.stage_checkpoint.is_some()
});

let factory =
reth_revm::EvmProcessorFactory::new(self.chain.clone(), EthEvmConfig::default());
let executor = block_executor!(self.chain.clone());
let mut execution_stage = ExecutionStage::new(
factory,
executor,
ExecutionStageThresholds {
max_blocks: Some(1),
max_changes: None,
Expand Down
Loading

0 comments on commit 067b0ff

Please sign in to comment.