Expand description
RPC component builder
§Example
Builds offline TraceApi
with only EVM and database. This can be useful
for example when downloading a state snapshot (pre-synced node) from some mirror.
use alloy_rpc_types_eth::BlockId;
use op_alloy_network::Optimism;
use reth_db::test_utils::create_test_rw_db_with_path;
use reth_node_builder::{
components::ComponentsBuilder,
hooks::OnComponentInitializedHook,
rpc::{EthApiBuilder, EthApiCtx},
LaunchContext, NodeConfig, RethFullAdapter,
};
use reth_optimism_chainspec::OP_SEPOLIA;
use reth_optimism_evm::OpEvmConfig;
use reth_optimism_node::{OpExecutorBuilder, OpNetworkPrimitives, OpNode};
use reth_optimism_rpc::OpEthApiBuilder;
use reth_optimism_txpool::OpPooledTransaction;
use reth_provider::providers::BlockchainProvider;
use reth_rpc::TraceApi;
use reth_rpc_eth_types::{EthConfig, EthStateCache};
use reth_tasks::{pool::BlockingTaskGuard, TaskManager};
use std::sync::Arc;
#[tokio::main]
async fn main() {
// build core node with all components disabled except EVM and state
let sepolia = NodeConfig::new(OP_SEPOLIA.clone());
let db = create_test_rw_db_with_path(sepolia.datadir());
let tasks = TaskManager::current();
let launch_ctx = LaunchContext::new(tasks.executor(), sepolia.datadir());
let node = launch_ctx
.with_loaded_toml_config(sepolia)
.unwrap()
.attach(Arc::new(db))
.with_provider_factory::<_, OpEvmConfig>()
.await
.unwrap()
.with_genesis()
.unwrap()
.with_metrics_task() // todo: shouldn't be req to set up blockchain db
.with_blockchain_db::<RethFullAdapter<_, OpNode>, _>(move |provider_factory| {
Ok(BlockchainProvider::new(provider_factory).unwrap())
})
.unwrap()
.with_components(
ComponentsBuilder::default()
.node_types::<RethFullAdapter<_, OpNode>>()
.noop_pool::<OpPooledTransaction>()
.noop_network::<OpNetworkPrimitives>()
.noop_consensus()
.executor(OpExecutorBuilder::default())
.noop_payload(),
Box::new(()) as Box<dyn OnComponentInitializedHook<_>>,
)
.await
.unwrap();
// build `eth` namespace API
let config = EthConfig::default();
let cache = EthStateCache::spawn_with(
node.provider_factory().clone(),
config.cache,
node.task_executor().clone(),
);
let ctx = EthApiCtx { components: node.node_adapter(), config, cache };
let eth_api = OpEthApiBuilder::<Optimism>::default().build_eth_api(ctx).await.unwrap();
// build `trace` namespace API
let trace_api = TraceApi::new(eth_api, BlockingTaskGuard::new(10), EthConfig::default());
// fetch traces for latest block
let traces = trace_api.trace_block(BlockId::latest()).await.unwrap();
}
Structs§
- OpEngine
Api - The Engine API implementation that grants the Consensus layer access to data and functions in the Execution layer that are crucial for the consensus process.
- OpEngine
ApiBuilder - Builder for basic
OpEngineApi
implementation. - OpEth
Api - OP-Reth
Eth
API implementation. - OpEth
ApiBuilder - Builds
OpEthApi
for Optimism.