feat: add Consensus to ExecutionStage (#14447)

This commit is contained in:
Arsenii Kulikov
2025-02-12 18:48:14 +04:00
committed by GitHub
parent 3e07d65751
commit 172369afd5
31 changed files with 355 additions and 194 deletions

View File

@ -18,7 +18,7 @@ use reth_db::DatabaseEnv;
use reth_ethereum_cli::chainspec::EthereumChainSpecParser;
use reth_network::EthNetworkPrimitives;
use reth_node_builder::{NodeBuilder, WithLaunchContext};
use reth_node_ethereum::{EthExecutorProvider, EthereumNode};
use reth_node_ethereum::{consensus::EthBeaconConsensus, EthExecutorProvider, EthereumNode};
use reth_node_metrics::recorder::install_prometheus_recorder;
use reth_tracing::FileWorkerGuard;
use std::{ffi::OsString, fmt, future::Future, sync::Arc};
@ -152,6 +152,9 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>, Ext: clap::Args + fmt::Debug> Cl
let _ = install_prometheus_recorder();
let runner = CliRunner::default();
let components = |spec: Arc<C::ChainSpec>| {
(EthExecutorProvider::ethereum(spec.clone()), EthBeaconConsensus::new(spec))
};
match self.command {
Commands::Node(command) => {
runner.run_command_until_exit(|ctx| command.execute(ctx, launcher))
@ -162,18 +165,15 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>, Ext: clap::Args + fmt::Debug> Cl
Commands::InitState(command) => {
runner.run_blocking_until_ctrl_c(command.execute::<EthereumNode>())
}
Commands::Import(command) => runner.run_blocking_until_ctrl_c(
command.execute::<EthereumNode, _, _>(EthExecutorProvider::ethereum),
),
Commands::Import(command) => {
runner.run_blocking_until_ctrl_c(command.execute::<EthereumNode, _, _>(components))
}
Commands::DumpGenesis(command) => runner.run_blocking_until_ctrl_c(command.execute()),
Commands::Db(command) => {
runner.run_blocking_until_ctrl_c(command.execute::<EthereumNode>())
}
Commands::Stage(command) => runner.run_command_until_exit(|ctx| {
command.execute::<EthereumNode, _, _, EthNetworkPrimitives>(
ctx,
EthExecutorProvider::ethereum,
)
command.execute::<EthereumNode, _, _, EthNetworkPrimitives>(ctx, components)
}),
Commands::P2P(command) => {
runner.run_until_ctrl_c(command.execute::<EthNetworkPrimitives>())

View File

@ -1,6 +1,6 @@
//! Command for debugging execution.
use crate::{api::BlockTy, args::NetworkArgs, utils::get_single_header};
use crate::{args::NetworkArgs, utils::get_single_header};
use alloy_eips::BlockHashOrNumber;
use alloy_primitives::{BlockNumber, B256};
use clap::Parser;
@ -11,7 +11,7 @@ use reth_cli_commands::common::{AccessRights, CliNodeTypes, Environment, Environ
use reth_cli_runner::CliContext;
use reth_cli_util::get_secret_key;
use reth_config::Config;
use reth_consensus::Consensus;
use reth_consensus::FullConsensus;
use reth_db::DatabaseEnv;
use reth_downloaders::{
bodies::bodies::BodiesDownloaderBuilder,
@ -64,7 +64,7 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
&self,
config: &Config,
client: Client,
consensus: Arc<dyn Consensus<BlockTy<N>, Error = ConsensusError>>,
consensus: Arc<dyn FullConsensus<N::Primitives, Error = ConsensusError>>,
provider_factory: ProviderFactory<N>,
task_executor: &TaskExecutor,
static_file_producer: StaticFileProducer<ProviderFactory<N>>,
@ -79,7 +79,7 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
.into_task_with(task_executor);
let body_downloader = BodiesDownloaderBuilder::new(config.stages.bodies)
.build(client, Arc::clone(&consensus), provider_factory.clone())
.build(client, consensus.clone().as_consensus(), provider_factory.clone())
.into_task_with(task_executor);
let stage_conf = &config.stages;
@ -94,7 +94,7 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
DefaultStages::new(
provider_factory.clone(),
tip_rx,
Arc::clone(&consensus),
consensus.clone(),
header_downloader,
body_downloader,
executor.clone(),
@ -103,6 +103,7 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
)
.set(ExecutionStage::new(
executor,
consensus.clone(),
ExecutionStageThresholds {
max_blocks: None,
max_changes: None,
@ -171,7 +172,7 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
let Environment { provider_factory, config, data_dir } =
self.env.init::<N>(AccessRights::RW)?;
let consensus: Arc<dyn Consensus<BlockTy<N>, Error = ConsensusError>> =
let consensus: Arc<dyn FullConsensus<N::Primitives, Error = ConsensusError>> =
Arc::new(EthBeaconConsensus::new(provider_factory.chain_spec()));
// Configure and build network
@ -195,7 +196,7 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
let mut pipeline = self.build_pipeline(
&config,
fetch_client.clone(),
Arc::clone(&consensus),
consensus.clone(),
provider_factory.clone(),
&ctx.task_executor,
static_file_producer,

View File

@ -1,5 +1,5 @@
//! Command for debugging merkle tree calculation.
use crate::{args::NetworkArgs, utils::get_single_header};
use crate::{args::NetworkArgs, providers::ExecutionOutcome, utils::get_single_header};
use alloy_consensus::BlockHeader;
use alloy_eips::BlockHashOrNumber;
use backon::{ConstantBuilder, Retryable};
@ -14,7 +14,7 @@ use reth_consensus::{Consensus, ConsensusError};
use reth_db::tables;
use reth_db_api::{cursor::DbCursorRO, transaction::DbTx};
use reth_ethereum_primitives::EthPrimitives;
use reth_evm::execute::{BatchExecutor, BlockExecutorProvider};
use reth_evm::execute::{BlockExecutorProvider, Executor};
use reth_network::{BlockDownloaderProvider, NetworkHandle};
use reth_network_api::NetworkInfo;
use reth_network_p2p::full_block::FullBlockClient;
@ -161,14 +161,12 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
provider_rw.insert_block(sealed_block.clone(), StorageLocation::Database)?;
td += sealed_block.difficulty();
let mut executor = executor_provider.batch_executor(StateProviderDatabase::new(
LatestStateProviderRef::new(&provider_rw),
));
executor.execute_and_verify_one(&sealed_block)?;
let execution_outcome = executor.finalize();
let executor = executor_provider
.executor(StateProviderDatabase::new(LatestStateProviderRef::new(&provider_rw)));
let output = executor.execute(&sealed_block)?;
provider_rw.write_state(
&execution_outcome,
&ExecutionOutcome::single(block_number, output),
OriginalValuesKnown::Yes,
StorageLocation::Database,
)?;