Skip to content

Commit

Permalink
feat: integrate OpChainSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr committed Sep 27, 2024
1 parent 9b1c5f4 commit 6373bda
Show file tree
Hide file tree
Showing 20 changed files with 77 additions and 63 deletions.
5 changes: 2 additions & 3 deletions crates/e2e-test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use reth::{
rpc::api::eth::{helpers::AddDevSigners, FullEthApiServer},
tasks::TaskManager,
};
use reth_chainspec::{ChainSpec, EthChainSpec, EthereumHardforks};
use reth_chainspec::{EthChainSpec, EthereumHardforks};
use reth_db::{test_utils::TempDatabase, DatabaseEnv};
use reth_node_builder::{
components::NodeComponentsBuilder, rpc::EthApiBuilderProvider, FullNodeTypesAdapter, Node,
Expand Down Expand Up @@ -73,8 +73,7 @@ where
let mut nodes: Vec<NodeTestContext<_, _>> = Vec::with_capacity(num_nodes);

for idx in 0..num_nodes {
let node_config = NodeConfig::test()
.with_chain(chain_spec.clone())
let node_config = NodeConfig::new(chain_spec.clone())
.with_network(network_config.clone())
.with_unused_ports()
.with_rpc(RpcServerArgs::default().with_unused_ports().with_http())
Expand Down
14 changes: 11 additions & 3 deletions crates/engine/invalid-block-hooks/src/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use alloy_primitives::{keccak256, B256, U256};
use alloy_rpc_types_debug::ExecutionWitness;
use eyre::OptionExt;
use pretty_assertions::Comparison;
use reth_chainspec::ChainSpec;
use reth_chainspec::{EthChainSpec, EthereumHardforks};
use reth_engine_primitives::InvalidBlockHook;
use reth_evm::{
system_calls::{apply_beacon_root_contract_call, apply_blockhashes_contract_call},
Expand Down Expand Up @@ -52,7 +52,11 @@ impl<P, EvmConfig> InvalidBlockWitnessHook<P, EvmConfig> {

impl<P, EvmConfig> InvalidBlockWitnessHook<P, EvmConfig>
where
P: StateProviderFactory + ChainSpecProvider<ChainSpec = ChainSpec> + Send + Sync + 'static,
P: StateProviderFactory
+ ChainSpecProvider<ChainSpec: EthChainSpec + EthereumHardforks>
+ Send
+ Sync
+ 'static,
EvmConfig: ConfigureEvm<Header = Header>,
{
fn on_invalid_block(
Expand Down Expand Up @@ -295,7 +299,11 @@ where

impl<P, EvmConfig> InvalidBlockHook for InvalidBlockWitnessHook<P, EvmConfig>
where
P: StateProviderFactory + ChainSpecProvider<ChainSpec = ChainSpec> + Send + Sync + 'static,
P: StateProviderFactory
+ ChainSpecProvider<ChainSpec: EthChainSpec + EthereumHardforks>
+ Send
+ Sync
+ 'static,
EvmConfig: ConfigureEvm<Header = Header>,
{
fn on_invalid_block(
Expand Down
6 changes: 3 additions & 3 deletions crates/node/builder/src/launch/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use reth_beacon_consensus::EthBeaconConsensus;
use reth_blockchain_tree::{
BlockchainTree, BlockchainTreeConfig, ShareableBlockchainTree, TreeExternals,
};
use reth_chainspec::{Chain, ChainSpec, EthChainSpec, EthereumHardforks};
use reth_chainspec::{Chain, EthChainSpec, EthereumHardforks};
use reth_config::{config::EtlConfig, PruneConfig};
use reth_consensus::Consensus;
use reth_db_api::database::Database;
Expand Down Expand Up @@ -879,8 +879,8 @@ impl<T, CB>
>
where
T: FullNodeTypes<
Provider: WithTree + StateProviderFactory + ChainSpecProvider<ChainSpec = ChainSpec>,
Types: NodeTypes<ChainSpec = ChainSpec>,
Provider: WithTree + StateProviderFactory + ChainSpecProvider,
Types: NodeTypes<ChainSpec: EthereumHardforks>,
>,
CB: NodeComponentsBuilder<T>,
{
Expand Down
15 changes: 7 additions & 8 deletions crates/node/builder/src/launch/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use reth_beacon_consensus::{
BeaconConsensusEngineHandle,
};
use reth_blockchain_tree::BlockchainTreeConfig;
use reth_chainspec::ChainSpec;
use reth_chainspec::EthChainSpec;
use reth_consensus_debug_client::{DebugConsensusClient, EtherscanBlockProvider};
use reth_engine_service::service::{ChainEvent, EngineService};
use reth_engine_tree::{
Expand All @@ -18,9 +18,7 @@ use reth_engine_util::EngineMessageStreamExt;
use reth_exex::ExExManagerHandle;
use reth_network::{NetworkSyncUpdater, SyncState};
use reth_network_api::{BlockDownloaderProvider, NetworkEventListenerProvider};
use reth_node_api::{
BuiltPayload, FullNodeTypes, NodeAddOns, NodeTypesWithDB, NodeTypesWithEngine,
};
use reth_node_api::{BuiltPayload, FullNodeTypes, NodeAddOns, NodeTypesWithEngine};
use reth_node_core::{
dirs::{ChainPath, DataDirPath},
exit::NodeExitFuture,
Expand All @@ -30,7 +28,8 @@ use reth_node_core::{
};
use reth_node_events::{cl::ConsensusLayerHealthEvents, node};
use reth_payload_primitives::PayloadBuilder;
use reth_provider::providers::BlockchainProvider2;
use reth_primitives::EthereumHardforks;
use reth_provider::providers::{BlockchainProvider2, ProviderNodeTypes};
use reth_rpc_engine_api::{capabilities::EngineCapabilities, EngineApi};
use reth_tasks::TaskExecutor;
use reth_tokio_util::EventSender;
Expand Down Expand Up @@ -72,7 +71,7 @@ impl EngineNodeLauncher {

impl<Types, T, CB, AO> LaunchNode<NodeBuilderWithComponents<T, CB, AO>> for EngineNodeLauncher
where
Types: NodeTypesWithDB<ChainSpec = ChainSpec> + NodeTypesWithEngine,
Types: ProviderNodeTypes + NodeTypesWithEngine,
T: FullNodeTypes<Types = Types, Provider = BlockchainProvider2<Types>>,
CB: NodeComponentsBuilder<T>,
AO: NodeAddOns<
Expand Down Expand Up @@ -127,7 +126,7 @@ where
debug!(target: "reth::cli", chain=%this.chain_id(), genesis=?this.genesis_hash(), "Initializing genesis");
})
.with_genesis()?
.inspect(|this: &LaunchContextWith<Attached<WithConfigs<ChainSpec>, _>>| {
.inspect(|this: &LaunchContextWith<Attached<WithConfigs<Types::ChainSpec>, _>>| {
info!(target: "reth::cli", "\n{}", this.chain_spec().display_hardforks());
})
.with_metrics_task()
Expand Down Expand Up @@ -296,7 +295,7 @@ where
if let Some(maybe_custom_etherscan_url) = ctx.node_config().debug.etherscan.clone() {
info!(target: "reth::cli", "Using etherscan as consensus client");

let chain = ctx.node_config().chain.chain;
let chain = ctx.node_config().chain.chain();
let etherscan_url = maybe_custom_etherscan_url.map(Ok).unwrap_or_else(|| {
// If URL isn't provided, use default Etherscan URL for the chain if it is known
chain
Expand Down
35 changes: 20 additions & 15 deletions crates/node/core/src/node_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,25 @@ impl NodeConfig<ChainSpec> {
}

impl<ChainSpec> NodeConfig<ChainSpec> {
/// Creates a new config with given chain spec, setting all fields to default values.
pub fn new(chain: Arc<ChainSpec>) -> Self {
Self {
config: None,
chain,
metrics: None,
instance: 1,
network: NetworkArgs::default(),
rpc: RpcServerArgs::default(),
txpool: TxPoolArgs::default(),
builder: PayloadBuilderArgs::default(),
debug: DebugArgs::default(),
db: DatabaseArgs::default(),
dev: DevArgs::default(),
pruning: PruningArgs::default(),
datadir: DatadirArgs::default(),
}
}

/// Sets --dev mode for the node.
///
/// In addition to setting the `--dev` flag, this also:
Expand Down Expand Up @@ -407,21 +426,7 @@ impl<ChainSpec> NodeConfig<ChainSpec> {

impl Default for NodeConfig<ChainSpec> {
fn default() -> Self {
Self {
config: None,
chain: MAINNET.clone(),
metrics: None,
instance: 1,
network: NetworkArgs::default(),
rpc: RpcServerArgs::default(),
txpool: TxPoolArgs::default(),
builder: PayloadBuilderArgs::default(),
debug: DebugArgs::default(),
db: DatabaseArgs::default(),
dev: DevArgs::default(),
pruning: PruningArgs::default(),
datadir: DatadirArgs::default(),
}
Self::new(MAINNET.clone())
}
}

Expand Down
5 changes: 2 additions & 3 deletions crates/optimism/cli/src/chainspec.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::sync::Arc;

use reth_chainspec::ChainSpec;
use reth_cli::chainspec::ChainSpecParser;
use reth_node_core::args::utils::parse_custom_chain_spec;
use reth_optimism_chainspec::{
Expand All @@ -27,7 +26,7 @@ fn chain_value_parser(s: &str) -> eyre::Result<Arc<OpChainSpec>, eyre::Error> {
pub struct OpChainSpecParser;

impl ChainSpecParser for OpChainSpecParser {
type ChainSpec = ChainSpec;
type ChainSpec = OpChainSpec;

const SUPPORTED_CHAINS: &'static [&'static str] = &[
"dev",
Expand All @@ -40,7 +39,7 @@ impl ChainSpecParser for OpChainSpecParser {
];

fn parse(s: &str) -> eyre::Result<Arc<Self::ChainSpec>> {
chain_value_parser(s).map(|s| Arc::new(Arc::unwrap_or_clone(s).inner))
chain_value_parser(s)
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/optimism/cli/src/commands/build_pipeline.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use alloy_primitives::B256;
use futures_util::{Stream, StreamExt};
use reth_chainspec::ChainSpec;
use reth_config::Config;
use reth_consensus::Consensus;
use reth_downloaders::{
Expand All @@ -15,6 +14,7 @@ use reth_network_p2p::{
};
use reth_node_builder::NodeTypesWithDB;
use reth_node_events::node::NodeEvent;
use reth_optimism_chainspec::OpChainSpec;
use reth_provider::{BlockNumReader, ChainSpecProvider, HeaderProvider, ProviderFactory};
use reth_prune::PruneModes;
use reth_stages::{sets::DefaultStages, Pipeline, StageSet};
Expand All @@ -36,7 +36,7 @@ pub(crate) async fn build_import_pipeline<N, C>(
disable_exec: bool,
) -> eyre::Result<(Pipeline<N>, impl Stream<Item = NodeEvent>)>
where
N: NodeTypesWithDB<ChainSpec = ChainSpec>,
N: NodeTypesWithDB<ChainSpec = OpChainSpec>,
C: Consensus + 'static,
{
if !file_client.has_canonical_blocks() {
Expand Down
2 changes: 1 addition & 1 deletion crates/optimism/cli/src/commands/import.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Command that initializes the node by importing OP Mainnet chain segment below Bedrock, from a
//! file.
use clap::Parser;
use reth_chainspec::ChainSpec;
use reth_cli::chainspec::ChainSpecParser;
use reth_cli_commands::common::{AccessRights, Environment, EnvironmentArgs};
use reth_consensus::noop::NoopConsensus;
Expand All @@ -12,6 +11,7 @@ use reth_downloaders::file_client::{
};
use reth_node_builder::NodeTypesWithEngine;
use reth_node_core::version::SHORT_VERSION;
use reth_optimism_chainspec::OpChainSpec;
use reth_optimism_primitives::bedrock::is_dup_tx;
use reth_provider::StageCheckpointReader;
use reth_prune::PruneModes;
Expand Down
12 changes: 6 additions & 6 deletions crates/optimism/cli/src/commands/import_receipts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use std::path::{Path, PathBuf};

use clap::Parser;
use reth_chainspec::ChainSpec;
use reth_cli::chainspec::ChainSpecParser;
use reth_cli_commands::common::{AccessRights, Environment, EnvironmentArgs};
use reth_db::tables;
Expand All @@ -15,12 +14,13 @@ use reth_downloaders::{
use reth_execution_types::ExecutionOutcome;
use reth_node_builder::{NodeTypesWithDB, NodeTypesWithEngine};
use reth_node_core::version::SHORT_VERSION;
use reth_optimism_chainspec::OpChainSpec;
use reth_optimism_primitives::bedrock::is_dup_tx;
use reth_primitives::Receipts;
use reth_provider::{
writer::UnifiedStorageWriter, DatabaseProviderFactory, OriginalValuesKnown, ProviderFactory,
StageCheckpointReader, StageCheckpointWriter, StateWriter, StaticFileProviderFactory,
StaticFileWriter, StatsReader,
providers::ProviderNodeTypes, writer::UnifiedStorageWriter, DatabaseProviderFactory,
OriginalValuesKnown, ProviderFactory, StageCheckpointReader, StageCheckpointWriter,
StateWriter, StaticFileProviderFactory, StaticFileWriter, StatsReader,
};
use reth_stages::{StageCheckpoint, StageId};
use reth_static_file_types::StaticFileSegment;
Expand Down Expand Up @@ -88,7 +88,7 @@ pub async fn import_receipts_from_file<N, P, F>(
filter: F,
) -> eyre::Result<()>
where
N: NodeTypesWithDB<ChainSpec = ChainSpec>,
N: NodeTypesWithDB<ChainSpec = OpChainSpec>,
P: AsRef<Path>,
F: FnMut(u64, &mut Receipts) -> usize,
{
Expand Down Expand Up @@ -126,7 +126,7 @@ pub async fn import_receipts_from_reader<N, F>(
mut filter: F,
) -> eyre::Result<ImportReceiptsResult>
where
N: NodeTypesWithDB<ChainSpec = ChainSpec>,
N: ProviderNodeTypes,
F: FnMut(u64, &mut Receipts) -> usize,
{
let static_file_provider = provider_factory.static_file_provider();
Expand Down
1 change: 0 additions & 1 deletion crates/optimism/cli/src/commands/init_state/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Command that initializes the node from a genesis file.

use clap::Parser;
use reth_chainspec::ChainSpec;
use reth_cli::chainspec::ChainSpecParser;
use reth_cli_commands::common::{AccessRights, Environment};
use reth_db_common::init::init_from_state_dump;
Expand Down
3 changes: 1 addition & 2 deletions crates/optimism/cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::chainspec::OpChainSpecParser;
use clap::Subcommand;
use import::ImportOpCommand;
use import_receipts::ImportReceiptsOpCommand;
use reth_chainspec::ChainSpec;
use reth_cli::chainspec::ChainSpecParser;
use reth_cli_commands::{
config_cmd, db, dump_genesis, init_cmd,
Expand All @@ -19,7 +18,7 @@ pub mod init_state;

/// Commands to be executed
#[derive(Debug, Subcommand)]
pub enum Commands<SpeC: ChainSpecParser = OpChainSpecParser, Ext: clap::Args + fmt::Debug = NoArgs>
pub enum Commands<Spec: ChainSpecParser = OpChainSpecParser, Ext: clap::Args + fmt::Debug = NoArgs>
{
/// Start the node
#[command(name = "node")]
Expand Down
5 changes: 3 additions & 2 deletions crates/optimism/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ pub mod commands;
pub mod receipt_file_codec;

pub use commands::{import::ImportOpCommand, import_receipts::ImportReceiptsOpCommand};
use reth_optimism_chainspec::OpChainSpec;

use std::{ffi::OsString, fmt, sync::Arc};

use chainspec::OpChainSpecParser;
use clap::{command, value_parser, Parser};
use commands::Commands;
use futures_util::Future;
use reth_chainspec::{ChainSpec, EthChainSpec};
use reth_chainspec::EthChainSpec;
use reth_cli::chainspec::ChainSpecParser;
use reth_cli_commands::node::NoArgs;
use reth_cli_runner::CliRunner;
Expand Down Expand Up @@ -111,7 +112,7 @@ impl Cli {

impl<C, Ext> Cli<C, Ext>
where
C: ChainSpecParser<ChainSpec: EthChainSpec>,
C: ChainSpecParser<ChainSpec = OpChainSpec>,
Ext: clap::Args + fmt::Debug,
{
/// Execute the configured cli command.
Expand Down
6 changes: 3 additions & 3 deletions crates/optimism/node/tests/e2e/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use reth_e2e_test_utils::{transaction::TransactionTestContext, wallet::Wallet, N
use reth_node_optimism::{
node::OptimismAddOns, OptimismBuiltPayload, OptimismNode, OptimismPayloadBuilderAttributes,
};
use reth_optimism_chainspec::BASE_MAINNET;
use reth_optimism_chainspec::{OpChainSpec, BASE_MAINNET};
use reth_payload_builder::EthPayloadBuilderAttributes;
use tokio::sync::Mutex;

Expand All @@ -19,13 +19,13 @@ pub(crate) async fn setup(num_nodes: usize) -> eyre::Result<(Vec<OpNode>, TaskMa
let genesis: Genesis = serde_json::from_str(include_str!("../assets/genesis.json")).unwrap();
reth_e2e_test_utils::setup(
num_nodes,
Arc::new(
Arc::new(OpChainSpec::new(
ChainSpecBuilder::default()
.chain(BASE_MAINNET.chain)
.genesis(genesis)
.ecotone_activated()
.build(),
),
)),
false,
)
.await
Expand Down
3 changes: 2 additions & 1 deletion crates/optimism/node/tests/it/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ use reth_db::test_utils::create_test_rw_db;
use reth_node_api::FullNodeComponents;
use reth_node_builder::{NodeBuilder, NodeConfig};
use reth_node_optimism::node::{OptimismAddOns, OptimismNode};
use reth_primitives::BASE_MAINNET;

#[test]
fn test_basic_setup() {
// parse CLI -> config
let config = NodeConfig::test();
let config = NodeConfig::new(BASE_MAINNET.clone());
let db = create_test_rw_db();
let _builder = NodeBuilder::new(config)
.with_database(db)
Expand Down
1 change: 1 addition & 0 deletions crates/optimism/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ reth-chainspec.workspace = true
# op-reth
reth-evm-optimism.workspace = true
reth-optimism-consensus.workspace = true
reth-optimism-chainspec.workspace = true
reth-optimism-forks.workspace = true

# ethereum
Expand Down
Loading

0 comments on commit 6373bda

Please sign in to comment.