Skip to content

Commit 57e0b75

Browse files
committed
feat(bin): kona consensus node
rollup boost args base prefixes fixes
1 parent 4d7d12d commit 57e0b75

File tree

9 files changed

+473
-103
lines changed

9 files changed

+473
-103
lines changed

Cargo.lock

Lines changed: 83 additions & 65 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ codegen-units = 1
5353

5454
[workspace.dependencies]
5555
# Shared
56-
base-access-lists = { path = "crates/shared/access-lists" }
5756
base-bundles = { path = "crates/shared/bundles" }
5857
base-cli-utils = { path = "crates/shared/cli-utils" }
5958
base-flashtypes = { path = "crates/shared/flashtypes" }
6059
base-primitives = { path = "crates/shared/primitives" }
60+
base-access-lists = { path = "crates/shared/access-lists" }
6161
base-reth-rpc-types = { path = "crates/shared/reth-rpc-types" }
6262
base-jwt = { path = "crates/shared/jwt" }
6363

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

75+
# Kona
76+
kona-rpc = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
77+
kona-disc = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
78+
kona-engine = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
79+
kona-derive = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
80+
kona-gossip = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
81+
kona-genesis = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
82+
kona-registry = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
83+
kona-node-service = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
84+
kona-providers-alloy = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
85+
kona-cli = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d", default-features = false, features = ["secrets"] }
86+
kona-peers = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
87+
kona-sources = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
88+
7589
# reth
7690
reth-ipc = { git = "https://github.com/paradigmxyz/reth", tag = "v1.9.3" }
7791
reth-evm = { git = "https://github.com/paradigmxyz/reth", tag = "v1.9.3" }
@@ -201,39 +215,22 @@ alloy-rpc-types-beacon = { version = "1.0.41", features = ["ssz"] }
201215
# op-alloy
202216
op-alloy-flz = { version = "0.13.1", default-features = false }
203217
op-alloy-network = { version = "0.22.0", default-features = false }
218+
op-alloy-provider = { version = "0.22.0", default-features = false }
204219
op-alloy-rpc-types = { version = "0.22.0", default-features = false }
205220
op-alloy-consensus = { version = "0.22.0", default-features = false }
206221
op-alloy-rpc-jsonrpsee = { version = "0.22.0", default-features = false }
207222
op-alloy-rpc-types-engine = { version = "0.22.0", default-features = false }
208-
op-alloy-provider = { version = "0.22.0", default-features = false }
209223
alloy-op-evm = { version = "0.23.3", default-features = false }
210224
alloy-op-hardforks = "0.4.4"
211225

212-
# op-revm
213-
op-revm = { version = "12.0.2", default-features = false }
214-
215-
# kona
216-
kona-cli = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d", default-features = false, features = ["secrets"] }
217-
kona-derive = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
218-
kona-disc = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
219-
kona-engine = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
220-
kona-genesis = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
221-
kona-gossip = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
222-
kona-node-service = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
223-
kona-peers = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
224-
kona-providers-alloy = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
225-
kona-registry = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
226-
kona-rpc = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
227-
kona-sources = { git = "https://github.com/op-rs/kona", rev = "24e7e2658e09ac00c8e6cbb48bebe6d10f8fb69d" }
228-
229226
# rollup-boost
230227
rollup-boost = { git = "https://github.com/flashbots/rollup-boost", tag = "v0.7.11" }
231228
# rollup-boost version that matches kona's dependency (used for consensus binary)
232229
rollup-boost-kona = { package = "rollup-boost", git = "https://github.com/flashbots/rollup-boost.git", rev = "7fda98f" }
233230

234-
# libp2p
235-
libp2p = { version = "0.56.0", default-features = false }
236-
discv5 = "0.10.1"
231+
232+
# op-revm
233+
op-revm = { version = "12.0.2", default-features = false }
237234

238235
# tokio
239236
tokio = "1.48.0"
@@ -244,7 +241,6 @@ tokio-tungstenite = { version = "0.28.0", features = ["native-tls"] }
244241
futures = "0.3.31"
245242
reqwest = "0.12.25"
246243
futures-util = "0.3.31"
247-
backon = "1.5"
248244

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

254+
# Tracing
255+
tracing = "0.1.43"
256+
tracing-appender = "0.2.4"
257+
tracing-subscriber = "0.3.22"
258+
258259
# Metrics
259260
metrics = { version = "0.24.3", default-features = false }
260261
prometheus = { version = "0.14.0", default-features = false }
@@ -265,6 +266,8 @@ metrics-exporter-prometheus = { version = "0.18.1", default-features = false }
265266
url = "2.5.7"
266267
lru = "0.16.3"
267268
rand = "0.9.2"
269+
strum = "0.27.2"
270+
backon = "1.6.0"
268271
uuid = "1.19.0"
269272
time = { version = "0.3.44", features = ["macros", "formatting", "parsing"] }
270273
rayon = "1.11"
@@ -277,21 +280,21 @@ rstest = "0.26.1"
277280
serde = "1.0.228"
278281
rustls = "0.23.35"
279282
httpmock = "0.8.2"
280-
tracing = "0.1.43"
281283
arc-swap = "1.7.1"
282284
once_cell = "1.21.3"
283285
itertools = "0.14.0"
284286
derive_more = "2.1.0"
285287
serde_json = "1.0.145"
286288
metrics-derive = "0.1.0"
287-
tracing-subscriber = "0.3.22"
288-
tracing-appender = "0.2"
289289
thiserror = "2.0"
290290
async-trait = "0.1.83"
291291
parking_lot = "0.12.3"
292292
auto_impl = "1.2.0"
293293
serde_with = "3.8.1"
294294
secp256k1 = "0.30"
295+
libp2p = "0.56.0"
296+
libp2p-identity = "0.2.12"
297+
discv5 = "0.10"
295298
either = { version = "1.15.0", default-features = false }
296299
tokio-util = { version = "0.7.4", features = ["codec"] }
297300
warp = "0.3.7"

bin/consensus/Cargo.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,27 @@ workspace = true
1515
[dependencies]
1616
# Workspace
1717
base-cli-utils.workspace = true
18+
base-client-cli.workspace = true
19+
20+
# Kona
21+
kona-disc = { workspace = true, features = ["metrics"] }
22+
kona-derive = { workspace = true, features = ["metrics"] }
23+
kona-engine = { workspace = true, features = ["metrics"] }
24+
kona-genesis.workspace = true
25+
kona-gossip = { workspace = true, features = ["metrics"] }
26+
kona-node-service = { workspace = true, features = ["metrics"] }
27+
kona-providers-alloy = { workspace = true, features = ["metrics"] }
1828

1929
# CLI
2030
clap.workspace = true
2131
eyre.workspace = true
32+
strum.workspace = true
33+
34+
# Tracing
35+
tracing.workspace = true
36+
tracing-subscriber = { workspace = true, features = ["fmt", "env-filter"] }
37+
38+
# Metrics
2239
metrics.workspace = true
2340

2441
[build-dependencies]

bin/consensus/src/cli.rs

Lines changed: 161 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,187 @@
11
//! Contains the CLI entry point for the Base consensus binary.
22
3-
use base_cli_utils::GlobalArgs;
3+
use std::{sync::Arc, time::Duration};
4+
5+
use base_cli_utils::{CliStyles, GlobalArgs, LogConfig, RuntimeManager};
6+
use base_client_cli::{
7+
BuilderClientArgs, L1ClientArgs, L1ConfigFile, L2ClientArgs, L2ConfigFile, P2PArgs,
8+
RollupBoostFlags, RpcArgs, SequencerArgs,
9+
};
410
use clap::Parser;
11+
use kona_node_service::{EngineConfig, L1ConfigBuilder, NodeMode, RollupNodeBuilder};
12+
use strum::IntoEnumIterator;
13+
use tracing::{error, info};
514

6-
use crate::version;
15+
use crate::{metrics::init_rollup_config_metrics, version};
716

817
/// The Base Consensus CLI.
918
#[derive(Parser, Clone, Debug)]
1019
#[command(
1120
author,
1221
version = version::SHORT_VERSION,
1322
long_version = version::LONG_VERSION,
23+
styles = CliStyles::init(),
1424
about,
1525
long_about = None
1626
)]
1727
pub struct Cli {
1828
/// Global arguments for the Base Consensus CLI.
1929
#[command(flatten)]
2030
pub global: GlobalArgs,
31+
/// The mode to run the node in.
32+
#[arg(
33+
long = "mode",
34+
default_value_t = NodeMode::Validator,
35+
env = "BASE_NODE_MODE",
36+
help = format!(
37+
"The mode to run the node in. Supported modes are: {}",
38+
NodeMode::iter()
39+
.map(|mode| format!("\"{}\"", mode.to_string()))
40+
.collect::<Vec<_>>()
41+
.join(", ")
42+
)
43+
)]
44+
pub node_mode: NodeMode,
45+
46+
/// L1 RPC CLI arguments.
47+
#[clap(flatten)]
48+
pub l1_rpc_args: L1ClientArgs,
49+
50+
/// L2 engine CLI arguments.
51+
#[clap(flatten)]
52+
pub l2_client_args: L2ClientArgs,
53+
54+
/// Optional block builder client.
55+
#[clap(flatten)]
56+
pub builder_client_args: BuilderClientArgs,
57+
58+
/// L1 configuration file.
59+
#[clap(flatten)]
60+
pub l1_config: L1ConfigFile,
61+
/// L2 configuration file.
62+
#[clap(flatten)]
63+
pub l2_config: L2ConfigFile,
64+
65+
/// P2P CLI arguments.
66+
#[command(flatten)]
67+
pub p2p_flags: P2PArgs,
68+
/// RPC CLI arguments.
69+
#[command(flatten)]
70+
pub rpc_flags: RpcArgs,
71+
/// SEQUENCER CLI arguments.
72+
#[command(flatten)]
73+
pub sequencer_flags: SequencerArgs,
74+
/// Rollup Boost CLI arguments.
75+
#[command(flatten)]
76+
pub rollup_boost_flags: RollupBoostFlags,
2177
}
2278

2379
impl Cli {
24-
/// Parse the CLI arguments.
25-
pub fn parse() -> Self {
26-
<Self as Parser>::parse()
80+
/// Runs the CLI.
81+
pub fn run(self) -> eyre::Result<()> {
82+
// Initialize telemetry - allow subcommands to customize the filter.
83+
Self::init_logs(&self.global)?;
84+
85+
// Initialize unified metrics
86+
self.global.metrics.init_with(|| {
87+
kona_gossip::Metrics::init();
88+
kona_disc::Metrics::init();
89+
kona_engine::Metrics::init();
90+
kona_node_service::Metrics::init();
91+
kona_derive::Metrics::init();
92+
kona_providers_alloy::Metrics::init();
93+
version::VersionInfo::from_build().register_version_metrics();
94+
})?;
95+
96+
// Run the subcommand.
97+
RuntimeManager::run_until_ctrl_c(self.exec(&self.global))
2798
}
2899

29-
/// Run the CLI.
30-
pub fn run(self) -> eyre::Result<()> {
31-
// TODO: Implement the CLI logic
100+
/// Run the Node subcommand.
101+
pub async fn exec(&self, args: &GlobalArgs) -> eyre::Result<()> {
102+
let cfg = self.l2_config.load(&args.l2_chain_id).map_err(|e| eyre::eyre!("{e}"))?;
103+
104+
info!(
105+
target: "rollup_node",
106+
chain_id = cfg.l2_chain_id.id(),
107+
"Starting rollup node services"
108+
);
109+
for hf in cfg.hardforks.to_string().lines() {
110+
info!(target: "rollup_node", "{hf}");
111+
}
112+
113+
let l1_chain_config =
114+
self.l1_config.load(cfg.l1_chain_id).map_err(|e| eyre::eyre!("{e}"))?;
115+
let l1_config = L1ConfigBuilder {
116+
chain_config: l1_chain_config,
117+
trust_rpc: self.l1_rpc_args.l1_trust_rpc,
118+
beacon: self.l1_rpc_args.l1_beacon.clone(),
119+
rpc_url: self.l1_rpc_args.l1_eth_rpc.clone(),
120+
slot_duration_override: self.l1_rpc_args.l1_slot_duration_override,
121+
};
122+
123+
// If metrics are enabled, initialize the global cli metrics.
124+
args.metrics.enabled.then(|| init_rollup_config_metrics(&cfg));
125+
126+
let jwt_secret = self.l2_client_args.validate_jwt().await?;
127+
128+
self.p2p_flags.check_ports()?;
129+
let genesis_signer = args.genesis_signer().ok();
130+
let p2p_config = self
131+
.p2p_flags
132+
.clone()
133+
.config(
134+
&cfg,
135+
args.l2_chain_id.into(),
136+
Some(self.l1_rpc_args.l1_eth_rpc.clone()),
137+
genesis_signer,
138+
)
139+
.await?;
140+
let rpc_config = self.rpc_flags.clone().into();
141+
142+
let engine_config = EngineConfig {
143+
config: Arc::new(cfg.clone()),
144+
builder_url: self.builder_client_args.l2_builder_rpc.clone(),
145+
builder_jwt_secret: self
146+
.builder_client_args
147+
.jwt_secret()
148+
.map_err(|e| eyre::eyre!(e))?,
149+
builder_timeout: Duration::from_millis(self.builder_client_args.builder_timeout),
150+
l2_url: self.l2_client_args.l2_engine_rpc.clone(),
151+
l2_jwt_secret: jwt_secret,
152+
l2_timeout: Duration::from_millis(self.l2_client_args.l2_engine_timeout),
153+
l1_url: self.l1_rpc_args.l1_eth_rpc.clone(),
154+
mode: self.node_mode,
155+
rollup_boost: self.rollup_boost_flags.clone().as_rollup_boost_args(),
156+
};
157+
158+
RollupNodeBuilder::new(
159+
cfg,
160+
l1_config,
161+
self.l2_client_args.l2_trust_rpc,
162+
engine_config,
163+
p2p_config,
164+
rpc_config,
165+
)
166+
.with_sequencer_config(self.sequencer_flags.config())
167+
.build()
168+
.start()
169+
.await
170+
.map_err(|e| {
171+
error!(target: "rollup_node", "Failed to start rollup node service: {e}");
172+
eyre::eyre!("{e}")
173+
})?;
174+
32175
Ok(())
33176
}
177+
178+
/// Initializes the logging system based on global arguments.
179+
pub fn init_logs(args: &GlobalArgs) -> eyre::Result<()> {
180+
// Filter out discovery warnings since they're very very noisy.
181+
let filter = tracing_subscriber::EnvFilter::from_default_env()
182+
.add_directive("discv5=error".parse()?);
183+
184+
let config: LogConfig = args.logging.clone().into();
185+
config.init_tracing_subscriber_with_filter(filter)
186+
}
34187
}

bin/consensus/src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
55

66
pub mod cli;
7+
pub mod metrics;
78
pub mod version;
89

910
fn main() {
11+
use clap::Parser;
12+
1013
base_cli_utils::Backtracing::enable();
1114
base_cli_utils::SigsegvHandler::install();
1215

0 commit comments

Comments
 (0)