mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-30 01:28:21 -05:00
feat(bin): node --full flag (#3965)
This commit is contained in:
@@ -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
bin/reth/src/args/pruning_args.rs
Normal file
37
bin/reth/src/args/pruning_args.rs
Normal file
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -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<Ext: RethCliExt = ()> {
|
||||
|
||||
#[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<PruneConfig>,
|
||||
max_block: Option<BlockNumber>,
|
||||
) -> eyre::Result<Pipeline<DB>>
|
||||
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<u64>,
|
||||
continuous: bool,
|
||||
metrics_tx: MetricEventsSender,
|
||||
prune_config: Option<PruneConfig>,
|
||||
) -> eyre::Result<Pipeline<DB>>
|
||||
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),
|
||||
)
|
||||
|
||||
@@ -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()
|
||||
});
|
||||
@@ -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()
|
||||
});
|
||||
@@ -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()
|
||||
});
|
||||
@@ -163,6 +169,7 @@ pub static DEV: Lazy<Arc<ChainSpec>> = 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<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 {
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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(),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user