Skip to content

Commit

Permalink
feat: add providerfactory builder to OpNode (#14322)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Feb 8, 2025
1 parent 44985c3 commit 7603b74
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
4 changes: 2 additions & 2 deletions crates/ethereum/node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ impl EthereumNode {
/// use reth_db::open_db_read_only;
/// use reth_node_ethereum::EthereumNode;
/// use reth_provider::providers::StaticFileProvider;
/// use std::{path::Path, sync::Arc};
/// use std::sync::Arc;
///
/// let factory = EthereumNode::provider_factory_builder()
/// .db(Arc::new(open_db_read_only(Path::new("db"), Default::default()).unwrap()))
/// .db(Arc::new(open_db_read_only("db", Default::default()).unwrap()))
/// .chainspec(ChainSpecBuilder::mainnet().build().into())
/// .static_file(StaticFileProvider::read_only("db/static_files", false).unwrap())
/// .build_provider_factory();
Expand Down
36 changes: 35 additions & 1 deletion crates/optimism/node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use reth_optimism_rpc::{
witness::{DebugExecutionWitnessApiServer, OpDebugWitnessApi},
OpEthApi, OpEthApiError, SequencerClient,
};
use reth_provider::{CanonStateSubscriptions, EthStorage};
use reth_provider::{providers::ProviderFactoryBuilder, CanonStateSubscriptions, EthStorage};
use reth_rpc_eth_types::error::FromEvmError;
use reth_rpc_server_types::RethRpcModule;
use reth_tracing::tracing::{debug, info};
Expand Down Expand Up @@ -115,6 +115,40 @@ impl OpNode {
.executor(OpExecutorBuilder::default())
.consensus(OpConsensusBuilder::default())
}

/// Instantiates the [`ProviderFactoryBuilder`] for an opstack node.
///
/// # Open a Providerfactory in read-only mode from a datadir
///
/// See also: [`ProviderFactoryBuilder`] and
/// [`ReadOnlyConfig`](reth_provider::providers::ReadOnlyConfig).
///
/// ```no_run
/// use reth_optimism_chainspec::BASE_MAINNET;
/// use reth_optimism_node::OpNode;
///
/// let factory =
/// OpNode::provider_factory_builder().open_read_only(BASE_MAINNET.clone(), "datadir").unwrap();
/// ```
///
/// # Open a Providerfactory manually with with all required components
///
/// ```no_run
/// use reth_db::open_db_read_only;
/// use reth_optimism_chainspec::OpChainSpecBuilder;
/// use reth_optimism_node::OpNode;
/// use reth_provider::providers::StaticFileProvider;
/// use std::sync::Arc;
///
/// let factory = OpNode::provider_factory_builder()
/// .db(Arc::new(open_db_read_only("db", Default::default()).unwrap()))
/// .chainspec(OpChainSpecBuilder::base_mainnet().build().into())
/// .static_file(StaticFileProvider::read_only("db/static_files", false).unwrap())
/// .build_provider_factory();
/// ```
pub fn provider_factory_builder() -> ProviderFactoryBuilder<Self> {
ProviderFactoryBuilder::default()
}
}

impl<N> Node<N> for OpNode
Expand Down

0 comments on commit 7603b74

Please sign in to comment.