Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr committed Sep 27, 2024
1 parent 59c8260 commit 9b1c5f4
Show file tree
Hide file tree
Showing 32 changed files with 101 additions and 82 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bin/reth/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl Cli {
}
}

impl<C: ChainSpecParser, Ext: clap::Args + fmt::Debug> Cli<C, Ext> {
impl<C: ChainSpecParser<ChainSpec = ChainSpec>, Ext: clap::Args + fmt::Debug> Cli<C, Ext> {
/// Execute the configured cli command.
///
/// This accepts a closure that is used to launch the node via the
Expand Down
2 changes: 1 addition & 1 deletion bin/reth/src/commands/debug_cmd/build_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub struct Command<C: ChainSpecParser> {
blobs_bundle_path: Option<PathBuf>,
}

impl<C: ChainSpecParser> Command<C> {
impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
/// Fetches the best block block from the database.
///
/// If the database is empty, returns the genesis block.
Expand Down
2 changes: 1 addition & 1 deletion bin/reth/src/commands/debug_cmd/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub struct Command<C: ChainSpecParser> {
pub interval: u64,
}

impl<C: ChainSpecParser> Command<C> {
impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
fn build_pipeline<N: NodeTypesWithDB<ChainSpec = C::ChainSpec>, Client>(
&self,
config: &Config,
Expand Down
2 changes: 1 addition & 1 deletion bin/reth/src/commands/debug_cmd/in_memory_merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub struct Command<C: ChainSpecParser> {
skip_node_depth: Option<usize>,
}

impl<C: ChainSpecParser> Command<C> {
impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
async fn build_network<N: NodeTypesWithDB<ChainSpec = C::ChainSpec>>(
&self,
config: &Config,
Expand Down
2 changes: 1 addition & 1 deletion bin/reth/src/commands/debug_cmd/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub struct Command<C: ChainSpecParser> {
skip_node_depth: Option<usize>,
}

impl<C: ChainSpecParser> Command<C> {
impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
async fn build_network<N: NodeTypesWithDB<ChainSpec = C::ChainSpec>>(
&self,
config: &Config,
Expand Down
2 changes: 1 addition & 1 deletion bin/reth/src/commands/debug_cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub enum Subcommands<C: ChainSpecParser> {
ReplayEngine(replay_engine::Command<C>),
}

impl<C: ChainSpecParser> Command<C> {
impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
/// Execute `debug` command
pub async fn execute<
N: NodeTypesWithEngine<Engine = EthEngineTypes, ChainSpec = C::ChainSpec>,
Expand Down
2 changes: 1 addition & 1 deletion bin/reth/src/commands/debug_cmd/replay_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub struct Command<C: ChainSpecParser> {
interval: u64,
}

impl<C: ChainSpecParser> Command<C> {
impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
async fn build_network<N: NodeTypesWithDB<ChainSpec = C::ChainSpec>>(
&self,
config: &Config,
Expand Down
8 changes: 8 additions & 0 deletions crates/chainspec/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use alloy_eips::eip1559::BaseFeeParams;
use alloy_genesis::Genesis;
use alloy_primitives::B256;
use core::fmt::{Debug, Display};
use reth_network_peers::NodeRecord;
use reth_primitives_traits::Header;

/// Trait representing type configuring a chain spec.
Expand Down Expand Up @@ -41,6 +42,9 @@ pub trait EthChainSpec: Send + Sync + Unpin + Debug {

/// The block gas limit.
fn max_gas_limit(&self) -> u64;

/// The bootnodes for the chain, if any.
fn bootnodes(&self) -> Option<Vec<NodeRecord>>;
}

impl EthChainSpec for ChainSpec {
Expand Down Expand Up @@ -83,4 +87,8 @@ impl EthChainSpec for ChainSpec {
fn max_gas_limit(&self) -> u64 {
self.max_gas_limit
}

fn bootnodes(&self) -> Option<Vec<NodeRecord>> {
self.bootnodes()
}
}
2 changes: 1 addition & 1 deletion crates/cli/commands/src/db/get.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alloy_primitives::BlockHash;
use alloy_primitives::{hex, BlockHash};
use clap::Parser;
use reth_db::{
static_file::{ColumnSelectorOne, ColumnSelectorTwo, HeaderMask, ReceiptMask, TransactionMask},
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/commands/src/prune.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Command that runs pruning without any limits.
use crate::common::{AccessRights, Environment, EnvironmentArgs};
use clap::Parser;
use reth_chainspec::{ChainSpec, EthChainSpec, EthereumHardforks};
use reth_chainspec::{EthChainSpec, EthereumHardforks};
use reth_cli::chainspec::ChainSpecParser;
use reth_node_builder::NodeTypesWithEngine;
use reth_prune::PrunerBuilder;
Expand Down
6 changes: 3 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;
use reth_chainspec::{ChainSpec, EthChainSpec, EthereumHardforks};
use reth_db::{test_utils::TempDatabase, DatabaseEnv};
use reth_node_builder::{
components::NodeComponentsBuilder, rpc::EthApiBuilderProvider, FullNodeTypesAdapter, Node,
Expand Down Expand Up @@ -47,11 +47,11 @@ mod traits;
/// Creates the initial setup with `num_nodes` started and interconnected.
pub async fn setup<N>(
num_nodes: usize,
chain_spec: Arc<ChainSpec>,
chain_spec: Arc<N::ChainSpec>,
is_dev: bool,
) -> eyre::Result<(Vec<NodeHelperType<N, N::AddOns>>, TaskManager, Wallet)>
where
N: Default + Node<TmpNodeAdapter<N>> + NodeTypesWithEngine<ChainSpec = ChainSpec>,
N: Default + Node<TmpNodeAdapter<N>> + NodeTypesWithEngine<ChainSpec: EthereumHardforks>,
N::ComponentsBuilder: NodeComponentsBuilder<
TmpNodeAdapter<N>,
Components: NodeComponents<TmpNodeAdapter<N>, Network: PeersHandleProvider>,
Expand Down
4 changes: 2 additions & 2 deletions crates/e2e-test-utils/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use reth::{
types::engine::PayloadStatusEnum,
},
};
use reth_chainspec::ChainSpec;
use reth_chainspec::EthereumHardforks;
use reth_node_builder::{NodeAddOns, NodeTypesWithEngine};
use reth_stages_types::StageId;
use tokio_stream::StreamExt;
Expand Down Expand Up @@ -50,7 +50,7 @@ impl<Node, Engine, AddOns> NodeTestContext<Node, AddOns>
where
Engine: EngineTypes,
Node: FullNodeComponents,
Node::Types: NodeTypesWithEngine<ChainSpec = ChainSpec, Engine = Engine>,
Node::Types: NodeTypesWithEngine<ChainSpec: EthereumHardforks, Engine = Engine>,
Node::Network: PeersHandleProvider,
AddOns: NodeAddOns<Node>,
{
Expand Down
4 changes: 2 additions & 2 deletions crates/e2e-test-utils/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use reth::{
DebugApiServer,
},
};
use reth_chainspec::ChainSpec;
use reth_chainspec::EthereumHardforks;
use reth_node_builder::{EthApiTypes, NodeTypes};

#[allow(missing_debug_implementations)]
Expand All @@ -18,7 +18,7 @@ pub struct RpcTestContext<Node: FullNodeComponents, EthApi: EthApiTypes> {

impl<Node, EthApi> RpcTestContext<Node, EthApi>
where
Node: FullNodeComponents<Types: NodeTypes<ChainSpec = ChainSpec>>,
Node: FullNodeComponents<Types: NodeTypes<ChainSpec: EthereumHardforks>>,
EthApi: EthApiSpec + EthTransactions + TraceExt,
{
/// Injects a raw transaction into the node tx pool via RPC server
Expand Down
4 changes: 2 additions & 2 deletions crates/node/builder/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub use states::*;
use std::sync::Arc;

use futures::Future;
use reth_chainspec::{ChainSpec, EthChainSpec, EthereumHardforks, Hardforks};
use reth_chainspec::{EthChainSpec, EthereumHardforks, Hardforks};
use reth_cli_util::get_secret_key;
use reth_db_api::{
database::Database,
Expand Down Expand Up @@ -641,7 +641,7 @@ impl<Node: FullNodeTypes> BuilderContext<Node> {
}
}

impl<Node: FullNodeTypes<Types: NodeTypes<ChainSpec = ChainSpec>>> BuilderContext<Node> {
impl<Node: FullNodeTypes<Types: NodeTypes<ChainSpec: Hardforks>>> BuilderContext<Node> {
/// Creates the [`NetworkBuilder`] for the node.
pub async fn network_builder(&self) -> eyre::Result<NetworkBuilder<(), ()>> {
let network_config = self.network_config()?;
Expand Down
5 changes: 2 additions & 3 deletions crates/node/core/src/args/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ use std::{
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6},
ops::Not,
path::PathBuf,
sync::Arc,
};

use clap::Args;
use reth_chainspec::ChainSpec;
use reth_chainspec::EthChainSpec;
use reth_config::Config;
use reth_discv4::{NodeRecord, DEFAULT_DISCOVERY_ADDR, DEFAULT_DISCOVERY_PORT};
use reth_discv5::{
Expand Down Expand Up @@ -200,7 +199,7 @@ impl NetworkArgs {
pub fn network_config(
&self,
config: &Config,
chain_spec: Arc<ChainSpec>,
chain_spec: impl EthChainSpec,
secret_key: SecretKey,
default_peers_file: PathBuf,
) -> NetworkConfigBuilder {
Expand Down
1 change: 1 addition & 0 deletions crates/optimism/chainspec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ workspace = true
reth-chainspec = { workspace = true, features = ["optimism"] }
reth-ethereum-forks.workspace = true
reth-primitives-traits.workspace = true
reth-network-peers.workspace = true

# op-reth
reth-optimism-forks.workspace = true
Expand Down
26 changes: 24 additions & 2 deletions crates/optimism/chainspec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ pub use op_sepolia::OP_SEPOLIA;

use derive_more::{Constructor, Deref, Into};
use reth_chainspec::{
BaseFeeParams, ChainSpec, DepositContract, EthChainSpec, EthereumHardforks, Hardforks,
BaseFeeParams, ChainSpec, DepositContract, EthChainSpec, EthereumHardforks, ForkFilter, ForkId,
Hardforks, Head,
};
use reth_network_peers::NodeRecord;
use reth_primitives_traits::Header;

/// OP stack chain spec type.
#[derive(Debug, Clone, Deref, Into, Constructor)]
#[derive(Debug, Clone, Deref, Into, Constructor, PartialEq, Eq)]
pub struct OpChainSpec {
/// [`ChainSpec`].
pub inner: ChainSpec,
Expand All @@ -54,6 +56,10 @@ impl EthChainSpec for OpChainSpec {
self.inner.base_fee_params_at_timestamp(timestamp)
}

fn base_fee_params_at_block(&self, block_number: u64) -> BaseFeeParams {
self.inner.base_fee_params_at_block(block_number)
}

fn deposit_contract(&self) -> Option<&DepositContract> {
self.inner.deposit_contract()
}
Expand Down Expand Up @@ -81,6 +87,10 @@ impl EthChainSpec for OpChainSpec {
fn max_gas_limit(&self) -> u64 {
self.inner.max_gas_limit()
}

fn bootnodes(&self) -> Option<Vec<NodeRecord>> {
self.inner.bootnodes()
}
}

impl Hardforks for OpChainSpec {
Expand All @@ -93,6 +103,18 @@ impl Hardforks for OpChainSpec {
) -> impl Iterator<Item = (&dyn reth_chainspec::Hardfork, reth_chainspec::ForkCondition)> {
self.inner.forks_iter()
}

fn fork_id(&self, head: &Head) -> ForkId {
self.inner.fork_id(head)
}

fn latest_fork_id(&self) -> ForkId {
self.inner.latest_fork_id()
}

fn fork_filter(&self, head: Head) -> ForkFilter {
self.inner.fork_filter(head)
}
}

impl EthereumHardforks for OpChainSpec {
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
Expand Up @@ -40,7 +40,7 @@ pub struct ImportOpCommand<C: ChainSpecParser> {
path: PathBuf,
}

impl<C: ChainSpecParser> ImportOpCommand<C> {
impl<C: ChainSpecParser<ChainSpec = OpChainSpec>> ImportOpCommand<C> {
/// Execute `import` command
pub async fn execute<N: NodeTypesWithEngine<ChainSpec = C::ChainSpec>>(
self,
Expand Down
2 changes: 1 addition & 1 deletion crates/optimism/cli/src/commands/import_receipts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub struct ImportReceiptsOpCommand<C: ChainSpecParser> {
path: PathBuf,
}

impl<C: ChainSpecParser> ImportReceiptsOpCommand<C> {
impl<C: ChainSpecParser<ChainSpec = OpChainSpec>> ImportReceiptsOpCommand<C> {
/// Execute `import` command
pub async fn execute<N: NodeTypesWithEngine<ChainSpec = C::ChainSpec>>(
self,
Expand Down
3 changes: 2 additions & 1 deletion crates/optimism/cli/src/commands/init_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use reth_cli::chainspec::ChainSpecParser;
use reth_cli_commands::common::{AccessRights, Environment};
use reth_db_common::init::init_from_state_dump;
use reth_node_builder::NodeTypesWithEngine;
use reth_optimism_chainspec::OpChainSpec;
use reth_optimism_primitives::bedrock::BEDROCK_HEADER;
use reth_provider::{
BlockNumReader, ChainSpecProvider, DatabaseProviderFactory, StaticFileProviderFactory,
Expand Down Expand Up @@ -35,7 +36,7 @@ pub struct InitStateCommandOp<C: ChainSpecParser> {
without_ovm: bool,
}

impl<C: ChainSpecParser> InitStateCommandOp<C> {
impl<C: ChainSpecParser<ChainSpec = OpChainSpec>> InitStateCommandOp<C> {
/// Execute the `init` command
pub async fn execute<N: NodeTypesWithEngine<ChainSpec = C::ChainSpec>>(
self,
Expand Down
10 changes: 5 additions & 5 deletions crates/optimism/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use chainspec::OpChainSpecParser;
use clap::{command, value_parser, Parser};
use commands::Commands;
use futures_util::Future;
use reth_chainspec::ChainSpec;
use reth_chainspec::{ChainSpec, EthChainSpec};
use reth_cli::chainspec::ChainSpecParser;
use reth_cli_commands::node::NoArgs;
use reth_cli_runner::CliRunner;
Expand All @@ -55,7 +55,7 @@ use tracing::info;
/// This is the entrypoint to the executable.
#[derive(Debug, Parser)]
#[command(author, version = SHORT_VERSION, long_version = LONG_VERSION, about = "Reth", long_about = None)]
pub struct Cli<SpeC: ChainSpecParser = OpChainSpecParser, Ext: clap::Args + fmt::Debug = NoArgs> {
pub struct Cli<Spec: ChainSpecParser = OpChainSpecParser, Ext: clap::Args + fmt::Debug = NoArgs> {
/// The command to run
#[command(subcommand)]
command: Commands<Spec, Ext>,
Expand Down Expand Up @@ -109,9 +109,9 @@ impl Cli {
}
}

impl<Spec, Ext> Cli<Spec, Ext>
impl<C, Ext> Cli<C, Ext>
where
Spec: ChainSpecParser,
C: ChainSpecParser<ChainSpec: EthChainSpec>,
Ext: clap::Args + fmt::Debug,
{
/// Execute the configured cli command.
Expand All @@ -125,7 +125,7 @@ where
{
// add network name to logs dir
self.logs.log_file_directory =
self.logs.log_file_directory.join(self.chain.chain.to_string());
self.logs.log_file_directory.join(self.chain.chain().to_string());

let _guard = self.init_tracing()?;
info!(target: "reth::cli", "Initialized tracing, debug log directory: {}", self.logs.log_file_directory);
Expand Down
1 change: 1 addition & 0 deletions crates/optimism/consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ reth-trie-common.workspace = true

# op-reth
reth-optimism-forks.workspace = true
reth-optimism-chainspec.workspace = true

# ethereum
alloy-primitives.workspace = true
Expand Down
Loading

0 comments on commit 9b1c5f4

Please sign in to comment.