feat: integrate NodeTypesWithDB (#10698)

Co-authored-by: joshieDo <93316087+joshieDo@users.noreply.github.com>
This commit is contained in:
Arsenii Kulikov
2024-09-05 19:17:28 +04:00
committed by GitHub
parent 5df03fb3c3
commit 5ecc9d2348
99 changed files with 1171 additions and 1143 deletions

View File

@ -17,7 +17,7 @@ use reth_cli_runner::CliRunner;
use reth_db::DatabaseEnv;
use reth_node_builder::{NodeBuilder, WithLaunchContext};
use reth_node_core::args::utils::DefaultChainSpecParser;
use reth_node_ethereum::EthExecutorProvider;
use reth_node_ethereum::{EthExecutorProvider, EthereumNode};
use reth_tracing::FileWorkerGuard;
use std::{ffi::OsString, fmt, future::Future, sync::Arc};
use tracing::info;
@ -148,22 +148,33 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>, Ext: clap::Args + fmt::Debug> Cl
Commands::Node(command) => {
runner.run_command_until_exit(|ctx| command.execute(ctx, launcher))
}
Commands::Init(command) => runner.run_blocking_until_ctrl_c(command.execute()),
Commands::InitState(command) => runner.run_blocking_until_ctrl_c(command.execute()),
Commands::Import(command) => {
runner.run_blocking_until_ctrl_c(command.execute(EthExecutorProvider::ethereum))
Commands::Init(command) => {
runner.run_blocking_until_ctrl_c(command.execute::<EthereumNode>())
}
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::DumpGenesis(command) => runner.run_blocking_until_ctrl_c(command.execute()),
Commands::Db(command) => runner.run_blocking_until_ctrl_c(command.execute()),
Commands::Stage(command) => runner
.run_command_until_exit(|ctx| command.execute(ctx, EthExecutorProvider::ethereum)),
Commands::Db(command) => {
runner.run_blocking_until_ctrl_c(command.execute::<EthereumNode>())
}
Commands::Stage(command) => runner.run_command_until_exit(|ctx| {
command.execute::<EthereumNode, _, _>(ctx, EthExecutorProvider::ethereum)
}),
Commands::P2P(command) => runner.run_until_ctrl_c(command.execute()),
#[cfg(feature = "dev")]
Commands::TestVectors(command) => runner.run_until_ctrl_c(command.execute()),
Commands::Config(command) => runner.run_until_ctrl_c(command.execute()),
Commands::Debug(command) => runner.run_command_until_exit(|ctx| command.execute(ctx)),
Commands::Recover(command) => runner.run_command_until_exit(|ctx| command.execute(ctx)),
Commands::Prune(command) => runner.run_until_ctrl_c(command.execute()),
Commands::Debug(command) => {
runner.run_command_until_exit(|ctx| command.execute::<EthereumNode>(ctx))
}
Commands::Recover(command) => {
runner.run_command_until_exit(|ctx| command.execute::<EthereumNode>(ctx))
}
Commands::Prune(command) => runner.run_until_ctrl_c(command.execute::<EthereumNode>()),
}
}

View File

@ -14,12 +14,11 @@ use reth_cli::chainspec::ChainSpecParser;
use reth_cli_commands::common::{AccessRights, Environment, EnvironmentArgs};
use reth_cli_runner::CliContext;
use reth_consensus::Consensus;
use reth_db::DatabaseEnv;
use reth_errors::RethResult;
use reth_evm::execute::{BlockExecutorProvider, Executor};
use reth_execution_types::ExecutionOutcome;
use reth_fs_util as fs;
use reth_node_api::PayloadBuilderAttributes;
use reth_node_api::{NodeTypesWithDB, NodeTypesWithEngine, PayloadBuilderAttributes};
use reth_node_ethereum::EthExecutorProvider;
use reth_payload_builder::database::CachedReads;
use reth_primitives::{
@ -83,9 +82,9 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
/// Fetches the best block block from the database.
///
/// If the database is empty, returns the genesis block.
fn lookup_best_block(
fn lookup_best_block<N: NodeTypesWithDB<ChainSpec = C::ChainSpec>>(
&self,
factory: ProviderFactory<Arc<DatabaseEnv>>,
factory: ProviderFactory<N>,
) -> RethResult<Arc<SealedBlock>> {
let provider = factory.provider()?;
@ -116,8 +115,11 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
}
/// Execute `debug in-memory-merkle` command
pub async fn execute(self, ctx: CliContext) -> eyre::Result<()> {
let Environment { provider_factory, .. } = self.env.init(AccessRights::RW)?;
pub async fn execute<N: NodeTypesWithEngine<ChainSpec = C::ChainSpec>>(
self,
ctx: CliContext,
) -> eyre::Result<()> {
let Environment { provider_factory, .. } = self.env.init::<N>(AccessRights::RW)?;
let consensus: Arc<dyn Consensus> =
Arc::new(EthBeaconConsensus::new(provider_factory.chain_spec()));

View File

@ -12,7 +12,6 @@ use reth_cli_util::get_secret_key;
use reth_config::Config;
use reth_consensus::Consensus;
use reth_db::DatabaseEnv;
use reth_db_api::database::Database;
use reth_downloaders::{
bodies::bodies::BodiesDownloaderBuilder,
headers::reverse_headers::ReverseHeadersDownloaderBuilder,
@ -21,6 +20,7 @@ use reth_exex::ExExManagerHandle;
use reth_network::{BlockDownloaderProvider, NetworkEventListenerProvider, NetworkHandle};
use reth_network_api::NetworkInfo;
use reth_network_p2p::{headers::client::HeadersClient, BlockClient};
use reth_node_api::{NodeTypesWithDB, NodeTypesWithDBAdapter, NodeTypesWithEngine};
use reth_node_ethereum::EthExecutorProvider;
use reth_primitives::{BlockHashOrNumber, BlockNumber, B256};
use reth_provider::{
@ -57,17 +57,16 @@ pub struct Command<C: ChainSpecParser> {
}
impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
fn build_pipeline<DB, Client>(
fn build_pipeline<N: NodeTypesWithDB<ChainSpec = C::ChainSpec>, Client>(
&self,
config: &Config,
client: Client,
consensus: Arc<dyn Consensus>,
provider_factory: ProviderFactory<DB>,
provider_factory: ProviderFactory<N>,
task_executor: &TaskExecutor,
static_file_producer: StaticFileProducer<DB>,
) -> eyre::Result<Pipeline<DB>>
static_file_producer: StaticFileProducer<N>,
) -> eyre::Result<Pipeline<N>>
where
DB: Database + Unpin + Clone + 'static,
Client: BlockClient + 'static,
{
// building network downloaders using the fetch client
@ -85,7 +84,7 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
let (tip_tx, tip_rx) = watch::channel(B256::ZERO);
let executor = EthExecutorProvider::ethereum(provider_factory.chain_spec());
let pipeline = Pipeline::builder()
let pipeline = Pipeline::<N>::builder()
.with_tip_sender(tip_tx)
.add_stages(
DefaultStages::new(
@ -116,11 +115,11 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
Ok(pipeline)
}
async fn build_network(
async fn build_network<N: NodeTypesWithEngine<ChainSpec = C::ChainSpec>>(
&self,
config: &Config,
task_executor: TaskExecutor,
provider_factory: ProviderFactory<Arc<DatabaseEnv>>,
provider_factory: ProviderFactory<NodeTypesWithDBAdapter<N, Arc<DatabaseEnv>>>,
network_secret_path: PathBuf,
default_peers_path: PathBuf,
) -> eyre::Result<NetworkHandle> {
@ -157,8 +156,12 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
}
/// Execute `execution-debug` command
pub async fn execute(self, ctx: CliContext) -> eyre::Result<()> {
let Environment { provider_factory, config, data_dir } = self.env.init(AccessRights::RW)?;
pub async fn execute<N: NodeTypesWithEngine<ChainSpec = C::ChainSpec>>(
self,
ctx: CliContext,
) -> eyre::Result<()> {
let Environment { provider_factory, config, data_dir } =
self.env.init::<N>(AccessRights::RW)?;
let consensus: Arc<dyn Consensus> =
Arc::new(EthBeaconConsensus::new(provider_factory.chain_spec()));

View File

@ -12,12 +12,12 @@ use reth_cli_commands::common::{AccessRights, Environment, EnvironmentArgs};
use reth_cli_runner::CliContext;
use reth_cli_util::get_secret_key;
use reth_config::Config;
use reth_db::DatabaseEnv;
use reth_errors::BlockValidationError;
use reth_evm::execute::{BlockExecutorProvider, Executor};
use reth_execution_types::ExecutionOutcome;
use reth_network::{BlockDownloaderProvider, NetworkHandle};
use reth_network_api::NetworkInfo;
use reth_node_api::{NodeTypesWithDB, NodeTypesWithEngine};
use reth_node_ethereum::EthExecutorProvider;
use reth_primitives::BlockHashOrNumber;
use reth_provider::{
@ -55,11 +55,11 @@ pub struct Command<C: ChainSpecParser> {
}
impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
async fn build_network(
async fn build_network<N: NodeTypesWithDB<ChainSpec = C::ChainSpec>>(
&self,
config: &Config,
task_executor: TaskExecutor,
provider_factory: ProviderFactory<Arc<DatabaseEnv>>,
provider_factory: ProviderFactory<N>,
network_secret_path: PathBuf,
default_peers_path: PathBuf,
) -> eyre::Result<NetworkHandle> {
@ -77,8 +77,12 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
}
/// Execute `debug in-memory-merkle` command
pub async fn execute(self, ctx: CliContext) -> eyre::Result<()> {
let Environment { provider_factory, config, data_dir } = self.env.init(AccessRights::RW)?;
pub async fn execute<N: NodeTypesWithEngine<ChainSpec = C::ChainSpec>>(
self,
ctx: CliContext,
) -> eyre::Result<()> {
let Environment { provider_factory, config, data_dir } =
self.env.init::<N>(AccessRights::RW)?;
let provider = provider_factory.provider()?;

View File

@ -10,12 +10,13 @@ use reth_cli_runner::CliContext;
use reth_cli_util::get_secret_key;
use reth_config::Config;
use reth_consensus::Consensus;
use reth_db::{tables, DatabaseEnv};
use reth_db::tables;
use reth_db_api::{cursor::DbCursorRO, transaction::DbTx};
use reth_evm::execute::{BatchExecutor, BlockExecutorProvider};
use reth_network::{BlockDownloaderProvider, NetworkHandle};
use reth_network_api::NetworkInfo;
use reth_network_p2p::full_block::FullBlockClient;
use reth_node_api::{NodeTypesWithDB, NodeTypesWithEngine};
use reth_node_ethereum::EthExecutorProvider;
use reth_primitives::BlockHashOrNumber;
use reth_provider::{
@ -54,11 +55,11 @@ pub struct Command<C: ChainSpecParser> {
}
impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
async fn build_network(
async fn build_network<N: NodeTypesWithDB<ChainSpec = C::ChainSpec>>(
&self,
config: &Config,
task_executor: TaskExecutor,
provider_factory: ProviderFactory<Arc<DatabaseEnv>>,
provider_factory: ProviderFactory<N>,
network_secret_path: PathBuf,
default_peers_path: PathBuf,
) -> eyre::Result<NetworkHandle> {
@ -76,8 +77,12 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
}
/// Execute `merkle-debug` command
pub async fn execute(self, ctx: CliContext) -> eyre::Result<()> {
let Environment { provider_factory, config, data_dir } = self.env.init(AccessRights::RW)?;
pub async fn execute<N: NodeTypesWithEngine<ChainSpec = C::ChainSpec>>(
self,
ctx: CliContext,
) -> eyre::Result<()> {
let Environment { provider_factory, config, data_dir } =
self.env.init::<N>(AccessRights::RW)?;
let provider_rw = provider_factory.provider_rw()?;

View File

@ -4,6 +4,8 @@ use clap::{Parser, Subcommand};
use reth_chainspec::ChainSpec;
use reth_cli::chainspec::ChainSpecParser;
use reth_cli_runner::CliContext;
use reth_node_api::NodeTypesWithEngine;
use reth_node_ethereum::EthEngineTypes;
mod build_block;
mod execution;
@ -35,13 +37,18 @@ pub enum Subcommands<C: ChainSpecParser> {
impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
/// Execute `debug` command
pub async fn execute(self, ctx: CliContext) -> eyre::Result<()> {
pub async fn execute<
N: NodeTypesWithEngine<Engine = EthEngineTypes, ChainSpec = C::ChainSpec>,
>(
self,
ctx: CliContext,
) -> eyre::Result<()> {
match self.command {
Subcommands::Execution(command) => command.execute(ctx).await,
Subcommands::Merkle(command) => command.execute(ctx).await,
Subcommands::InMemoryMerkle(command) => command.execute(ctx).await,
Subcommands::BuildBlock(command) => command.execute(ctx).await,
Subcommands::ReplayEngine(command) => command.execute(ctx).await,
Subcommands::Execution(command) => command.execute::<N>(ctx).await,
Subcommands::Merkle(command) => command.execute::<N>(ctx).await,
Subcommands::InMemoryMerkle(command) => command.execute::<N>(ctx).await,
Subcommands::BuildBlock(command) => command.execute::<N>(ctx).await,
Subcommands::ReplayEngine(command) => command.execute::<N>(ctx).await,
}
}
}

View File

@ -18,7 +18,8 @@ use reth_engine_util::engine_store::{EngineMessageStore, StoredEngineApiMessage}
use reth_fs_util as fs;
use reth_network::{BlockDownloaderProvider, NetworkHandle};
use reth_network_api::NetworkInfo;
use reth_node_ethereum::EthExecutorProvider;
use reth_node_api::{NodeTypesWithDB, NodeTypesWithDBAdapter, NodeTypesWithEngine};
use reth_node_ethereum::{EthEngineTypes, EthExecutorProvider};
use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService};
use reth_provider::{
providers::BlockchainProvider, CanonStateSubscriptions, ChainSpecProvider, ProviderFactory,
@ -53,11 +54,11 @@ pub struct Command<C: ChainSpecParser> {
}
impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
async fn build_network(
async fn build_network<N: NodeTypesWithDB<ChainSpec = C::ChainSpec>>(
&self,
config: &Config,
task_executor: TaskExecutor,
provider_factory: ProviderFactory<Arc<DatabaseEnv>>,
provider_factory: ProviderFactory<N>,
network_secret_path: PathBuf,
default_peers_path: PathBuf,
) -> eyre::Result<NetworkHandle> {
@ -75,8 +76,14 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
}
/// Execute `debug replay-engine` command
pub async fn execute(self, ctx: CliContext) -> eyre::Result<()> {
let Environment { provider_factory, config, data_dir } = self.env.init(AccessRights::RW)?;
pub async fn execute<
N: NodeTypesWithEngine<Engine = EthEngineTypes, ChainSpec = C::ChainSpec>,
>(
self,
ctx: CliContext,
) -> eyre::Result<()> {
let Environment { provider_factory, config, data_dir } =
self.env.init::<N>(AccessRights::RW)?;
let consensus: Arc<dyn Consensus> =
Arc::new(EthBeaconConsensus::new(provider_factory.chain_spec()));
@ -121,10 +128,8 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
payload_builder,
);
let (payload_service, payload_builder): (
_,
PayloadBuilderHandle<reth_node_ethereum::EthEngineTypes>,
) = PayloadBuilderService::new(payload_generator, blockchain_db.canonical_state_stream());
let (payload_service, payload_builder): (_, PayloadBuilderHandle<EthEngineTypes>) =
PayloadBuilderService::new(payload_generator, blockchain_db.canonical_state_stream());
ctx.task_executor.spawn_critical("payload builder service", payload_service);
@ -132,7 +137,7 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
let network_client = network.fetch_client().await?;
let (beacon_consensus_engine, beacon_engine_handle) = BeaconConsensusEngine::new(
network_client,
Pipeline::builder().build(
Pipeline::<NodeTypesWithDBAdapter<N, Arc<DatabaseEnv>>>::builder().build(
provider_factory.clone(),
StaticFileProducer::new(provider_factory.clone(), PruneModes::none()),
),