From 9a7911b49e0b4bbb03d01db5fce645124b01ab89 Mon Sep 17 00:00:00 2001 From: Alexey Shekhirin Date: Mon, 31 Jul 2023 17:00:45 +0100 Subject: [PATCH] feat(bin): `node --full` flag (#3965) --- bin/reth/src/args/mod.rs | 4 ++++ bin/reth/src/args/pruning_args.rs | 37 +++++++++++++++++++++++++++++ bin/reth/src/init.rs | 1 + bin/reth/src/node/mod.rs | 20 ++++++++++++---- crates/primitives/src/chain/spec.rs | 13 ++++++++++ crates/primitives/src/hardfork.rs | 2 ++ crates/rpc/rpc-builder/src/lib.rs | 2 +- 7 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 bin/reth/src/args/pruning_args.rs diff --git a/bin/reth/src/args/mod.rs b/bin/reth/src/args/mod.rs index dd4dd83d0b..0710176a0d 100644 --- a/bin/reth/src/args/mod.rs +++ b/bin/reth/src/args/mod.rs @@ -39,4 +39,8 @@ pub use txpool_args::TxPoolArgs; mod dev_args; pub use dev_args::DevArgs; +/// PruneArgs for configuring the pruning and full node +mod pruning_args; +pub use pruning_args::PruningArgs; + pub mod utils; diff --git a/bin/reth/src/args/pruning_args.rs b/bin/reth/src/args/pruning_args.rs new file mode 100644 index 0000000000..42f8d6571c --- /dev/null +++ b/bin/reth/src/args/pruning_args.rs @@ -0,0 +1,37 @@ +//! Pruning and full node arguments + +use clap::Args; +use reth_config::config::PruneConfig; +use reth_primitives::{ChainSpec, PruneMode, PruneModes}; +use std::sync::Arc; + +/// Parameters for pruning and full node +#[derive(Debug, Args, PartialEq, Default)] +#[command(next_help_heading = "Pruning")] +pub struct PruningArgs { + /// Run full node. Only the most recent 128 block states are stored. This flag takes + /// priority over pruning configuration in reth.toml. + // TODO(alexey): unhide when pruning is ready for production use + #[arg(long, hide = true, default_value_t = false)] + pub full: bool, +} + +impl PruningArgs { + /// Returns pruning configuration. + pub fn prune_config(&self, chain_spec: Arc) -> Option { + if self.full { + Some(PruneConfig { + block_interval: 5, + parts: PruneModes { + sender_recovery: Some(PruneMode::Distance(128)), + transaction_lookup: None, + receipts: chain_spec.deposit_contract_deployment_block.map(PruneMode::Before), + account_history: Some(PruneMode::Distance(128)), + storage_history: Some(PruneMode::Distance(128)), + }, + }) + } else { + None + } + } +} diff --git a/bin/reth/src/init.rs b/bin/reth/src/init.rs index cb6f885801..1e3cae8778 100644 --- a/bin/reth/src/init.rs +++ b/bin/reth/src/init.rs @@ -272,6 +272,7 @@ mod tests { fork_timestamps: ForkTimestamps::default(), genesis_hash: None, paris_block_and_final_difficulty: None, + deposit_contract_deployment_block: None, }); let db = create_test_rw_db(); diff --git a/bin/reth/src/node/mod.rs b/bin/reth/src/node/mod.rs index 8dc76f0fe2..76448af826 100644 --- a/bin/reth/src/node/mod.rs +++ b/bin/reth/src/node/mod.rs @@ -5,8 +5,8 @@ use crate::{ args::{ get_secret_key, utils::{genesis_value_parser, parse_socket_address}, - DatabaseArgs, DebugArgs, DevArgs, NetworkArgs, PayloadBuilderArgs, RpcServerArgs, - TxPoolArgs, + DatabaseArgs, DebugArgs, DevArgs, NetworkArgs, PayloadBuilderArgs, PruningArgs, + RpcServerArgs, TxPoolArgs, }, cli::ext::RethCliExt, dirs::{DataDirPath, MaybePlatformPath}, @@ -27,7 +27,7 @@ use reth_beacon_consensus::{BeaconConsensus, BeaconConsensusEngine, MIN_BLOCKS_F use reth_blockchain_tree::{ config::BlockchainTreeConfig, externals::TreeExternals, BlockchainTree, ShareableBlockchainTree, }; -use reth_config::Config; +use reth_config::{config::PruneConfig, Config}; use reth_db::{database::Database, init_db, DatabaseEnv}; use reth_discv4::DEFAULT_DISCOVERY_PORT; use reth_downloaders::{ @@ -143,6 +143,9 @@ pub struct Command { #[clap(flatten)] dev: DevArgs, + + #[clap(flatten)] + pruning: PruningArgs, } impl Command { @@ -298,6 +301,8 @@ impl Command { None }; + let prune_config = self.pruning.prune_config(Arc::clone(&self.chain)).or(config.prune); + // Configure the pipeline let (mut pipeline, client) = if self.dev.dev { info!(target: "reth::cli", "Starting Reth in dev mode"); @@ -332,6 +337,7 @@ impl Command { db.clone(), &ctx.task_executor, metrics_tx, + prune_config, max_block, ) .await?; @@ -351,6 +357,7 @@ impl Command { db.clone(), &ctx.task_executor, metrics_tx, + prune_config, max_block, ) .await?; @@ -373,7 +380,7 @@ impl Command { None }; - let pruner = config.prune.map(|prune_config| { + let pruner = prune_config.map(|prune_config| { info!(target: "reth::cli", "Pruner initialized"); reth_prune::Pruner::new( db.clone(), @@ -479,6 +486,7 @@ impl Command { db: DB, task_executor: &TaskExecutor, metrics_tx: MetricEventsSender, + prune_config: Option, max_block: Option, ) -> eyre::Result> where @@ -504,6 +512,7 @@ impl Command { max_block, self.debug.continuous, metrics_tx, + prune_config, ) .await?; @@ -685,6 +694,7 @@ impl Command { max_block: Option, continuous: bool, metrics_tx: MetricEventsSender, + prune_config: Option, ) -> eyre::Result> where DB: Database + Clone + 'static, @@ -746,7 +756,7 @@ impl Command { max_blocks: stage_config.execution.max_blocks, max_changes: stage_config.execution.max_changes, }, - config.prune.map(|prune| prune.parts).unwrap_or_default(), + prune_config.map(|prune| prune.parts).unwrap_or_default(), ) .with_metrics_tx(metrics_tx), ) diff --git a/crates/primitives/src/chain/spec.rs b/crates/primitives/src/chain/spec.rs index d86d375a44..f23839d1da 100644 --- a/crates/primitives/src/chain/spec.rs +++ b/crates/primitives/src/chain/spec.rs @@ -54,6 +54,8 @@ pub static MAINNET: Lazy> = Lazy::new(|| { ), (Hardfork::Shanghai, ForkCondition::Timestamp(1681338455)), ]), + // https://etherscan.io/tx/0xe75fb554e433e03763a1560646ee22dcb74e5274b34c5ad644e7c0f619a7e1d0 + deposit_contract_deployment_block: Some(11052984), } .into() }); @@ -88,6 +90,8 @@ pub static GOERLI: Lazy> = Lazy::new(|| { ), (Hardfork::Shanghai, ForkCondition::Timestamp(1678832736)), ]), + // https://goerli.etherscan.io/tx/0xa3c07dc59bfdb1bfc2d50920fed2ef2c1c4e0a09fe2325dbc14e07702f965a78 + deposit_contract_deployment_block: Some(4367322), } .into() }); @@ -126,6 +130,8 @@ pub static SEPOLIA: Lazy> = Lazy::new(|| { ), (Hardfork::Shanghai, ForkCondition::Timestamp(1677557088)), ]), + // https://sepolia.etherscan.io/tx/0x025ecbf81a2f1220da6285d1701dc89fb5a956b62562ee922e1a9efd73eb4b14 + deposit_contract_deployment_block: Some(1273020), } .into() }); @@ -163,6 +169,7 @@ pub static DEV: Lazy> = Lazy::new(|| { ), (Hardfork::Shanghai, ForkCondition::Timestamp(0)), ]), + deposit_contract_deployment_block: Some(0), } .into() }); @@ -201,6 +208,10 @@ pub struct ChainSpec { /// The active hard forks and their activation conditions pub hardforks: BTreeMap, + + /// The block at which the deposit contract for PoS was deployed. + #[serde(skip, default)] + pub deposit_contract_deployment_block: Option, } impl ChainSpec { @@ -433,6 +444,7 @@ impl From for ChainSpec { fork_timestamps: ForkTimestamps::from_hardforks(&hardforks), hardforks, paris_block_and_final_difficulty: None, + deposit_contract_deployment_block: None, } } } @@ -655,6 +667,7 @@ impl ChainSpecBuilder { fork_timestamps: ForkTimestamps::from_hardforks(&self.hardforks), hardforks: self.hardforks, paris_block_and_final_difficulty: None, + deposit_contract_deployment_block: None, } } } diff --git a/crates/primitives/src/hardfork.rs b/crates/primitives/src/hardfork.rs index ba87a53ef7..724ddf93a3 100644 --- a/crates/primitives/src/hardfork.rs +++ b/crates/primitives/src/hardfork.rs @@ -164,6 +164,7 @@ mod tests { hardforks: BTreeMap::from([(Hardfork::Frontier, ForkCondition::Never)]), fork_timestamps: Default::default(), paris_block_and_final_difficulty: None, + deposit_contract_deployment_block: None, }; assert_eq!(Hardfork::Frontier.fork_id(&spec), None); @@ -178,6 +179,7 @@ mod tests { hardforks: BTreeMap::from([(Hardfork::Shanghai, ForkCondition::Never)]), fork_timestamps: Default::default(), paris_block_and_final_difficulty: None, + deposit_contract_deployment_block: None, }; assert_eq!(Hardfork::Shanghai.fork_filter(&spec), None); diff --git a/crates/rpc/rpc-builder/src/lib.rs b/crates/rpc/rpc-builder/src/lib.rs index c66636babb..e7f617194e 100644 --- a/crates/rpc/rpc-builder/src/lib.rs +++ b/crates/rpc/rpc-builder/src/lib.rs @@ -818,7 +818,7 @@ where let eth = self.eth_handlers(); self.modules.insert( RethRpcModule::Trace, - TraceApi::new(self.provider.clone(), eth.api.clone(), self.tracing_call_guard.clone()) + TraceApi::new(self.provider.clone(), eth.api, self.tracing_call_guard.clone()) .into_rpc() .into(), );