Skip to content

Commit beebcb3

Browse files
authored
feat(client): Consensus CLI (#420)
* feat(client): cli crate * fix(cli): rm jwt dep
1 parent d9310cc commit beebcb3

File tree

7 files changed

+172
-0
lines changed

7 files changed

+172
-0
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ base-flashtypes = { path = "crates/shared/flashtypes" }
6060
base-primitives = { path = "crates/shared/primitives" }
6161
base-reth-rpc-types = { path = "crates/shared/reth-rpc-types" }
6262
# Client
63+
base-client-cli = { path = "crates/client/cli" }
6364
base-client-node = { path = "crates/client/node" }
6465
base-metering = { path = "crates/client/metering" }
6566
base-txpool = { path = "crates/client/txpool" }

crates/client/cli/Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "base-client-cli"
3+
description = "CLI argument types for Base node consensus clients"
4+
version.workspace = true
5+
edition.workspace = true
6+
rust-version.workspace = true
7+
license.workspace = true
8+
homepage.workspace = true
9+
repository.workspace = true
10+
11+
[lints]
12+
workspace = true
13+
14+
[dependencies]
15+
# General
16+
url.workspace = true
17+
clap.workspace = true
18+
alloy-rpc-types-engine.workspace = true

crates/client/cli/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# `base-client-cli`
2+
3+
CLI argument types for Base node consensus clients.
4+
5+
## Overview
6+
7+
This crate provides reusable CLI argument types for configuring Base node consensus clients:
8+
9+
- **`L1ClientArgs`**: L1 execution client RPC configuration
10+
- **`L2ClientArgs`**: L2 engine API configuration with JWT handling
11+
12+
## Usage
13+
14+
```toml
15+
[dependencies]
16+
base-client-cli = { workspace = true }
17+
```
18+
19+
```rust
20+
use base_client_cli::{L1ClientArgs, L2ClientArgs};
21+
use clap::Parser;
22+
23+
#[derive(Parser)]
24+
struct Cli {
25+
#[clap(flatten)]
26+
l1_args: L1ClientArgs,
27+
#[clap(flatten)]
28+
l2_args: L2ClientArgs,
29+
}
30+
```
31+
32+
## License
33+
34+
Licensed under the MIT License.

crates/client/cli/src/l1.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//! L1 Client CLI arguments.
2+
3+
use url::Url;
4+
5+
const DEFAULT_L1_TRUST_RPC: bool = true;
6+
7+
/// L1 client arguments.
8+
#[derive(Clone, Debug, clap::Args)]
9+
pub struct L1ClientArgs {
10+
/// URL of the L1 execution client RPC API.
11+
#[arg(long, visible_alias = "l1", env = "KONA_NODE_L1_ETH_RPC")]
12+
pub l1_eth_rpc: Url,
13+
/// Whether to trust the L1 RPC.
14+
/// If false, block hash verification is performed for all retrieved blocks.
15+
#[arg(
16+
long,
17+
visible_alias = "l1.trust-rpc",
18+
env = "KONA_NODE_L1_TRUST_RPC",
19+
default_value_t = DEFAULT_L1_TRUST_RPC
20+
)]
21+
pub l1_trust_rpc: bool,
22+
/// URL of the L1 beacon API.
23+
#[arg(long, visible_alias = "l1.beacon", env = "KONA_NODE_L1_BEACON")]
24+
pub l1_beacon: Url,
25+
/// Duration in seconds of an L1 slot.
26+
///
27+
/// This is an optional argument that can be used to use a fixed slot duration for l1 blocks
28+
/// and bypass the initial beacon spec fetch. This is useful for testing purposes when the
29+
/// l1-beacon spec endpoint is not available (with anvil for example).
30+
#[arg(
31+
long,
32+
visible_alias = "l1.slot-duration-override",
33+
env = "KONA_NODE_L1_SLOT_DURATION_OVERRIDE"
34+
)]
35+
pub l1_slot_duration_override: Option<u64>,
36+
}
37+
38+
impl Default for L1ClientArgs {
39+
fn default() -> Self {
40+
Self {
41+
l1_eth_rpc: Url::parse("http://localhost:8545").unwrap(),
42+
l1_trust_rpc: DEFAULT_L1_TRUST_RPC,
43+
l1_beacon: Url::parse("http://localhost:5052").unwrap(),
44+
l1_slot_duration_override: None,
45+
}
46+
}
47+
}

crates/client/cli/src/l2.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//! L2 Client CLI arguments with JWT handling.
2+
3+
use std::path::PathBuf;
4+
5+
use alloy_rpc_types_engine::JwtSecret;
6+
use url::Url;
7+
8+
const DEFAULT_L2_ENGINE_TIMEOUT: u64 = 30_000;
9+
const DEFAULT_L2_TRUST_RPC: bool = true;
10+
11+
/// L2 client arguments.
12+
#[derive(Clone, Debug, clap::Args)]
13+
pub struct L2ClientArgs {
14+
/// URI of the engine API endpoint of an L2 execution client.
15+
#[arg(long, visible_alias = "l2", env = "KONA_NODE_L2_ENGINE_RPC")]
16+
pub l2_engine_rpc: Url,
17+
/// JWT secret for the auth-rpc endpoint of the execution client.
18+
/// This MUST be a valid path to a file containing the hex-encoded JWT secret.
19+
#[arg(long, visible_alias = "l2.jwt-secret", env = "KONA_NODE_L2_ENGINE_AUTH")]
20+
pub l2_engine_jwt_secret: Option<PathBuf>,
21+
/// Hex encoded JWT secret to use for the authenticated engine-API RPC server.
22+
/// This MUST be a valid hex-encoded JWT secret of 64 digits.
23+
#[arg(long, visible_alias = "l2.jwt-secret-encoded", env = "KONA_NODE_L2_ENGINE_AUTH_ENCODED")]
24+
pub l2_engine_jwt_encoded: Option<JwtSecret>,
25+
/// Timeout for http calls in milliseconds.
26+
#[arg(
27+
long,
28+
visible_alias = "l2.timeout",
29+
env = "KONA_NODE_L2_ENGINE_TIMEOUT",
30+
default_value_t = DEFAULT_L2_ENGINE_TIMEOUT
31+
)]
32+
pub l2_engine_timeout: u64,
33+
/// If false, block hash verification is performed for all retrieved blocks.
34+
#[arg(
35+
long,
36+
visible_alias = "l2.trust-rpc",
37+
env = "KONA_NODE_L2_TRUST_RPC",
38+
default_value_t = DEFAULT_L2_TRUST_RPC
39+
)]
40+
pub l2_trust_rpc: bool,
41+
}
42+
43+
impl Default for L2ClientArgs {
44+
fn default() -> Self {
45+
Self {
46+
l2_engine_rpc: Url::parse("http://localhost:8551").unwrap(),
47+
l2_engine_jwt_secret: None,
48+
l2_engine_jwt_encoded: None,
49+
l2_engine_timeout: DEFAULT_L2_ENGINE_TIMEOUT,
50+
l2_trust_rpc: DEFAULT_L2_TRUST_RPC,
51+
}
52+
}
53+
}

crates/client/cli/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![doc = include_str!("../README.md")]
2+
#![doc(issue_tracker_base_url = "https://github.com/base/node-reth/issues/")]
3+
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
4+
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
5+
6+
mod l1;
7+
pub use l1::L1ClientArgs;
8+
9+
mod l2;
10+
pub use l2::L2ClientArgs;

0 commit comments

Comments
 (0)