reth_node_builder/launch/
common.rs

1//! Helper types that can be used by launchers.
2//!
3//! ## Launch Context Type System
4//!
5//! The node launch process uses a type-state pattern to ensure correct initialization
6//! order at compile time. Methods are only available when their prerequisites are met.
7//!
8//! ### Core Types
9//!
10//! - [`LaunchContext`]: Base context with executor and data directory
11//! - [`LaunchContextWith<T>`]: Context with an attached value of type `T`
12//! - [`Attached<L, R>`]: Pairs values, preserving both previous (L) and new (R) state
13//!
14//! ### Helper Attachments
15//!
16//! - [`WithConfigs`]: Node config + TOML config
17//! - [`WithMeteredProvider`]: Provider factory with metrics
18//! - [`WithMeteredProviders`]: Provider factory + blockchain provider
19//! - [`WithComponents`]: Final form with all components
20//!
21//! ### Method Availability
22//!
23//! Methods are implemented on specific type combinations:
24//! - `impl<T> LaunchContextWith<T>`: Generic methods available for any attachment
25//! - `impl LaunchContextWith<WithConfigs>`: Config-specific methods
26//! - `impl LaunchContextWith<Attached<WithConfigs, DB>>`: Database operations
27//! - `impl LaunchContextWith<Attached<WithConfigs, ProviderFactory>>`: Provider operations
28//! - etc.
29//!
30//! This ensures correct initialization order without runtime checks.
31
32use crate::{
33    components::{NodeComponents, NodeComponentsBuilder},
34    hooks::OnComponentInitializedHook,
35    BuilderContext, ExExLauncher, NodeAdapter, PrimitivesTy,
36};
37use alloy_eips::eip2124::Head;
38use alloy_primitives::{BlockNumber, B256};
39use eyre::Context;
40use rayon::ThreadPoolBuilder;
41use reth_chainspec::{Chain, EthChainSpec, EthereumHardforks};
42use reth_config::{config::EtlConfig, PruneConfig};
43use reth_consensus::noop::NoopConsensus;
44use reth_db_api::{database::Database, database_metrics::DatabaseMetrics};
45use reth_db_common::init::{init_genesis_with_settings, InitStorageError};
46use reth_downloaders::{bodies::noop::NoopBodiesDownloader, headers::noop::NoopHeaderDownloader};
47use reth_engine_local::MiningMode;
48use reth_evm::{noop::NoopEvmConfig, ConfigureEvm};
49use reth_exex::ExExManagerHandle;
50use reth_fs_util as fs;
51use reth_network_p2p::headers::client::HeadersClient;
52use reth_node_api::{FullNodeTypes, NodeTypes, NodeTypesWithDB, NodeTypesWithDBAdapter};
53use reth_node_core::{
54    args::DefaultEraHost,
55    dirs::{ChainPath, DataDirPath},
56    node_config::NodeConfig,
57    primitives::BlockHeader,
58    version::version_metadata,
59};
60use reth_node_metrics::{
61    chain::ChainSpecInfo,
62    hooks::Hooks,
63    recorder::install_prometheus_recorder,
64    server::{MetricServer, MetricServerConfig},
65    version::VersionInfo,
66};
67use reth_provider::{
68    providers::{NodeTypesForProvider, ProviderNodeTypes, RocksDBProvider, StaticFileProvider},
69    BlockHashReader, BlockNumReader, DatabaseProviderFactory, ProviderError, ProviderFactory,
70    ProviderResult, RocksDBProviderFactory, StageCheckpointReader, StaticFileProviderBuilder,
71    StaticFileProviderFactory,
72};
73use reth_prune::{PruneModes, PrunerBuilder};
74use reth_rpc_builder::config::RethRpcServerConfig;
75use reth_rpc_layer::JwtSecret;
76use reth_stages::{
77    sets::DefaultStages, stages::EraImportSource, MetricEvent, PipelineBuilder, PipelineTarget,
78    StageId,
79};
80use reth_static_file::StaticFileProducer;
81use reth_tasks::TaskExecutor;
82use reth_tracing::{
83    throttle,
84    tracing::{debug, error, info, warn},
85};
86use reth_transaction_pool::TransactionPool;
87use std::{sync::Arc, thread::available_parallelism, time::Duration};
88use tokio::sync::{
89    mpsc::{unbounded_channel, UnboundedSender},
90    oneshot, watch,
91};
92
93use futures::{future::Either, stream, Stream, StreamExt};
94use reth_node_ethstats::EthStatsService;
95use reth_node_events::{cl::ConsensusLayerHealthEvents, node::NodeEvent};
96
97/// Reusable setup for launching a node.
98///
99/// This is the entry point for the node launch process. It implements a builder
100/// pattern using type-state programming to enforce correct initialization order.
101///
102/// ## Type Evolution
103///
104/// Starting from `LaunchContext`, each method transforms the type to reflect
105/// accumulated state:
106///
107/// ```text
108/// LaunchContext
109///   └─> LaunchContextWith<WithConfigs>
110///       └─> LaunchContextWith<Attached<WithConfigs, DB>>
111///           └─> LaunchContextWith<Attached<WithConfigs, ProviderFactory>>
112///               └─> LaunchContextWith<Attached<WithConfigs, WithMeteredProviders>>
113///                   └─> LaunchContextWith<Attached<WithConfigs, WithComponents>>
114/// ```
115#[derive(Debug, Clone)]
116pub struct LaunchContext {
117    /// The task executor for the node.
118    pub task_executor: TaskExecutor,
119    /// The data directory for the node.
120    pub data_dir: ChainPath<DataDirPath>,
121}
122
123impl LaunchContext {
124    /// Create a new instance of the default node launcher.
125    pub const fn new(task_executor: TaskExecutor, data_dir: ChainPath<DataDirPath>) -> Self {
126        Self { task_executor, data_dir }
127    }
128
129    /// Create launch context with attachment.
130    pub const fn with<T>(self, attachment: T) -> LaunchContextWith<T> {
131        LaunchContextWith { inner: self, attachment }
132    }
133
134    /// Loads the reth config with the configured `data_dir` and overrides settings according to the
135    /// `config`.
136    ///
137    /// Attaches both the `NodeConfig` and the loaded `reth.toml` config to the launch context.
138    pub fn with_loaded_toml_config<ChainSpec>(
139        self,
140        config: NodeConfig<ChainSpec>,
141    ) -> eyre::Result<LaunchContextWith<WithConfigs<ChainSpec>>>
142    where
143        ChainSpec: EthChainSpec + reth_chainspec::EthereumHardforks,
144    {
145        let toml_config = self.load_toml_config(&config)?;
146        Ok(self.with(WithConfigs { config, toml_config }))
147    }
148
149    /// Loads the reth config with the configured `data_dir` and overrides settings according to the
150    /// `config`.
151    ///
152    /// This is async because the trusted peers may have to be resolved.
153    pub fn load_toml_config<ChainSpec>(
154        &self,
155        config: &NodeConfig<ChainSpec>,
156    ) -> eyre::Result<reth_config::Config>
157    where
158        ChainSpec: EthChainSpec + reth_chainspec::EthereumHardforks,
159    {
160        let config_path = config.config.clone().unwrap_or_else(|| self.data_dir.config());
161
162        let mut toml_config = reth_config::Config::from_path(&config_path)
163            .wrap_err_with(|| format!("Could not load config file {config_path:?}"))?;
164
165        Self::save_pruning_config(&mut toml_config, config, &config_path)?;
166
167        info!(target: "reth::cli", path = ?config_path, "Configuration loaded");
168
169        // Update the config with the command line arguments
170        toml_config.peers.trusted_nodes_only = config.network.trusted_only;
171
172        // Merge static file CLI arguments with config file, giving priority to CLI
173        toml_config.static_files =
174            config.static_files.merge_with_config(toml_config.static_files, config.pruning.minimal);
175
176        Ok(toml_config)
177    }
178
179    /// Save prune config to the toml file if node is a full node or has custom pruning CLI
180    /// arguments. Also migrates deprecated prune config values to new defaults.
181    fn save_pruning_config<ChainSpec>(
182        reth_config: &mut reth_config::Config,
183        config: &NodeConfig<ChainSpec>,
184        config_path: impl AsRef<std::path::Path>,
185    ) -> eyre::Result<()>
186    where
187        ChainSpec: EthChainSpec + reth_chainspec::EthereumHardforks,
188    {
189        let mut should_save = reth_config.prune.segments.migrate();
190
191        if let Some(prune_config) = config.prune_config() {
192            if reth_config.prune != prune_config {
193                reth_config.set_prune_config(prune_config);
194                should_save = true;
195            }
196        } else if !reth_config.prune.is_default() {
197            warn!(target: "reth::cli", "Pruning configuration is present in the config file, but no CLI arguments are provided. Using config from file.");
198        }
199
200        if should_save {
201            info!(target: "reth::cli", "Saving prune config to toml file");
202            reth_config.save(config_path.as_ref())?;
203        }
204
205        Ok(())
206    }
207
208    /// Convenience function to [`Self::configure_globals`]
209    pub fn with_configured_globals(self, reserved_cpu_cores: usize) -> Self {
210        self.configure_globals(reserved_cpu_cores);
211        self
212    }
213
214    /// Configure global settings this includes:
215    ///
216    /// - Raising the file descriptor limit
217    /// - Configuring the global rayon thread pool with available parallelism. Honoring
218    ///   engine.reserved-cpu-cores to reserve given number of cores for O while using at least 1
219    ///   core for the rayon thread pool
220    pub fn configure_globals(&self, reserved_cpu_cores: usize) {
221        // Raise the fd limit of the process.
222        // Does not do anything on windows.
223        match fdlimit::raise_fd_limit() {
224            Ok(fdlimit::Outcome::LimitRaised { from, to }) => {
225                debug!(from, to, "Raised file descriptor limit");
226            }
227            Ok(fdlimit::Outcome::Unsupported) => {}
228            Err(err) => warn!(%err, "Failed to raise file descriptor limit"),
229        }
230
231        // Reserving the given number of CPU cores for the rest of OS.
232        // Users can reserve more cores by setting engine.reserved-cpu-cores
233        // Note: The global rayon thread pool will use at least one core.
234        let num_threads = available_parallelism()
235            .map_or(0, |num| num.get().saturating_sub(reserved_cpu_cores).max(1));
236        if let Err(err) = ThreadPoolBuilder::new()
237            .num_threads(num_threads)
238            .thread_name(|i| format!("reth-rayon-{i}"))
239            .build_global()
240        {
241            warn!(%err, "Failed to build global thread pool")
242        }
243    }
244}
245
246/// A [`LaunchContext`] along with an additional value.
247///
248/// The type parameter `T` represents the current state of the launch process.
249/// Methods are conditionally implemented based on `T`, ensuring operations
250/// are only available when their prerequisites are met.
251///
252/// For example:
253/// - Config methods when `T = WithConfigs<ChainSpec>`
254/// - Database operations when `T = Attached<WithConfigs<ChainSpec>, DB>`
255/// - Provider operations when `T = Attached<WithConfigs<ChainSpec>, ProviderFactory<N>>`
256#[derive(Debug, Clone)]
257pub struct LaunchContextWith<T> {
258    /// The wrapped launch context.
259    pub inner: LaunchContext,
260    /// The additional attached value.
261    pub attachment: T,
262}
263
264impl<T> LaunchContextWith<T> {
265    /// Configure global settings this includes:
266    ///
267    /// - Raising the file descriptor limit
268    /// - Configuring the global rayon thread pool
269    pub fn configure_globals(&self, reserved_cpu_cores: u64) {
270        self.inner.configure_globals(reserved_cpu_cores.try_into().unwrap());
271    }
272
273    /// Returns the data directory.
274    pub const fn data_dir(&self) -> &ChainPath<DataDirPath> {
275        &self.inner.data_dir
276    }
277
278    /// Returns the task executor.
279    pub const fn task_executor(&self) -> &TaskExecutor {
280        &self.inner.task_executor
281    }
282
283    /// Attaches another value to the launch context.
284    pub fn attach<A>(self, attachment: A) -> LaunchContextWith<Attached<T, A>> {
285        LaunchContextWith {
286            inner: self.inner,
287            attachment: Attached::new(self.attachment, attachment),
288        }
289    }
290
291    /// Consumes the type and calls a function with a reference to the context.
292    // Returns the context again
293    pub fn inspect<F>(self, f: F) -> Self
294    where
295        F: FnOnce(&Self),
296    {
297        f(&self);
298        self
299    }
300}
301
302impl<ChainSpec> LaunchContextWith<WithConfigs<ChainSpec>> {
303    /// Resolves the trusted peers and adds them to the toml config.
304    pub fn with_resolved_peers(mut self) -> eyre::Result<Self> {
305        if !self.attachment.config.network.trusted_peers.is_empty() {
306            info!(target: "reth::cli", "Adding trusted nodes");
307
308            self.attachment
309                .toml_config
310                .peers
311                .trusted_nodes
312                .extend(self.attachment.config.network.trusted_peers.clone());
313        }
314        Ok(self)
315    }
316}
317
318impl<L, R> LaunchContextWith<Attached<L, R>> {
319    /// Get a reference to the left value.
320    pub const fn left(&self) -> &L {
321        &self.attachment.left
322    }
323
324    /// Get a reference to the right value.
325    pub const fn right(&self) -> &R {
326        &self.attachment.right
327    }
328
329    /// Get a mutable reference to the left value.
330    pub const fn left_mut(&mut self) -> &mut L {
331        &mut self.attachment.left
332    }
333
334    /// Get a mutable reference to the right value.
335    pub const fn right_mut(&mut self) -> &mut R {
336        &mut self.attachment.right
337    }
338}
339impl<R, ChainSpec: EthChainSpec> LaunchContextWith<Attached<WithConfigs<ChainSpec>, R>> {
340    /// Adjust certain settings in the config to make sure they are set correctly
341    ///
342    /// This includes:
343    /// - Making sure the ETL dir is set to the datadir
344    /// - RPC settings are adjusted to the correct port
345    pub fn with_adjusted_configs(self) -> Self {
346        self.ensure_etl_datadir().with_adjusted_instance_ports()
347    }
348
349    /// Make sure ETL doesn't default to /tmp/, but to whatever datadir is set to
350    pub fn ensure_etl_datadir(mut self) -> Self {
351        if self.toml_config_mut().stages.etl.dir.is_none() {
352            let etl_path = EtlConfig::from_datadir(self.data_dir().data_dir());
353            if etl_path.exists() {
354                // Remove etl-path files on launch
355                if let Err(err) = fs::remove_dir_all(&etl_path) {
356                    warn!(target: "reth::cli", ?etl_path, %err, "Failed to remove ETL path on launch");
357                }
358            }
359            self.toml_config_mut().stages.etl.dir = Some(etl_path);
360        }
361
362        self
363    }
364
365    /// Change rpc port numbers based on the instance number.
366    pub fn with_adjusted_instance_ports(mut self) -> Self {
367        self.node_config_mut().adjust_instance_ports();
368        self
369    }
370
371    /// Returns the container for all config types
372    pub const fn configs(&self) -> &WithConfigs<ChainSpec> {
373        self.attachment.left()
374    }
375
376    /// Returns the attached [`NodeConfig`].
377    pub const fn node_config(&self) -> &NodeConfig<ChainSpec> {
378        &self.left().config
379    }
380
381    /// Returns the attached [`NodeConfig`].
382    pub const fn node_config_mut(&mut self) -> &mut NodeConfig<ChainSpec> {
383        &mut self.left_mut().config
384    }
385
386    /// Returns the attached toml config [`reth_config::Config`].
387    pub const fn toml_config(&self) -> &reth_config::Config {
388        &self.left().toml_config
389    }
390
391    /// Returns the attached toml config [`reth_config::Config`].
392    pub const fn toml_config_mut(&mut self) -> &mut reth_config::Config {
393        &mut self.left_mut().toml_config
394    }
395
396    /// Returns the configured chain spec.
397    pub fn chain_spec(&self) -> Arc<ChainSpec> {
398        self.node_config().chain.clone()
399    }
400
401    /// Get the hash of the genesis block.
402    pub fn genesis_hash(&self) -> B256 {
403        self.node_config().chain.genesis_hash()
404    }
405
406    /// Returns the chain identifier of the node.
407    pub fn chain_id(&self) -> Chain {
408        self.node_config().chain.chain()
409    }
410
411    /// Returns true if the node is configured as --dev
412    pub const fn is_dev(&self) -> bool {
413        self.node_config().dev.dev
414    }
415
416    /// Returns the configured [`PruneConfig`]
417    ///
418    /// Any configuration set in CLI will take precedence over those set in toml
419    pub fn prune_config(&self) -> PruneConfig
420    where
421        ChainSpec: reth_chainspec::EthereumHardforks,
422    {
423        let Some(mut node_prune_config) = self.node_config().prune_config() else {
424            // No CLI config is set, use the toml config.
425            return self.toml_config().prune.clone();
426        };
427
428        // Otherwise, use the CLI configuration and merge with toml config.
429        node_prune_config.merge(self.toml_config().prune.clone());
430        node_prune_config
431    }
432
433    /// Returns the configured [`PruneModes`], returning the default if no config was available.
434    pub fn prune_modes(&self) -> PruneModes
435    where
436        ChainSpec: reth_chainspec::EthereumHardforks,
437    {
438        self.prune_config().segments
439    }
440
441    /// Returns an initialized [`PrunerBuilder`] based on the configured [`PruneConfig`]
442    pub fn pruner_builder(&self) -> PrunerBuilder
443    where
444        ChainSpec: reth_chainspec::EthereumHardforks,
445    {
446        PrunerBuilder::new(self.prune_config())
447    }
448
449    /// Loads the JWT secret for the engine API
450    pub fn auth_jwt_secret(&self) -> eyre::Result<JwtSecret> {
451        let default_jwt_path = self.data_dir().jwt();
452        let secret = self.node_config().rpc.auth_jwt_secret(default_jwt_path)?;
453        Ok(secret)
454    }
455
456    /// Returns the [`MiningMode`] intended for --dev mode.
457    pub fn dev_mining_mode<Pool>(&self, pool: Pool) -> MiningMode<Pool>
458    where
459        Pool: TransactionPool + Unpin,
460    {
461        self.node_config().dev_mining_mode(pool)
462    }
463}
464
465impl<DB, ChainSpec> LaunchContextWith<Attached<WithConfigs<ChainSpec>, DB>>
466where
467    DB: Database + Clone + 'static,
468    ChainSpec: EthChainSpec + EthereumHardforks + 'static,
469{
470    /// Returns the [`ProviderFactory`] for the attached storage after executing a consistent check
471    /// between the database and static files. **It may execute a pipeline unwind if it fails this
472    /// check.**
473    pub async fn create_provider_factory<N, Evm>(&self) -> eyre::Result<ProviderFactory<N>>
474    where
475        N: ProviderNodeTypes<DB = DB, ChainSpec = ChainSpec>,
476        Evm: ConfigureEvm<Primitives = N::Primitives> + 'static,
477    {
478        // Validate static files configuration
479        let static_files_config = &self.toml_config().static_files;
480        static_files_config.validate()?;
481
482        // Apply per-segment blocks_per_file configuration
483        let static_file_provider =
484            StaticFileProviderBuilder::read_write(self.data_dir().static_files())
485                .with_metrics()
486                .with_blocks_per_file_for_segments(static_files_config.as_blocks_per_file_map())
487                .with_genesis_block_number(self.chain_spec().genesis().number.unwrap_or_default())
488                .build()?;
489
490        // Initialize RocksDB provider with metrics, statistics, and default tables
491        let rocksdb_provider = RocksDBProvider::builder(self.data_dir().rocksdb())
492            .with_default_tables()
493            .with_metrics()
494            .with_statistics()
495            .build()?;
496
497        let factory = ProviderFactory::new(
498            self.right().clone(),
499            self.chain_spec(),
500            static_file_provider,
501            rocksdb_provider,
502        )?
503        .with_prune_modes(self.prune_modes());
504
505        // Keep MDBX, static files, and RocksDB aligned. If any check fails, unwind to the
506        // earliest consistent block.
507        //
508        // Order matters:
509        // 1) heal static files (no pruning)
510        // 2) check RocksDB (needs static-file tx data)
511        // 3) check static-file checkpoints vs MDBX (may prune)
512        //
513        // Compute one unwind target and run a single unwind.
514
515        let provider_ro = factory.database_provider_ro()?;
516
517        // Step 1: heal file-level inconsistencies (no pruning)
518        factory.static_file_provider().check_file_consistency(&provider_ro)?;
519
520        // Step 2: RocksDB consistency check (needs static files tx data)
521        let rocksdb_unwind = factory.rocksdb_provider().check_consistency(&provider_ro)?;
522
523        // Step 3: Static file checkpoint consistency (may prune)
524        let static_file_unwind = factory
525            .static_file_provider()
526            .check_consistency(&provider_ro)?
527            .map(|target| match target {
528                PipelineTarget::Unwind(block) => block,
529                PipelineTarget::Sync(_) => unreachable!("check_consistency returns Unwind"),
530            });
531
532        // Take the minimum block number to ensure all storage layers are consistent.
533        let unwind_target = [rocksdb_unwind, static_file_unwind].into_iter().flatten().min();
534
535        if let Some(unwind_block) = unwind_target {
536            // Highly unlikely to happen, and given its destructive nature, it's better to panic
537            // instead. Unwinding to 0 would leave MDBX with a huge free list size.
538            let inconsistency_source = match (rocksdb_unwind, static_file_unwind) {
539                (Some(_), Some(_)) => "RocksDB and static file",
540                (Some(_), None) => "RocksDB",
541                (None, Some(_)) => "static file",
542                (None, None) => unreachable!(),
543            };
544            assert_ne!(
545                unwind_block, 0,
546                "A {} inconsistency was found that would trigger an unwind to block 0",
547                inconsistency_source
548            );
549
550            let unwind_target = PipelineTarget::Unwind(unwind_block);
551
552            info!(target: "reth::cli", %unwind_target, %inconsistency_source, "Executing unwind after consistency check.");
553
554            let (_tip_tx, tip_rx) = watch::channel(B256::ZERO);
555
556            // Builds an unwind-only pipeline
557            let pipeline = PipelineBuilder::default()
558                .add_stages(DefaultStages::new(
559                    factory.clone(),
560                    tip_rx,
561                    Arc::new(NoopConsensus::default()),
562                    NoopHeaderDownloader::default(),
563                    NoopBodiesDownloader::default(),
564                    NoopEvmConfig::<Evm>::default(),
565                    self.toml_config().stages.clone(),
566                    self.prune_modes(),
567                    None,
568                ))
569                .build(
570                    factory.clone(),
571                    StaticFileProducer::new(factory.clone(), self.prune_modes()),
572                );
573
574            // Unwinds to block
575            let (tx, rx) = oneshot::channel();
576
577            // Pipeline should be run as blocking and panic if it fails.
578            self.task_executor().spawn_critical_blocking(
579                "pipeline task",
580                Box::pin(async move {
581                    let (_, result) = pipeline.run_as_fut(Some(unwind_target)).await;
582                    let _ = tx.send(result);
583                }),
584            );
585            rx.await?.inspect_err(|err| {
586                error!(target: "reth::cli", %unwind_target, %inconsistency_source, %err, "failed to run unwind")
587            })?;
588        }
589
590        Ok(factory)
591    }
592
593    /// Creates a new [`ProviderFactory`] and attaches it to the launch context.
594    pub async fn with_provider_factory<N, Evm>(
595        self,
596    ) -> eyre::Result<LaunchContextWith<Attached<WithConfigs<ChainSpec>, ProviderFactory<N>>>>
597    where
598        N: ProviderNodeTypes<DB = DB, ChainSpec = ChainSpec>,
599        Evm: ConfigureEvm<Primitives = N::Primitives> + 'static,
600    {
601        let factory = self.create_provider_factory::<N, Evm>().await?;
602        let ctx = LaunchContextWith {
603            inner: self.inner,
604            attachment: self.attachment.map_right(|_| factory),
605        };
606
607        Ok(ctx)
608    }
609}
610
611impl<T> LaunchContextWith<Attached<WithConfigs<T::ChainSpec>, ProviderFactory<T>>>
612where
613    T: ProviderNodeTypes,
614{
615    /// Returns access to the underlying database.
616    pub const fn database(&self) -> &T::DB {
617        self.right().db_ref()
618    }
619
620    /// Returns the configured `ProviderFactory`.
621    pub const fn provider_factory(&self) -> &ProviderFactory<T> {
622        self.right()
623    }
624
625    /// Returns the static file provider to interact with the static files.
626    pub fn static_file_provider(&self) -> StaticFileProvider<T::Primitives> {
627        self.right().static_file_provider()
628    }
629
630    /// This launches the prometheus endpoint.
631    ///
632    /// Convenience function to [`Self::start_prometheus_endpoint`]
633    pub async fn with_prometheus_server(self) -> eyre::Result<Self> {
634        self.start_prometheus_endpoint().await?;
635        Ok(self)
636    }
637
638    /// Starts the prometheus endpoint.
639    pub async fn start_prometheus_endpoint(&self) -> eyre::Result<()> {
640        // ensure recorder runs upkeep periodically
641        install_prometheus_recorder().spawn_upkeep();
642
643        let listen_addr = self.node_config().metrics.prometheus;
644        if let Some(addr) = listen_addr {
645            let config = MetricServerConfig::new(
646                addr,
647                VersionInfo {
648                    version: version_metadata().cargo_pkg_version.as_ref(),
649                    build_timestamp: version_metadata().vergen_build_timestamp.as_ref(),
650                    cargo_features: version_metadata().vergen_cargo_features.as_ref(),
651                    git_sha: version_metadata().vergen_git_sha.as_ref(),
652                    target_triple: version_metadata().vergen_cargo_target_triple.as_ref(),
653                    build_profile: version_metadata().build_profile_name.as_ref(),
654                },
655                ChainSpecInfo { name: self.chain_id().to_string() },
656                self.task_executor().clone(),
657                metrics_hooks(self.provider_factory()),
658                self.data_dir().pprof_dumps(),
659            )
660            .with_push_gateway(
661                self.node_config().metrics.push_gateway_url.clone(),
662                self.node_config().metrics.push_gateway_interval,
663            );
664
665            MetricServer::new(config).serve().await?;
666        }
667
668        Ok(())
669    }
670
671    /// Convenience function to [`Self::init_genesis`]
672    pub fn with_genesis(self) -> Result<Self, InitStorageError> {
673        init_genesis_with_settings(
674            self.provider_factory(),
675            self.node_config().static_files.to_settings(),
676        )?;
677        Ok(self)
678    }
679
680    /// Write the genesis block and state if it has not already been written
681    pub fn init_genesis(&self) -> Result<B256, InitStorageError> {
682        init_genesis_with_settings(
683            self.provider_factory(),
684            self.node_config().static_files.to_settings(),
685        )
686    }
687
688    /// Creates a new `WithMeteredProvider` container and attaches it to the
689    /// launch context.
690    ///
691    /// This spawns a metrics task that listens for metrics related events and updates metrics for
692    /// prometheus.
693    pub fn with_metrics_task(
694        self,
695    ) -> LaunchContextWith<Attached<WithConfigs<T::ChainSpec>, WithMeteredProvider<T>>> {
696        let (metrics_sender, metrics_receiver) = unbounded_channel();
697
698        let with_metrics =
699            WithMeteredProvider { provider_factory: self.right().clone(), metrics_sender };
700
701        debug!(target: "reth::cli", "Spawning stages metrics listener task");
702        let sync_metrics_listener = reth_stages::MetricsListener::new(metrics_receiver);
703        self.task_executor().spawn_critical("stages metrics listener task", sync_metrics_listener);
704
705        LaunchContextWith {
706            inner: self.inner,
707            attachment: self.attachment.map_right(|_| with_metrics),
708        }
709    }
710}
711
712impl<N, DB>
713    LaunchContextWith<
714        Attached<WithConfigs<N::ChainSpec>, WithMeteredProvider<NodeTypesWithDBAdapter<N, DB>>>,
715    >
716where
717    N: NodeTypes,
718    DB: Database + DatabaseMetrics + Clone + Unpin + 'static,
719{
720    /// Returns the configured `ProviderFactory`.
721    const fn provider_factory(&self) -> &ProviderFactory<NodeTypesWithDBAdapter<N, DB>> {
722        &self.right().provider_factory
723    }
724
725    /// Returns the metrics sender.
726    fn sync_metrics_tx(&self) -> UnboundedSender<MetricEvent> {
727        self.right().metrics_sender.clone()
728    }
729
730    /// Creates a `BlockchainProvider` and attaches it to the launch context.
731    #[expect(clippy::complexity)]
732    pub fn with_blockchain_db<T, F>(
733        self,
734        create_blockchain_provider: F,
735    ) -> eyre::Result<LaunchContextWith<Attached<WithConfigs<N::ChainSpec>, WithMeteredProviders<T>>>>
736    where
737        T: FullNodeTypes<Types = N, DB = DB>,
738        F: FnOnce(ProviderFactory<NodeTypesWithDBAdapter<N, DB>>) -> eyre::Result<T::Provider>,
739    {
740        let blockchain_db = create_blockchain_provider(self.provider_factory().clone())?;
741
742        let metered_providers = WithMeteredProviders {
743            db_provider_container: WithMeteredProvider {
744                provider_factory: self.provider_factory().clone(),
745                metrics_sender: self.sync_metrics_tx(),
746            },
747            blockchain_db,
748        };
749
750        let ctx = LaunchContextWith {
751            inner: self.inner,
752            attachment: self.attachment.map_right(|_| metered_providers),
753        };
754
755        Ok(ctx)
756    }
757}
758
759impl<T>
760    LaunchContextWith<
761        Attached<WithConfigs<<T::Types as NodeTypes>::ChainSpec>, WithMeteredProviders<T>>,
762    >
763where
764    T: FullNodeTypes<Types: NodeTypesForProvider>,
765{
766    /// Returns access to the underlying database.
767    pub const fn database(&self) -> &T::DB {
768        self.provider_factory().db_ref()
769    }
770
771    /// Returns the configured `ProviderFactory`.
772    pub const fn provider_factory(
773        &self,
774    ) -> &ProviderFactory<NodeTypesWithDBAdapter<T::Types, T::DB>> {
775        &self.right().db_provider_container.provider_factory
776    }
777
778    /// Fetches the head block from the database.
779    ///
780    /// If the database is empty, returns the genesis block.
781    pub fn lookup_head(&self) -> eyre::Result<Head> {
782        self.node_config()
783            .lookup_head(self.provider_factory())
784            .wrap_err("the head block is missing")
785    }
786
787    /// Returns the metrics sender.
788    pub fn sync_metrics_tx(&self) -> UnboundedSender<MetricEvent> {
789        self.right().db_provider_container.metrics_sender.clone()
790    }
791
792    /// Returns a reference to the blockchain provider.
793    pub const fn blockchain_db(&self) -> &T::Provider {
794        &self.right().blockchain_db
795    }
796
797    /// Creates a `NodeAdapter` and attaches it to the launch context.
798    pub async fn with_components<CB>(
799        self,
800        components_builder: CB,
801        on_component_initialized: Box<
802            dyn OnComponentInitializedHook<NodeAdapter<T, CB::Components>>,
803        >,
804    ) -> eyre::Result<
805        LaunchContextWith<
806            Attached<WithConfigs<<T::Types as NodeTypes>::ChainSpec>, WithComponents<T, CB>>,
807        >,
808    >
809    where
810        CB: NodeComponentsBuilder<T>,
811    {
812        // fetch the head block from the database
813        let head = self.lookup_head()?;
814
815        let builder_ctx = BuilderContext::new(
816            head,
817            self.blockchain_db().clone(),
818            self.task_executor().clone(),
819            self.configs().clone(),
820        );
821
822        debug!(target: "reth::cli", "creating components");
823        let components = components_builder.build_components(&builder_ctx).await?;
824
825        let blockchain_db = self.blockchain_db().clone();
826
827        let node_adapter = NodeAdapter {
828            components,
829            task_executor: self.task_executor().clone(),
830            provider: blockchain_db,
831        };
832
833        debug!(target: "reth::cli", "calling on_component_initialized hook");
834        on_component_initialized.on_event(node_adapter.clone())?;
835
836        let components_container = WithComponents {
837            db_provider_container: WithMeteredProvider {
838                provider_factory: self.provider_factory().clone(),
839                metrics_sender: self.sync_metrics_tx(),
840            },
841            node_adapter,
842            head,
843        };
844
845        let ctx = LaunchContextWith {
846            inner: self.inner,
847            attachment: self.attachment.map_right(|_| components_container),
848        };
849
850        Ok(ctx)
851    }
852}
853
854impl<T, CB>
855    LaunchContextWith<
856        Attached<WithConfigs<<T::Types as NodeTypes>::ChainSpec>, WithComponents<T, CB>>,
857    >
858where
859    T: FullNodeTypes<Types: NodeTypesForProvider>,
860    CB: NodeComponentsBuilder<T>,
861{
862    /// Returns the configured `ProviderFactory`.
863    pub const fn provider_factory(
864        &self,
865    ) -> &ProviderFactory<NodeTypesWithDBAdapter<T::Types, T::DB>> {
866        &self.right().db_provider_container.provider_factory
867    }
868
869    /// Returns the max block that the node should run to, looking it up from the network if
870    /// necessary
871    pub async fn max_block<C>(&self, client: C) -> eyre::Result<Option<BlockNumber>>
872    where
873        C: HeadersClient<Header: BlockHeader>,
874    {
875        self.node_config().max_block(client, self.provider_factory().clone()).await
876    }
877
878    /// Returns the static file provider to interact with the static files.
879    pub fn static_file_provider(&self) -> StaticFileProvider<<T::Types as NodeTypes>::Primitives> {
880        self.provider_factory().static_file_provider()
881    }
882
883    /// Creates a new [`StaticFileProducer`] with the attached database.
884    pub fn static_file_producer(
885        &self,
886    ) -> StaticFileProducer<ProviderFactory<NodeTypesWithDBAdapter<T::Types, T::DB>>> {
887        StaticFileProducer::new(self.provider_factory().clone(), self.prune_modes())
888    }
889
890    /// Returns the current head block.
891    pub const fn head(&self) -> Head {
892        self.right().head
893    }
894
895    /// Returns the configured `NodeAdapter`.
896    pub const fn node_adapter(&self) -> &NodeAdapter<T, CB::Components> {
897        &self.right().node_adapter
898    }
899
900    /// Returns mutable reference to the configured `NodeAdapter`.
901    pub const fn node_adapter_mut(&mut self) -> &mut NodeAdapter<T, CB::Components> {
902        &mut self.right_mut().node_adapter
903    }
904
905    /// Returns a reference to the blockchain provider.
906    pub const fn blockchain_db(&self) -> &T::Provider {
907        &self.node_adapter().provider
908    }
909
910    /// Returns the initial backfill to sync to at launch.
911    ///
912    /// This returns the configured `debug.tip` if set, otherwise it will check if backfill was
913    /// previously interrupted and returns the block hash of the last checkpoint, see also
914    /// [`Self::check_pipeline_consistency`]
915    pub fn initial_backfill_target(&self) -> ProviderResult<Option<B256>> {
916        let mut initial_target = self.node_config().debug.tip;
917
918        if initial_target.is_none() {
919            initial_target = self.check_pipeline_consistency()?;
920        }
921
922        Ok(initial_target)
923    }
924
925    /// Returns true if the node should terminate after the initial backfill run.
926    ///
927    /// This is the case if any of these configs are set:
928    ///  `--debug.max-block`
929    ///  `--debug.terminate`
930    pub const fn terminate_after_initial_backfill(&self) -> bool {
931        self.node_config().debug.terminate || self.node_config().debug.max_block.is_some()
932    }
933
934    /// Ensures that the database matches chain-specific requirements.
935    ///
936    /// This checks for OP-Mainnet and ensures we have all the necessary data to progress (past
937    /// bedrock height)
938    fn ensure_chain_specific_db_checks(&self) -> ProviderResult<()> {
939        if self.chain_spec().is_optimism() &&
940            !self.is_dev() &&
941            self.chain_id() == Chain::optimism_mainnet()
942        {
943            let latest = self.blockchain_db().last_block_number()?;
944            // bedrock height
945            if latest < 105235063 {
946                error!(
947                    "Op-mainnet has been launched without importing the pre-Bedrock state. The chain can't progress without this. See also https://reth.rs/run/sync-op-mainnet.html?minimal-bootstrap-recommended"
948                );
949                return Err(ProviderError::BestBlockNotFound)
950            }
951        }
952
953        Ok(())
954    }
955
956    /// Check if the pipeline is consistent (all stages have the checkpoint block numbers no less
957    /// than the checkpoint of the first stage).
958    ///
959    /// This will return the pipeline target if:
960    ///  * the pipeline was interrupted during its previous run
961    ///  * a new stage was added
962    ///  * stage data was dropped manually through `reth stage drop ...`
963    ///
964    /// # Returns
965    ///
966    /// A target block hash if the pipeline is inconsistent, otherwise `None`.
967    pub fn check_pipeline_consistency(&self) -> ProviderResult<Option<B256>> {
968        // We skip the era stage if it's not enabled
969        let era_enabled = self.era_import_source().is_some();
970        let mut all_stages =
971            StageId::ALL.into_iter().filter(|id| era_enabled || id != &StageId::Era);
972
973        // Get the expected first stage based on config.
974        let first_stage = all_stages.next().expect("there must be at least one stage");
975
976        // If no target was provided, check if the stages are congruent - check if the
977        // checkpoint of the last stage matches the checkpoint of the first.
978        let first_stage_checkpoint = self
979            .blockchain_db()
980            .get_stage_checkpoint(first_stage)?
981            .unwrap_or_default()
982            .block_number;
983
984        // Compare all other stages against the first
985        for stage_id in all_stages {
986            let stage_checkpoint = self
987                .blockchain_db()
988                .get_stage_checkpoint(stage_id)?
989                .unwrap_or_default()
990                .block_number;
991
992            // If the checkpoint of any stage is less than the checkpoint of the first stage,
993            // retrieve and return the block hash of the latest header and use it as the target.
994            debug!(
995                target: "consensus::engine",
996                first_stage_id = %first_stage,
997                first_stage_checkpoint,
998                stage_id = %stage_id,
999                stage_checkpoint = stage_checkpoint,
1000                "Checking stage against first stage",
1001            );
1002            if stage_checkpoint < first_stage_checkpoint {
1003                debug!(
1004                    target: "consensus::engine",
1005                    first_stage_id = %first_stage,
1006                    first_stage_checkpoint,
1007                    inconsistent_stage_id = %stage_id,
1008                    inconsistent_stage_checkpoint = stage_checkpoint,
1009                    "Pipeline sync progress is inconsistent"
1010                );
1011                return self.blockchain_db().block_hash(first_stage_checkpoint);
1012            }
1013        }
1014
1015        self.ensure_chain_specific_db_checks()?;
1016
1017        Ok(None)
1018    }
1019
1020    /// Returns the metrics sender.
1021    pub fn sync_metrics_tx(&self) -> UnboundedSender<MetricEvent> {
1022        self.right().db_provider_container.metrics_sender.clone()
1023    }
1024
1025    /// Returns the node adapter components.
1026    pub const fn components(&self) -> &CB::Components {
1027        &self.node_adapter().components
1028    }
1029
1030    /// Launches ExEx (Execution Extensions) and returns the ExEx manager handle.
1031    #[allow(clippy::type_complexity)]
1032    pub async fn launch_exex(
1033        &self,
1034        installed_exex: Vec<(
1035            String,
1036            Box<dyn crate::exex::BoxedLaunchExEx<NodeAdapter<T, CB::Components>>>,
1037        )>,
1038    ) -> eyre::Result<Option<ExExManagerHandle<PrimitivesTy<T::Types>>>> {
1039        self.exex_launcher(installed_exex).launch().await
1040    }
1041
1042    /// Creates an [`ExExLauncher`] for the installed ExExes.
1043    ///
1044    /// This returns the launcher before calling `.launch()`, allowing custom configuration
1045    /// such as setting the WAL blocks warning threshold for L2 chains with faster block times:
1046    ///
1047    /// ```ignore
1048    /// ctx.exex_launcher(exexes)
1049    ///     .with_wal_blocks_warning(768)  // For 2-second block times
1050    ///     .launch()
1051    ///     .await
1052    /// ```
1053    #[allow(clippy::type_complexity)]
1054    pub fn exex_launcher(
1055        &self,
1056        installed_exex: Vec<(
1057            String,
1058            Box<dyn crate::exex::BoxedLaunchExEx<NodeAdapter<T, CB::Components>>>,
1059        )>,
1060    ) -> ExExLauncher<NodeAdapter<T, CB::Components>> {
1061        ExExLauncher::new(
1062            self.head(),
1063            self.node_adapter().clone(),
1064            installed_exex,
1065            self.configs().clone(),
1066        )
1067    }
1068
1069    /// Creates the ERA import source based on node configuration.
1070    ///
1071    /// Returns `Some(EraImportSource)` if ERA is enabled in the node config, otherwise `None`.
1072    pub fn era_import_source(&self) -> Option<EraImportSource> {
1073        let node_config = self.node_config();
1074        if !node_config.era.enabled {
1075            return None;
1076        }
1077
1078        EraImportSource::maybe_new(
1079            node_config.era.source.path.clone(),
1080            node_config.era.source.url.clone(),
1081            || node_config.chain.chain().kind().default_era_host(),
1082            || node_config.datadir().data_dir().join("era").into(),
1083        )
1084    }
1085
1086    /// Creates consensus layer health events stream based on node configuration.
1087    ///
1088    /// Returns a stream that monitors consensus layer health if:
1089    /// - No debug tip is configured
1090    /// - Not running in dev mode
1091    ///
1092    /// Otherwise returns an empty stream.
1093    pub fn consensus_layer_events(
1094        &self,
1095    ) -> impl Stream<Item = NodeEvent<PrimitivesTy<T::Types>>> + 'static
1096    where
1097        T::Provider: reth_provider::CanonChainTracker,
1098    {
1099        if self.node_config().debug.tip.is_none() && !self.is_dev() {
1100            Either::Left(
1101                ConsensusLayerHealthEvents::new(Box::new(self.blockchain_db().clone()))
1102                    .map(Into::into),
1103            )
1104        } else {
1105            Either::Right(stream::empty())
1106        }
1107    }
1108
1109    /// Spawns the [`EthStatsService`] service if configured.
1110    pub async fn spawn_ethstats<St>(&self, mut engine_events: St) -> eyre::Result<()>
1111    where
1112        St: Stream<Item = reth_engine_primitives::ConsensusEngineEvent<PrimitivesTy<T::Types>>>
1113            + Send
1114            + Unpin
1115            + 'static,
1116    {
1117        let Some(url) = self.node_config().debug.ethstats.as_ref() else { return Ok(()) };
1118
1119        let network = self.components().network().clone();
1120        let pool = self.components().pool().clone();
1121        let provider = self.node_adapter().provider.clone();
1122
1123        info!(target: "reth::cli", "Starting EthStats service at {}", url);
1124
1125        let ethstats = EthStatsService::new(url, network, provider, pool).await?;
1126
1127        // If engine events are provided, spawn listener for new payload reporting
1128        let ethstats_for_events = ethstats.clone();
1129        let task_executor = self.task_executor().clone();
1130        task_executor.spawn(Box::pin(async move {
1131            while let Some(event) = engine_events.next().await {
1132                use reth_engine_primitives::ConsensusEngineEvent;
1133                match event {
1134                    ConsensusEngineEvent::ForkBlockAdded(executed, duration) |
1135                    ConsensusEngineEvent::CanonicalBlockAdded(executed, duration) => {
1136                        let block_hash = executed.recovered_block.num_hash().hash;
1137                        let block_number = executed.recovered_block.num_hash().number;
1138                        if let Err(e) = ethstats_for_events
1139                            .report_new_payload(block_hash, block_number, duration)
1140                            .await
1141                        {
1142                            debug!(
1143                                target: "ethstats",
1144                                "Failed to report new payload: {}", e
1145                            );
1146                        }
1147                    }
1148                    _ => {
1149                        // Ignore other event types for ethstats reporting
1150                    }
1151                }
1152            }
1153        }));
1154
1155        // Spawn main ethstats service
1156        task_executor.spawn(Box::pin(async move { ethstats.run().await }));
1157
1158        Ok(())
1159    }
1160}
1161
1162/// Joins two attachments together, preserving access to both values.
1163///
1164/// This type enables the launch process to accumulate state while maintaining
1165/// access to all previously attached components. The `left` field holds the
1166/// previous state, while `right` holds the newly attached component.
1167#[derive(Clone, Copy, Debug)]
1168pub struct Attached<L, R> {
1169    left: L,
1170    right: R,
1171}
1172
1173impl<L, R> Attached<L, R> {
1174    /// Creates a new `Attached` with the given values.
1175    pub const fn new(left: L, right: R) -> Self {
1176        Self { left, right }
1177    }
1178
1179    /// Maps the left value to a new value.
1180    pub fn map_left<F, T>(self, f: F) -> Attached<T, R>
1181    where
1182        F: FnOnce(L) -> T,
1183    {
1184        Attached::new(f(self.left), self.right)
1185    }
1186
1187    /// Maps the right value to a new value.
1188    pub fn map_right<F, T>(self, f: F) -> Attached<L, T>
1189    where
1190        F: FnOnce(R) -> T,
1191    {
1192        Attached::new(self.left, f(self.right))
1193    }
1194
1195    /// Get a reference to the left value.
1196    pub const fn left(&self) -> &L {
1197        &self.left
1198    }
1199
1200    /// Get a reference to the right value.
1201    pub const fn right(&self) -> &R {
1202        &self.right
1203    }
1204
1205    /// Get a mutable reference to the left value.
1206    pub const fn left_mut(&mut self) -> &mut L {
1207        &mut self.left
1208    }
1209
1210    /// Get a mutable reference to the right value.
1211    pub const fn right_mut(&mut self) -> &mut R {
1212        &mut self.right
1213    }
1214}
1215
1216/// Helper container type to bundle the initial [`NodeConfig`] and the loaded settings from the
1217/// reth.toml config
1218#[derive(Debug)]
1219pub struct WithConfigs<ChainSpec> {
1220    /// The configured, usually derived from the CLI.
1221    pub config: NodeConfig<ChainSpec>,
1222    /// The loaded reth.toml config.
1223    pub toml_config: reth_config::Config,
1224}
1225
1226impl<ChainSpec> Clone for WithConfigs<ChainSpec> {
1227    fn clone(&self) -> Self {
1228        Self { config: self.config.clone(), toml_config: self.toml_config.clone() }
1229    }
1230}
1231
1232/// Helper container type to bundle the [`ProviderFactory`] and the metrics
1233/// sender.
1234#[derive(Debug, Clone)]
1235pub struct WithMeteredProvider<N: NodeTypesWithDB> {
1236    provider_factory: ProviderFactory<N>,
1237    metrics_sender: UnboundedSender<MetricEvent>,
1238}
1239
1240/// Helper container to bundle the [`ProviderFactory`], [`FullNodeTypes::Provider`]
1241/// and a metrics sender.
1242#[expect(missing_debug_implementations)]
1243pub struct WithMeteredProviders<T>
1244where
1245    T: FullNodeTypes,
1246{
1247    db_provider_container: WithMeteredProvider<NodeTypesWithDBAdapter<T::Types, T::DB>>,
1248    blockchain_db: T::Provider,
1249}
1250
1251/// Helper container to bundle the metered providers container and [`NodeAdapter`].
1252#[expect(missing_debug_implementations)]
1253pub struct WithComponents<T, CB>
1254where
1255    T: FullNodeTypes,
1256    CB: NodeComponentsBuilder<T>,
1257{
1258    db_provider_container: WithMeteredProvider<NodeTypesWithDBAdapter<T::Types, T::DB>>,
1259    node_adapter: NodeAdapter<T, CB::Components>,
1260    head: Head,
1261}
1262
1263/// Returns the metrics hooks for the node.
1264pub fn metrics_hooks<N: NodeTypesWithDB>(provider_factory: &ProviderFactory<N>) -> Hooks {
1265    Hooks::builder()
1266        .with_hook({
1267            let db = provider_factory.db_ref().clone();
1268            move || throttle!(Duration::from_secs(5 * 60), || db.report_metrics())
1269        })
1270        .with_hook({
1271            let sfp = provider_factory.static_file_provider();
1272            move || {
1273                throttle!(Duration::from_secs(5 * 60), || {
1274                    if let Err(error) = sfp.report_metrics() {
1275                        error!(%error, "Failed to report metrics from static file provider");
1276                    }
1277                })
1278            }
1279        })
1280        .build()
1281}
1282
1283#[cfg(test)]
1284mod tests {
1285    use super::{LaunchContext, NodeConfig};
1286    use reth_config::Config;
1287    use reth_node_core::args::PruningArgs;
1288
1289    const EXTENSION: &str = "toml";
1290
1291    fn with_tempdir(filename: &str, proc: fn(&std::path::Path)) {
1292        let temp_dir = tempfile::tempdir().unwrap();
1293        let config_path = temp_dir.path().join(filename).with_extension(EXTENSION);
1294        proc(&config_path);
1295        temp_dir.close().unwrap()
1296    }
1297
1298    #[test]
1299    fn test_save_prune_config() {
1300        with_tempdir("prune-store-test", |config_path| {
1301            let mut reth_config = Config::default();
1302            let node_config = NodeConfig {
1303                pruning: PruningArgs {
1304                    full: true,
1305                    minimal: false,
1306                    block_interval: None,
1307                    sender_recovery_full: false,
1308                    sender_recovery_distance: None,
1309                    sender_recovery_before: None,
1310                    transaction_lookup_full: false,
1311                    transaction_lookup_distance: None,
1312                    transaction_lookup_before: None,
1313                    receipts_full: false,
1314                    receipts_pre_merge: false,
1315                    receipts_distance: None,
1316                    receipts_before: None,
1317                    account_history_full: false,
1318                    account_history_distance: None,
1319                    account_history_before: None,
1320                    storage_history_full: false,
1321                    storage_history_distance: None,
1322                    storage_history_before: None,
1323                    bodies_pre_merge: false,
1324                    bodies_distance: None,
1325                    receipts_log_filter: None,
1326                    bodies_before: None,
1327                },
1328                ..NodeConfig::test()
1329            };
1330            LaunchContext::save_pruning_config(&mut reth_config, &node_config, config_path)
1331                .unwrap();
1332
1333            let loaded_config = Config::from_path(config_path).unwrap();
1334
1335            assert_eq!(reth_config, loaded_config);
1336        })
1337    }
1338}