Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 83 additions & 65 deletions Cargo.lock

Large diffs are not rendered by default.

55 changes: 29 additions & 26 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ codegen-units = 1

[workspace.dependencies]
# Shared
base-access-lists = { path = "crates/shared/access-lists" }
base-bundles = { path = "crates/shared/bundles" }
base-cli-utils = { path = "crates/shared/cli-utils" }
base-flashtypes = { path = "crates/shared/flashtypes" }
base-primitives = { path = "crates/shared/primitives" }
base-access-lists = { path = "crates/shared/access-lists" }
base-reth-rpc-types = { path = "crates/shared/reth-rpc-types" }
base-jwt = { path = "crates/shared/jwt" }

Expand All @@ -72,6 +72,20 @@ base-flashblocks = { path = "crates/client/flashblocks" }
# Builder
op-rbuilder = { path = "crates/builder/op-rbuilder" }

# Kona
kona-rpc = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
kona-disc = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
kona-engine = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
kona-derive = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
kona-gossip = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
kona-genesis = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
kona-registry = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
kona-node-service = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
kona-providers-alloy = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
kona-cli = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d", default-features = false, features = ["secrets"] }
kona-peers = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
kona-sources = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }

# reth
reth-ipc = { git = "https://github.com/paradigmxyz/reth", tag = "v1.9.3" }
reth-evm = { git = "https://github.com/paradigmxyz/reth", tag = "v1.9.3" }
Expand Down Expand Up @@ -201,39 +215,22 @@ alloy-rpc-types-beacon = { version = "1.0.41", features = ["ssz"] }
# op-alloy
op-alloy-flz = { version = "0.13.1", default-features = false }
op-alloy-network = { version = "0.22.0", default-features = false }
op-alloy-provider = { version = "0.22.0", default-features = false }
op-alloy-rpc-types = { version = "0.22.0", default-features = false }
op-alloy-consensus = { version = "0.22.0", default-features = false }
op-alloy-rpc-jsonrpsee = { version = "0.22.0", default-features = false }
op-alloy-rpc-types-engine = { version = "0.22.0", default-features = false }
op-alloy-provider = { version = "0.22.0", default-features = false }
alloy-op-evm = { version = "0.23.3", default-features = false }
alloy-op-hardforks = "0.4.4"

# op-revm
op-revm = { version = "12.0.2", default-features = false }

# kona
kona-cli = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d", default-features = false, features = ["secrets"] }
kona-derive = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
kona-disc = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
kona-engine = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
kona-genesis = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
kona-gossip = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
kona-node-service = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
kona-peers = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
kona-providers-alloy = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
kona-registry = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
kona-rpc = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
kona-sources = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }

# rollup-boost
rollup-boost = { git = "https://github.com/flashbots/rollup-boost", tag = "v0.7.11" }
# rollup-boost version that matches kona's dependency (used for consensus binary)
rollup-boost-kona = { package = "rollup-boost", git = "https://github.com/flashbots/rollup-boost.git", rev = "7fda98f" }

# libp2p
libp2p = { version = "0.56.0", default-features = false }
discv5 = "0.10.1"

# op-revm
op-revm = { version = "12.0.2", default-features = false }

# tokio
tokio = "1.48.0"
Expand All @@ -244,7 +241,6 @@ tokio-tungstenite = { version = "0.28.0", features = ["native-tls"] }
futures = "0.3.31"
reqwest = "0.12.25"
futures-util = "0.3.31"
backon = "1.5"

# rpc
jsonrpsee = "0.26.0"
Expand All @@ -255,6 +251,11 @@ vergen = "9.0.6"
vergen-git2 = "1.0.7"
clap = { version = "4.5.53", features = ["derive", "env", "string"] }

# Tracing
tracing = "0.1.43"
tracing-appender = "0.2.4"
tracing-subscriber = "0.3.22"

# Metrics
metrics = { version = "0.24.3", default-features = false }
prometheus = { version = "0.14.0", default-features = false }
Expand All @@ -265,6 +266,8 @@ metrics-exporter-prometheus = { version = "0.18.1", default-features = false }
url = "2.5.7"
lru = "0.16.3"
rand = "0.9.2"
strum = "0.27.2"
backon = "1.6.0"
uuid = "1.19.0"
time = { version = "0.3.44", features = ["macros", "formatting", "parsing"] }
rayon = "1.11"
Expand All @@ -277,21 +280,21 @@ rstest = "0.26.1"
serde = "1.0.228"
rustls = "0.23.35"
httpmock = "0.8.2"
tracing = "0.1.43"
arc-swap = "1.7.1"
once_cell = "1.21.3"
itertools = "0.14.0"
derive_more = "2.1.0"
serde_json = "1.0.145"
metrics-derive = "0.1.0"
tracing-subscriber = "0.3.22"
tracing-appender = "0.2"
thiserror = "2.0"
async-trait = "0.1.83"
parking_lot = "0.12.3"
auto_impl = "1.2.0"
serde_with = "3.8.1"
secp256k1 = "0.30"
libp2p = "0.56.0"
libp2p-identity = "0.2.12"
discv5 = "0.10"
either = { version = "1.15.0", default-features = false }
tokio-util = { version = "0.7.4", features = ["codec"] }
warp = "0.3.7"
Expand Down
17 changes: 17 additions & 0 deletions bin/consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,27 @@ workspace = true
[dependencies]
# Workspace
base-cli-utils.workspace = true
base-client-cli.workspace = true

# Kona
kona-disc = { workspace = true, features = ["metrics"] }
kona-derive = { workspace = true, features = ["metrics"] }
kona-engine = { workspace = true, features = ["metrics"] }
kona-genesis.workspace = true
kona-gossip = { workspace = true, features = ["metrics"] }
kona-node-service = { workspace = true, features = ["metrics"] }
kona-providers-alloy = { workspace = true, features = ["metrics"] }

# CLI
clap.workspace = true
eyre.workspace = true
strum.workspace = true

# Tracing
tracing.workspace = true
tracing-subscriber = { workspace = true, features = ["fmt", "env-filter"] }

# Metrics
metrics.workspace = true

[build-dependencies]
Expand Down
169 changes: 161 additions & 8 deletions bin/consensus/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,187 @@
//! Contains the CLI entry point for the Base consensus binary.

use base_cli_utils::GlobalArgs;
use std::{sync::Arc, time::Duration};

use base_cli_utils::{CliStyles, GlobalArgs, LogConfig, RuntimeManager};
use base_client_cli::{
BuilderClientArgs, L1ClientArgs, L1ConfigFile, L2ClientArgs, L2ConfigFile, P2PArgs,
RollupBoostFlags, RpcArgs, SequencerArgs,
};
use clap::Parser;
use kona_node_service::{EngineConfig, L1ConfigBuilder, NodeMode, RollupNodeBuilder};
use strum::IntoEnumIterator;
use tracing::{error, info};

use crate::version;
use crate::{metrics::init_rollup_config_metrics, version};

/// The Base Consensus CLI.
#[derive(Parser, Clone, Debug)]
#[command(
author,
version = version::SHORT_VERSION,
long_version = version::LONG_VERSION,
styles = CliStyles::init(),
about,
long_about = None
)]
pub struct Cli {
/// Global arguments for the Base Consensus CLI.
#[command(flatten)]
pub global: GlobalArgs,
/// The mode to run the node in.
#[arg(
long = "mode",
default_value_t = NodeMode::Validator,
env = "BASE_NODE_MODE",
help = format!(
"The mode to run the node in. Supported modes are: {}",
NodeMode::iter()
.map(|mode| format!("\"{}\"", mode.to_string()))
.collect::<Vec<_>>()
.join(", ")
)
)]
pub node_mode: NodeMode,

/// L1 RPC CLI arguments.
#[clap(flatten)]
pub l1_rpc_args: L1ClientArgs,

/// L2 engine CLI arguments.
#[clap(flatten)]
pub l2_client_args: L2ClientArgs,

/// Optional block builder client.
#[clap(flatten)]
pub builder_client_args: BuilderClientArgs,

/// L1 configuration file.
#[clap(flatten)]
pub l1_config: L1ConfigFile,
/// L2 configuration file.
#[clap(flatten)]
pub l2_config: L2ConfigFile,

/// P2P CLI arguments.
#[command(flatten)]
pub p2p_flags: P2PArgs,
/// RPC CLI arguments.
#[command(flatten)]
pub rpc_flags: RpcArgs,
/// SEQUENCER CLI arguments.
#[command(flatten)]
pub sequencer_flags: SequencerArgs,
/// Rollup Boost CLI arguments.
#[command(flatten)]
pub rollup_boost_flags: RollupBoostFlags,
}

impl Cli {
/// Parse the CLI arguments.
pub fn parse() -> Self {
<Self as Parser>::parse()
/// Runs the CLI.
pub fn run(self) -> eyre::Result<()> {
// Initialize telemetry - allow subcommands to customize the filter.
Self::init_logs(&self.global)?;

// Initialize unified metrics
self.global.metrics.init_with(|| {
kona_gossip::Metrics::init();
kona_disc::Metrics::init();
kona_engine::Metrics::init();
kona_node_service::Metrics::init();
kona_derive::Metrics::init();
kona_providers_alloy::Metrics::init();
version::VersionInfo::from_build().register_version_metrics();
})?;

// Run the subcommand.
RuntimeManager::run_until_ctrl_c(self.exec(&self.global))
}

/// Run the CLI.
pub fn run(self) -> eyre::Result<()> {
// TODO: Implement the CLI logic
/// Run the Node subcommand.
pub async fn exec(&self, args: &GlobalArgs) -> eyre::Result<()> {
let cfg = self.l2_config.load(&args.l2_chain_id).map_err(|e| eyre::eyre!("{e}"))?;

info!(
target: "rollup_node",
chain_id = cfg.l2_chain_id.id(),
"Starting rollup node services"
);
for hf in cfg.hardforks.to_string().lines() {
info!(target: "rollup_node", "{hf}");
}

let l1_chain_config =
self.l1_config.load(cfg.l1_chain_id).map_err(|e| eyre::eyre!("{e}"))?;
let l1_config = L1ConfigBuilder {
chain_config: l1_chain_config,
trust_rpc: self.l1_rpc_args.l1_trust_rpc,
beacon: self.l1_rpc_args.l1_beacon.clone(),
rpc_url: self.l1_rpc_args.l1_eth_rpc.clone(),
slot_duration_override: self.l1_rpc_args.l1_slot_duration_override,
};

// If metrics are enabled, initialize the global cli metrics.
args.metrics.enabled.then(|| init_rollup_config_metrics(&cfg));

let jwt_secret = self.l2_client_args.validate_jwt().await?;

self.p2p_flags.check_ports()?;
let genesis_signer = args.genesis_signer().ok();
let p2p_config = self
.p2p_flags
.clone()
.config(
&cfg,
args.l2_chain_id.into(),
Some(self.l1_rpc_args.l1_eth_rpc.clone()),
genesis_signer,
)
.await?;
let rpc_config = self.rpc_flags.clone().into();

let engine_config = EngineConfig {
config: Arc::new(cfg.clone()),
builder_url: self.builder_client_args.l2_builder_rpc.clone(),
builder_jwt_secret: self
.builder_client_args
.jwt_secret()
.map_err(|e| eyre::eyre!(e))?,
builder_timeout: Duration::from_millis(self.builder_client_args.builder_timeout),
l2_url: self.l2_client_args.l2_engine_rpc.clone(),
l2_jwt_secret: jwt_secret,
l2_timeout: Duration::from_millis(self.l2_client_args.l2_engine_timeout),
l1_url: self.l1_rpc_args.l1_eth_rpc.clone(),
mode: self.node_mode,
rollup_boost: self.rollup_boost_flags.clone().as_rollup_boost_args(),
};

RollupNodeBuilder::new(
cfg,
l1_config,
self.l2_client_args.l2_trust_rpc,
engine_config,
p2p_config,
rpc_config,
)
.with_sequencer_config(self.sequencer_flags.config())
.build()
.start()
.await
.map_err(|e| {
error!(target: "rollup_node", "Failed to start rollup node service: {e}");
eyre::eyre!("{e}")
})?;

Ok(())
}

/// Initializes the logging system based on global arguments.
pub fn init_logs(args: &GlobalArgs) -> eyre::Result<()> {
// Filter out discovery warnings since they're very very noisy.
let filter = tracing_subscriber::EnvFilter::from_default_env()
.add_directive("discv5=error".parse()?);

let config: LogConfig = args.logging.clone().into();
config.init_tracing_subscriber_with_filter(filter)
}
}
3 changes: 3 additions & 0 deletions bin/consensus/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
#![cfg_attr(not(test), warn(unused_crate_dependencies))]

pub mod cli;
pub mod metrics;
pub mod version;

fn main() {
use clap::Parser;

base_cli_utils::Backtracing::enable();
base_cli_utils::SigsegvHandler::install();

Expand Down
Loading