Skip to content

Commit cb1f98b

Browse files
authored
Separate rollup-boost library args from service args (#432)
1 parent bb51564 commit cb1f98b

File tree

7 files changed

+56
-51
lines changed

7 files changed

+56
-51
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use clap::Parser;
22
use dotenvy::dotenv;
3-
use rollup_boost::RollupBoostArgs;
3+
use rollup_boost::RollupBoostServiceArgs;
44
use rollup_boost::init_tracing;
55

66
#[tokio::main]
77
async fn main() -> eyre::Result<()> {
88
dotenv().ok();
99

10-
let args = RollupBoostArgs::parse();
10+
let args = RollupBoostServiceArgs::parse();
1111
init_tracing(&args)?;
1212
args.run().await
1313
}

crates/rollup-boost/src/cli.rs

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,47 @@ use crate::{
1414
};
1515
use crate::{FlashblocksService, RpcClient};
1616

17-
#[derive(Clone, Parser, Debug)]
18-
#[clap(author, version = get_version(), about)]
19-
pub struct RollupBoostArgs {
17+
#[derive(Clone, Debug, clap::Args)]
18+
pub struct RollupBoostLibArgs {
2019
#[clap(flatten)]
2120
pub builder: BuilderArgs,
2221

2322
#[clap(flatten)]
2423
pub l2_client: L2ClientArgs,
2524

25+
/// Execution mode to start rollup boost with
26+
#[arg(long, env, default_value = "enabled")]
27+
pub execution_mode: ExecutionMode,
28+
29+
#[arg(long, env)]
30+
pub block_selection_policy: Option<BlockSelectionPolicy>,
31+
32+
/// Should we use the l2 client for computing state root
33+
#[arg(long, env, default_value = "false")]
34+
pub external_state_root: bool,
35+
36+
/// Allow all engine API calls to builder even when marked as unhealthy
37+
/// This is default true assuming no builder CL set up
38+
#[arg(long, env, default_value = "false")]
39+
pub ignore_unhealthy_builders: bool,
40+
41+
#[clap(flatten)]
42+
pub flashblocks: FlashblocksArgs,
43+
2644
/// Duration in seconds between async health checks on the builder
2745
#[arg(long, env, default_value = "60")]
2846
pub health_check_interval: u64,
2947

3048
/// Max duration in seconds between the unsafe head block of the builder and the current time
3149
#[arg(long, env, default_value = "10")]
3250
pub max_unsafe_interval: u64,
51+
}
52+
53+
#[derive(Clone, Parser, Debug)]
54+
#[clap(author, version = get_version(), about)]
55+
pub struct RollupBoostServiceArgs {
56+
#[clap(flatten)]
57+
pub lib: RollupBoostLibArgs,
3358

3459
/// Host to run the server on
3560
#[arg(long, env, default_value = "127.0.0.1")]
@@ -78,57 +103,38 @@ pub struct RollupBoostArgs {
78103
/// Debug server port
79104
#[arg(long, env, default_value = "5555")]
80105
pub debug_server_port: u16,
81-
82-
/// Execution mode to start rollup boost with
83-
#[arg(long, env, default_value = "enabled")]
84-
pub execution_mode: ExecutionMode,
85-
86-
#[arg(long, env)]
87-
pub block_selection_policy: Option<BlockSelectionPolicy>,
88-
89-
/// Should we use the l2 client for computing state root
90-
#[arg(long, env, default_value = "false")]
91-
pub external_state_root: bool,
92-
93-
/// Allow all engine API calls to builder even when marked as unhealthy
94-
/// This is default true assuming no builder CL set up
95-
#[arg(long, env, default_value = "false")]
96-
pub ignore_unhealthy_builders: bool,
97-
98-
#[clap(flatten)]
99-
pub flashblocks: FlashblocksArgs,
100106
}
101107

102-
impl RollupBoostArgs {
108+
impl RollupBoostServiceArgs {
103109
pub async fn run(self) -> eyre::Result<()> {
104110
let _ = rustls::crypto::ring::default_provider().install_default();
105111
init_metrics(&self)?;
106112

107113
let debug_addr = format!("{}:{}", self.debug_host, self.debug_server_port);
108-
let l2_client_args: ClientArgs = self.l2_client.clone().into();
114+
let l2_client_args: ClientArgs = self.lib.l2_client.clone().into();
109115
let l2_http_client = l2_client_args.new_http_client(PayloadSource::L2)?;
110116

111-
let builder_client_args: ClientArgs = self.builder.clone().into();
117+
let builder_client_args: ClientArgs = self.lib.builder.clone().into();
112118
let builder_http_client = builder_client_args.new_http_client(PayloadSource::Builder)?;
113119

114120
let (probe_layer, probes) = ProbeLayer::new();
115121

116-
let (health_handle, rpc_module) = if self.flashblocks.flashblocks {
122+
let (health_handle, rpc_module) = if self.lib.flashblocks.flashblocks {
117123
let rollup_boost = RollupBoostServer::<FlashblocksService>::new_from_args(
118-
self.clone(),
124+
self.lib.clone(),
119125
probes.clone(),
120126
)?;
121127
let health_handle = rollup_boost
122-
.spawn_health_check(self.health_check_interval, self.max_unsafe_interval);
128+
.spawn_health_check(self.lib.health_check_interval, self.lib.max_unsafe_interval);
123129
let debug_server = DebugServer::new(rollup_boost.execution_mode.clone());
124130
debug_server.run(&debug_addr).await?;
125131
let rpc_module: RpcModule<()> = rollup_boost.try_into()?;
126132
(health_handle, rpc_module)
127133
} else {
128134
let rollup_boost =
129-
RollupBoostServer::<RpcClient>::new_from_args(self.clone(), probes.clone())?;
135+
RollupBoostServer::<RpcClient>::new_from_args(self.lib.clone(), probes.clone())?;
130136
let health_handle = rollup_boost
131-
.spawn_health_check(self.health_check_interval, self.max_unsafe_interval);
137+
.spawn_health_check(self.lib.health_check_interval, self.lib.max_unsafe_interval);
132138
let debug_server = DebugServer::new(rollup_boost.execution_mode.clone());
133139
debug_server.run(&debug_addr).await?;
134140
let rpc_module: RpcModule<()> = rollup_boost.try_into()?;
@@ -180,7 +186,7 @@ impl RollupBoostArgs {
180186
}
181187
}
182188

183-
impl Default for RollupBoostArgs {
189+
impl Default for RollupBoostServiceArgs {
184190
fn default() -> Self {
185191
Self::parse_from::<_, &str>(std::iter::empty())
186192
}

crates/rollup-boost/src/metrics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ use jsonrpsee::http_client::HttpBody;
1515
use metrics_exporter_prometheus::PrometheusHandle;
1616

1717
use crate::ExecutionMode;
18-
use crate::cli::RollupBoostArgs;
18+
use crate::cli::RollupBoostServiceArgs;
1919

20-
pub fn init_metrics(args: &RollupBoostArgs) -> Result<()> {
20+
pub fn init_metrics(args: &RollupBoostServiceArgs) -> Result<()> {
2121
if args.metrics {
2222
let recorder = PrometheusBuilder::new().build_recorder();
2323
let handle = recorder.handle();

crates/rollup-boost/src/server.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::debug_api::ExecutionMode;
22
use crate::{
33
BlockSelectionPolicy, ClientArgs, EngineApiExt, Flashblocks, FlashblocksService,
4-
RollupBoostArgs, update_execution_mode_gauge,
4+
RollupBoostLibArgs, update_execution_mode_gauge,
55
};
66
use crate::{
77
client::rpc::RpcClient,
@@ -71,7 +71,7 @@ pub struct RollupBoostServer<T: EngineApiExt> {
7171

7272
impl RollupBoostServer<FlashblocksService> {
7373
pub fn new_from_args(
74-
rollup_boost_args: RollupBoostArgs,
74+
rollup_boost_args: RollupBoostLibArgs,
7575
probes: Arc<Probes>,
7676
) -> eyre::Result<Self> {
7777
if !rollup_boost_args.flashblocks.flashblocks {
@@ -113,7 +113,7 @@ impl RollupBoostServer<FlashblocksService> {
113113

114114
impl RollupBoostServer<RpcClient> {
115115
pub fn new_from_args(
116-
rollup_boost_args: RollupBoostArgs,
116+
rollup_boost_args: RollupBoostLibArgs,
117117
probes: Arc<Probes>,
118118
) -> eyre::Result<Self> {
119119
if rollup_boost_args.flashblocks.flashblocks {

crates/rollup-boost/src/tests/common/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -381,15 +381,15 @@ impl RollupBoostTestHarnessBuilder {
381381

382382
// Start Rollup-boost instance
383383
let mut rollup_boost = RollupBoostConfig::default();
384-
rollup_boost.args.l2_client.l2_url = l2.auth_rpc().await?;
385-
rollup_boost.args.builder.builder_url = builder_url.try_into().unwrap();
384+
rollup_boost.args.lib.l2_client.l2_url = l2.auth_rpc().await?;
385+
rollup_boost.args.lib.builder.builder_url = builder_url.try_into().unwrap();
386386
rollup_boost.args.log_file = Some(rollup_boost_log_file_path);
387-
rollup_boost.args.external_state_root = self.external_state_root;
387+
rollup_boost.args.lib.external_state_root = self.external_state_root;
388388
if let Some(allow_traffic) = self.ignore_unhealthy_builders {
389-
rollup_boost.args.ignore_unhealthy_builders = allow_traffic;
389+
rollup_boost.args.lib.ignore_unhealthy_builders = allow_traffic;
390390
}
391391
if let Some(interval) = self.max_unsafe_interval {
392-
rollup_boost.args.max_unsafe_interval = interval;
392+
rollup_boost.args.lib.max_unsafe_interval = interval;
393393
}
394394
let rollup_boost = rollup_boost.start().await;
395395
println!("rollup-boost authrpc: {}", rollup_boost.rpc_endpoint());

crates/rollup-boost/src/tests/common/services/rollup_boost.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::{fs::File, time::Duration};
22

3-
use crate::RollupBoostArgs;
4-
use clap::Parser;
3+
use crate::RollupBoostServiceArgs;
54
use tokio::task::JoinHandle;
65
use tracing::subscriber::DefaultGuard;
76
use tracing_subscriber::fmt;
@@ -10,13 +9,13 @@ use crate::tests::common::{TEST_DATA, get_available_port};
109

1110
#[derive(Debug)]
1211
pub struct RollupBoost {
13-
args: RollupBoostArgs,
12+
args: RollupBoostServiceArgs,
1413
pub _handle: JoinHandle<eyre::Result<()>>,
1514
pub _tracing_guard: DefaultGuard,
1615
}
1716

1817
impl RollupBoost {
19-
pub fn args(&self) -> &RollupBoostArgs {
18+
pub fn args(&self) -> &RollupBoostServiceArgs {
2019
&self.args
2120
}
2221

@@ -41,12 +40,12 @@ impl RollupBoost {
4140

4241
#[derive(Clone, Debug)]
4342
pub struct RollupBoostConfig {
44-
pub args: RollupBoostArgs,
43+
pub args: RollupBoostServiceArgs,
4544
}
4645

4746
impl Default for RollupBoostConfig {
4847
fn default() -> Self {
49-
let mut args = RollupBoostArgs::parse_from([
48+
let mut args = <RollupBoostServiceArgs as clap::Parser>::parse_from([
5049
"rollup-boost",
5150
&format!("--l2-jwt-path={}/jwt_secret.hex", *TEST_DATA),
5251
&format!("--builder-jwt-path={}/jwt_secret.hex", *TEST_DATA),

crates/rollup-boost/src/tracing.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use tracing_subscriber::filter::Targets;
1212
use tracing_subscriber::fmt::writer::BoxMakeWriter;
1313
use tracing_subscriber::layer::SubscriberExt;
1414

15-
use crate::cli::{LogFormat, RollupBoostArgs};
15+
use crate::cli::{LogFormat, RollupBoostServiceArgs};
1616

1717
/// Span attribute keys that should be recorded as metric labels.
1818
///
@@ -99,7 +99,7 @@ impl SpanProcessor for MetricsSpanProcessor {
9999
}
100100
}
101101

102-
pub fn init_tracing(args: &RollupBoostArgs) -> eyre::Result<()> {
102+
pub fn init_tracing(args: &RollupBoostServiceArgs) -> eyre::Result<()> {
103103
// Be cautious with snake_case and kebab-case here
104104
let filter_name = "rollup_boost".to_string();
105105

0 commit comments

Comments
 (0)