diff --git a/bin/node/src/cli.rs b/bin/node/src/cli.rs index 40b3cbd7..4ae92dc5 100644 --- a/bin/node/src/cli.rs +++ b/bin/node/src/cli.rs @@ -1,6 +1,8 @@ //! Contains the CLI arguments -use base_reth_runner::{BaseNodeConfig, FlashblocksConfig, TracingConfig}; +use std::path::PathBuf; + +use base_reth_runner::{BaseNodeConfig, FlashblocksConfig, ProofsConfig, TracingConfig}; use reth_optimism_node::args::RollupArgs; /// CLI Arguments @@ -37,6 +39,19 @@ pub struct Args { /// Enable metering RPC for transaction bundle simulation #[arg(long = "enable-metering", value_name = "ENABLE_METERING")] pub enable_metering: bool, + + /// If true, initialize external-proofs exex to save and serve trie nodes to provide proofs + /// faster. + #[arg(long = "proofs-history", value_name = "PROOFS_HISTORY", default_value = "false")] + pub proofs_history: bool, + + /// The path to the storage DB for proofs history. + #[arg( + long = "proofs-history.storage-path", + value_name = "PROOFS_HISTORY_STORAGE_PATH", + required_if_eq("proofs_history", "true") + )] + pub proofs_history_storage_path: Option, } impl Args { @@ -45,22 +60,39 @@ impl Args { pub const fn flashblocks_enabled(&self) -> bool { self.websocket_url.is_some() } + + /// Returns the [`FlashblocksConfig`] if flashblocks is enabled. + pub fn flashblocks_config(&self) -> Option { + self.websocket_url.as_ref().map(|websocket_url| FlashblocksConfig { + websocket_url: websocket_url.clone(), + max_pending_blocks_depth: self.max_pending_blocks_depth, + }) + } + + /// Returns the [`ProofsConfig`]. + pub fn proofs_config(&self) -> ProofsConfig { + ProofsConfig { + enabled: self.proofs_history, + storage_path: self.proofs_history_storage_path.clone(), + } + } + + /// Returns the [`TracingConfig`]. + pub const fn tracing_config(&self) -> TracingConfig { + TracingConfig { + enabled: self.enable_transaction_tracing, + logs_enabled: self.enable_transaction_tracing_logs, + } + } } impl From for BaseNodeConfig { fn from(args: Args) -> Self { - let flashblocks = args.websocket_url.map(|websocket_url| FlashblocksConfig { - websocket_url, - max_pending_blocks_depth: args.max_pending_blocks_depth, - }); - Self { + flashblocks: args.flashblocks_config(), + proofs: args.proofs_config(), + tracing: args.tracing_config(), rollup_args: args.rollup_args, - flashblocks, - tracing: TracingConfig { - enabled: args.enable_transaction_tracing, - logs_enabled: args.enable_transaction_tracing_logs, - }, metering_enabled: args.enable_metering, } } diff --git a/crates/runner/src/config.rs b/crates/runner/src/config.rs index 56029c6b..b83abfe0 100644 --- a/crates/runner/src/config.rs +++ b/crates/runner/src/config.rs @@ -11,6 +11,8 @@ pub struct BaseNodeConfig { pub flashblocks: Option, /// Execution extension tracing toggles. pub tracing: TracingConfig, + /// Proofs extension configuration. + pub proofs: ProofsConfig, /// Indicates whether the metering RPC surface should be installed. pub metering_enabled: bool, } @@ -31,6 +33,16 @@ pub struct FlashblocksConfig { pub max_pending_blocks_depth: u64, } +/// Proofs Extension Configuration. +#[derive(Debug, Clone)] +pub struct ProofsConfig { + /// If true, initializes external-proofs ExEx to save and serve trie nodes to provide proofs + /// faster. + pub enabled: bool, + /// The path to the storage DB for proofs history. + pub storage_path: Option, +} + /// Transaction tracing toggles. #[derive(Debug, Clone, Copy)] pub struct TracingConfig { diff --git a/crates/runner/src/extensions/mod.rs b/crates/runner/src/extensions/mod.rs index f9204126..2094d952 100644 --- a/crates/runner/src/extensions/mod.rs +++ b/crates/runner/src/extensions/mod.rs @@ -3,6 +3,9 @@ //! Builder extensions for the node nicely modularizes parts //! of the node building process. +mod proofs; +pub use proofs::ProofsExtension; + mod canon; pub use canon::FlashblocksCanonExtension; @@ -13,4 +16,4 @@ mod tracing; pub use tracing::TransactionTracingExtension; mod types; -pub use types::{FlashblocksCell, OpBuilder, OpProvider}; +pub use types::{FlashblocksCell, OpBuilder, OpProvider, ProofsCell}; diff --git a/crates/runner/src/extensions/proofs.rs b/crates/runner/src/extensions/proofs.rs new file mode 100644 index 00000000..511597c8 --- /dev/null +++ b/crates/runner/src/extensions/proofs.rs @@ -0,0 +1,24 @@ +//! Contains a [`ProofsExtensions`] which stores intermediate storage updates. + +use crate::{ProofsCell, ProofsConfig, extensions::OpBuilder}; + +/// Proofs Extension. +#[derive(Debug, Clone)] +pub struct ProofsExtension { + /// Shared state. + pub cell: ProofsCell, + /// Proofs config. + pub config: ProofsConfig, +} + +impl ProofsExtension { + /// Create a new Proofs extension helper. + pub const fn new(cell: ProofsCell, config: ProofsConfig) -> Self { + Self { cell, config } + } + + /// Applies the extension to the supplied builder. + pub fn apply(&self, _builder: OpBuilder) -> OpBuilder { + unimplemented!("ProofsExtension::apply is not yet implemented") + } +} diff --git a/crates/runner/src/extensions/types.rs b/crates/runner/src/extensions/types.rs index 444dc56c..e0165744 100644 --- a/crates/runner/src/extensions/types.rs +++ b/crates/runner/src/extensions/types.rs @@ -25,3 +25,6 @@ pub type OpBuilder = /// The flashblocks cell holds the [`FlashblocksState`]. pub type FlashblocksCell = Arc>>>; + +/// A cell holding the proofs state. +pub type ProofsCell = Arc>>; diff --git a/crates/runner/src/lib.rs b/crates/runner/src/lib.rs index 82025faf..fe35c31d 100644 --- a/crates/runner/src/lib.rs +++ b/crates/runner/src/lib.rs @@ -10,10 +10,10 @@ mod runner; pub use runner::BaseNodeRunner; mod config; -pub use config::{BaseNodeConfig, FlashblocksConfig, TracingConfig}; +pub use config::{BaseNodeConfig, FlashblocksConfig, ProofsConfig, TracingConfig}; mod extensions; pub use extensions::{ BaseRpcExtension, FlashblocksCanonExtension, FlashblocksCell, OpBuilder, OpProvider, - TransactionTracingExtension, + ProofsCell, ProofsExtension, TransactionTracingExtension, }; diff --git a/crates/runner/src/runner.rs b/crates/runner/src/runner.rs index e4574036..7377f87d 100644 --- a/crates/runner/src/runner.rs +++ b/crates/runner/src/runner.rs @@ -12,8 +12,8 @@ use reth_optimism_node::OpNode; use tracing::info; use crate::{ - BaseNodeBuilder, BaseNodeConfig, BaseRpcExtension, FlashblocksCanonExtension, - TransactionTracingExtension, + BaseNodeBuilder, BaseNodeConfig, BaseRpcExtension, FlashblocksCanonExtension, ProofsCell, + ProofsExtension, TransactionTracingExtension, }; /// Wraps the Base node configuration and orchestrates builder wiring. @@ -54,10 +54,17 @@ impl BaseNodeRunner { FlashblocksCanonExtension::new(flashblocks_cell.clone(), flashblocks_config.clone()); let builder = flashblocks_extension.apply(builder); + // Apply the Proofs extension + let proofs_cell: ProofsCell<()> = Arc::new(OnceCell::new()); + let proofs_extension = + ProofsExtension::new(proofs_cell.clone(), self.config.proofs.clone()); + let builder = ProofsExtension::apply(&proofs_extension, builder); + // Apply the Transaction Tracing extension let tracing_extension = TransactionTracingExtension::new(self.config.tracing); let builder = tracing_extension.apply(builder); + // Apply the Base RPC extension let rpc_extension = BaseRpcExtension::new( flashblocks_cell.clone(), flashblocks_config.clone(),