Skip to content

Commit

Permalink
feat(bin): node --full flag (#3965)
Browse files Browse the repository at this point in the history
  • Loading branch information
shekhirin authored Jul 31, 2023
1 parent dee14c7 commit 9a7911b
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 6 deletions.
4 changes: 4 additions & 0 deletions bin/reth/src/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
37 changes: 37 additions & 0 deletions bin/reth/src/args/pruning_args.rs
Original file line number Diff line number Diff line change
@@ -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<ChainSpec>) -> Option<PruneConfig> {
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
}
}
}
1 change: 1 addition & 0 deletions bin/reth/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
20 changes: 15 additions & 5 deletions bin/reth/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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::{
Expand Down Expand Up @@ -143,6 +143,9 @@ pub struct Command<Ext: RethCliExt = ()> {

#[clap(flatten)]
dev: DevArgs,

#[clap(flatten)]
pruning: PruningArgs,
}

impl Command {
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -332,6 +337,7 @@ impl Command {
db.clone(),
&ctx.task_executor,
metrics_tx,
prune_config,
max_block,
)
.await?;
Expand All @@ -351,6 +357,7 @@ impl Command {
db.clone(),
&ctx.task_executor,
metrics_tx,
prune_config,
max_block,
)
.await?;
Expand All @@ -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(),
Expand Down Expand Up @@ -479,6 +486,7 @@ impl Command {
db: DB,
task_executor: &TaskExecutor,
metrics_tx: MetricEventsSender,
prune_config: Option<PruneConfig>,
max_block: Option<BlockNumber>,
) -> eyre::Result<Pipeline<DB>>
where
Expand All @@ -504,6 +512,7 @@ impl Command {
max_block,
self.debug.continuous,
metrics_tx,
prune_config,
)
.await?;

Expand Down Expand Up @@ -685,6 +694,7 @@ impl Command {
max_block: Option<u64>,
continuous: bool,
metrics_tx: MetricEventsSender,
prune_config: Option<PruneConfig>,
) -> eyre::Result<Pipeline<DB>>
where
DB: Database + Clone + 'static,
Expand Down Expand Up @@ -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),
)
Expand Down
13 changes: 13 additions & 0 deletions crates/primitives/src/chain/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ pub static MAINNET: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
),
(Hardfork::Shanghai, ForkCondition::Timestamp(1681338455)),
]),
// https://etherscan.io/tx/0xe75fb554e433e03763a1560646ee22dcb74e5274b34c5ad644e7c0f619a7e1d0
deposit_contract_deployment_block: Some(11052984),
}
.into()
});
Expand Down Expand Up @@ -88,6 +90,8 @@ pub static GOERLI: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
),
(Hardfork::Shanghai, ForkCondition::Timestamp(1678832736)),
]),
// https://goerli.etherscan.io/tx/0xa3c07dc59bfdb1bfc2d50920fed2ef2c1c4e0a09fe2325dbc14e07702f965a78
deposit_contract_deployment_block: Some(4367322),
}
.into()
});
Expand Down Expand Up @@ -126,6 +130,8 @@ pub static SEPOLIA: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
),
(Hardfork::Shanghai, ForkCondition::Timestamp(1677557088)),
]),
// https://sepolia.etherscan.io/tx/0x025ecbf81a2f1220da6285d1701dc89fb5a956b62562ee922e1a9efd73eb4b14
deposit_contract_deployment_block: Some(1273020),
}
.into()
});
Expand Down Expand Up @@ -163,6 +169,7 @@ pub static DEV: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
),
(Hardfork::Shanghai, ForkCondition::Timestamp(0)),
]),
deposit_contract_deployment_block: Some(0),
}
.into()
});
Expand Down Expand Up @@ -201,6 +208,10 @@ pub struct ChainSpec {

/// The active hard forks and their activation conditions
pub hardforks: BTreeMap<Hardfork, ForkCondition>,

/// The block at which the deposit contract for PoS was deployed.
#[serde(skip, default)]
pub deposit_contract_deployment_block: Option<BlockNumber>,
}

impl ChainSpec {
Expand Down Expand Up @@ -433,6 +444,7 @@ impl From<Genesis> for ChainSpec {
fork_timestamps: ForkTimestamps::from_hardforks(&hardforks),
hardforks,
paris_block_and_final_difficulty: None,
deposit_contract_deployment_block: None,
}
}
}
Expand Down Expand Up @@ -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,
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/primitives/src/hardfork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
Expand Down

0 comments on commit 9a7911b

Please sign in to comment.