Skip to content

Commit a217513

Browse files
committed
refactor: Enable library usage of rollup-boost
* unify client configuration with ClientArgs struct * Consolidate BuilderArgs/L2ClientArgs into unified ClientArgs pattern * Move JWT handling into ClientArgs with helper methods * Update ProxyLayer to accept HttpClient instances instead of raw config * Add RollupBoostServer::new_from_args for cleaner initialization * Bump reth-rpc-layer to v1.8.2
1 parent cab95df commit a217513

File tree

8 files changed

+321
-234
lines changed

8 files changed

+321
-234
lines changed

crates/rollup-boost/src/cli.rs

Lines changed: 31 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,18 @@
1-
use alloy_rpc_types_engine::JwtSecret;
21
use clap::Parser;
3-
use eyre::bail;
42
use jsonrpsee::{RpcModule, server::Server};
5-
use parking_lot::Mutex;
6-
use std::{
7-
net::{IpAddr, SocketAddr},
8-
path::PathBuf,
9-
str::FromStr,
10-
sync::Arc,
11-
};
3+
use std::{net::SocketAddr, path::PathBuf};
124
use tokio::signal::unix::{SignalKind, signal as unix_signal};
135
use tracing::{Level, info};
146

157
use crate::{
16-
BlockSelectionPolicy, Flashblocks, FlashblocksArgs, ProxyLayer, RollupBoostServer, RpcClient,
8+
BlockSelectionPolicy, ClientArgs, DebugServer, FlashblocksArgs, PayloadSource, ProxyLayer,
9+
RollupBoostServer,
1710
client::rpc::{BuilderArgs, L2ClientArgs},
1811
debug_api::ExecutionMode,
1912
get_version, init_metrics,
20-
payload::PayloadSource,
2113
probe::ProbeLayer,
2214
};
15+
use crate::{FlashblocksService, RpcClient};
2316

2417
#[derive(Clone, Parser, Debug)]
2518
#[clap(author, version = get_version(), about)]
@@ -112,90 +105,34 @@ impl RollupBoostArgs {
112105
init_metrics(&self)?;
113106

114107
let debug_addr = format!("{}:{}", self.debug_host, self.debug_server_port);
115-
let l2_client_args = self.l2_client;
116-
117-
let l2_auth_jwt = if let Some(secret) = l2_client_args.l2_jwt_token {
118-
secret
119-
} else if let Some(path) = l2_client_args.l2_jwt_path.as_ref() {
120-
JwtSecret::from_file(path)?
121-
} else {
122-
bail!("Missing L2 Client JWT secret");
123-
};
108+
let l2_client_args: ClientArgs = self.l2_client.clone().into();
109+
let l2_http_client = l2_client_args.new_http_client(PayloadSource::L2)?;
124110

125-
let l2_client = RpcClient::new(
126-
l2_client_args.l2_url.clone(),
127-
l2_auth_jwt,
128-
l2_client_args.l2_timeout,
129-
PayloadSource::L2,
130-
)?;
131-
132-
let builder_args = self.builder;
133-
let builder_auth_jwt = if let Some(secret) = builder_args.builder_jwt_token {
134-
secret
135-
} else if let Some(path) = builder_args.builder_jwt_path.as_ref() {
136-
JwtSecret::from_file(path)?
137-
} else {
138-
bail!("Missing Builder JWT secret");
139-
};
140-
141-
let builder_client = RpcClient::new(
142-
builder_args.builder_url.clone(),
143-
builder_auth_jwt,
144-
builder_args.builder_timeout,
145-
PayloadSource::Builder,
146-
)?;
111+
let builder_client_args: ClientArgs = self.builder.clone().into();
112+
let builder_http_client = builder_client_args.new_http_client(PayloadSource::Builder)?;
147113

148114
let (probe_layer, probes) = ProbeLayer::new();
149-
let execution_mode = Arc::new(Mutex::new(self.execution_mode));
150-
151-
let (rpc_module, health_handle): (RpcModule<()>, _) = if self.flashblocks.flashblocks {
152-
let flashblocks_args = self.flashblocks;
153-
let inbound_url = flashblocks_args.flashblocks_builder_url;
154-
let outbound_addr = SocketAddr::new(
155-
IpAddr::from_str(&flashblocks_args.flashblocks_host)?,
156-
flashblocks_args.flashblocks_port,
157-
);
158-
159-
let builder_client = Arc::new(Flashblocks::run(
160-
builder_client.clone(),
161-
inbound_url,
162-
outbound_addr,
163-
flashblocks_args.flashblock_builder_ws_reconnect_ms,
164-
)?);
165-
166-
let rollup_boost = RollupBoostServer::new(
167-
l2_client,
168-
builder_client,
169-
execution_mode.clone(),
170-
self.block_selection_policy,
171-
probes.clone(),
172-
self.external_state_root,
173-
self.ignore_unhealthy_builders,
174-
);
175115

116+
let (health_handle, rpc_module) = if self.flashblocks.flashblocks {
117+
let rollup_boost = RollupBoostServer::<FlashblocksService>::new_from_args(
118+
self.clone(),
119+
probes.clone(),
120+
)?;
176121
let health_handle = rollup_boost
177122
.spawn_health_check(self.health_check_interval, self.max_unsafe_interval);
178-
179-
// Spawn the debug server
180-
rollup_boost.start_debug_server(debug_addr.as_str()).await?;
181-
(rollup_boost.try_into()?, health_handle)
123+
let debug_server = DebugServer::new(rollup_boost.execution_mode.clone());
124+
debug_server.run(&debug_addr).await?;
125+
let rpc_module: RpcModule<()> = rollup_boost.try_into()?;
126+
(health_handle, rpc_module)
182127
} else {
183-
let rollup_boost = RollupBoostServer::new(
184-
l2_client,
185-
Arc::new(builder_client),
186-
execution_mode.clone(),
187-
self.block_selection_policy,
188-
probes.clone(),
189-
self.external_state_root,
190-
self.ignore_unhealthy_builders,
191-
);
192-
128+
let rollup_boost =
129+
RollupBoostServer::<RpcClient>::new_from_args(self.clone(), probes.clone())?;
193130
let health_handle = rollup_boost
194131
.spawn_health_check(self.health_check_interval, self.max_unsafe_interval);
195-
196-
// Spawn the debug server
197-
rollup_boost.start_debug_server(debug_addr.as_str()).await?;
198-
(rollup_boost.try_into()?, health_handle)
132+
let debug_server = DebugServer::new(rollup_boost.execution_mode.clone());
133+
debug_server.run(&debug_addr).await?;
134+
let rpc_module: RpcModule<()> = rollup_boost.try_into()?;
135+
(health_handle, rpc_module)
199136
};
200137

201138
// Build and start the server
@@ -205,12 +142,8 @@ impl RollupBoostArgs {
205142
tower::ServiceBuilder::new()
206143
.layer(probe_layer)
207144
.layer(ProxyLayer::new(
208-
l2_client_args.l2_url,
209-
l2_auth_jwt,
210-
l2_client_args.l2_timeout,
211-
builder_args.builder_url,
212-
builder_auth_jwt,
213-
builder_args.builder_timeout,
145+
l2_http_client.clone(),
146+
builder_http_client.clone(),
214147
));
215148

216149
let server = Server::builder()
@@ -247,6 +180,12 @@ impl RollupBoostArgs {
247180
}
248181
}
249182

183+
impl Default for RollupBoostArgs {
184+
fn default() -> Self {
185+
Self::parse_from::<_, &str>(std::iter::empty())
186+
}
187+
}
188+
250189
#[derive(Clone, Debug)]
251190
pub enum LogFormat {
252191
Json,

crates/rollup-boost/src/client/rpc.rs

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::EngineApiExt;
22
use crate::client::auth::AuthLayer;
3+
use crate::client::http::HttpClient as RollupBoostHttpClient;
34
use crate::payload::{NewPayload, OpExecutionPayloadEnvelope, PayloadSource, PayloadVersion};
45
use crate::server::EngineApiClient;
56
use crate::version::{CARGO_PKG_VERSION, VERGEN_GIT_SHA};
@@ -10,6 +11,7 @@ use alloy_rpc_types_engine::{
1011
};
1112
use alloy_rpc_types_eth::{Block, BlockNumberOrTag};
1213
use clap::{Parser, arg};
14+
use eyre::bail;
1315
use http::{HeaderMap, Uri};
1416
use jsonrpsee::core::async_trait;
1517
use jsonrpsee::core::middleware::layer::RpcLogger;
@@ -101,7 +103,7 @@ impl From<RpcClientError> for ErrorObjectOwned {
101103
///
102104
/// - **Engine API** calls are faciliated via the `auth_client` (requires JWT authentication).
103105
///
104-
#[derive(Clone)]
106+
#[derive(Clone, Debug)]
105107
pub struct RpcClient {
106108
/// Handles requests to the authenticated Engine API (requires JWT authentication)
107109
auth_client: RpcClientService,
@@ -376,8 +378,57 @@ impl EngineApiExt for RpcClient {
376378
}
377379
}
378380

381+
#[derive(Debug, Clone)]
382+
pub struct ClientArgs {
383+
/// Auth server address
384+
pub url: Uri,
385+
386+
/// Hex encoded JWT secret to use for the authenticated engine-API RPC server.
387+
pub jwt_token: Option<JwtSecret>,
388+
389+
/// Path to a JWT secret to use for the authenticated engine-API RPC server.
390+
pub jwt_path: Option<PathBuf>,
391+
392+
/// Timeout for http calls in milliseconds
393+
pub timeout: u64,
394+
}
395+
396+
impl ClientArgs {
397+
fn get_auth_jwt(&self) -> eyre::Result<JwtSecret> {
398+
if let Some(secret) = self.jwt_token {
399+
Ok(secret)
400+
} else if let Some(path) = self.jwt_path.as_ref() {
401+
Ok(JwtSecret::from_file(path)?)
402+
} else {
403+
bail!("Missing Client JWT secret");
404+
}
405+
}
406+
407+
pub fn new_rpc_client(&self, payload_source: PayloadSource) -> eyre::Result<RpcClient> {
408+
RpcClient::new(
409+
self.url.clone(),
410+
self.get_auth_jwt()?,
411+
self.timeout,
412+
payload_source,
413+
)
414+
.map_err(eyre::Report::from)
415+
}
416+
417+
pub fn new_http_client(
418+
&self,
419+
payload_source: PayloadSource,
420+
) -> eyre::Result<RollupBoostHttpClient> {
421+
Ok(RollupBoostHttpClient::new(
422+
self.url.clone(),
423+
self.get_auth_jwt()?,
424+
payload_source,
425+
self.timeout,
426+
))
427+
}
428+
}
429+
379430
/// Generates Clap argument structs with a prefix to create a unique namespace when specifying RPC client config via the CLI.
380-
macro_rules! define_rpc_args {
431+
macro_rules! define_client_args {
381432
($(($name:ident, $prefix:ident)),*) => {
382433
$(
383434
paste! {
@@ -399,12 +450,24 @@ macro_rules! define_rpc_args {
399450
#[arg(long, env, default_value_t = 1000)]
400451
pub [<$prefix _timeout>]: u64,
401452
}
453+
454+
455+
impl From<$name> for ClientArgs {
456+
fn from(args: $name) -> Self {
457+
ClientArgs {
458+
url: args.[<$prefix _url>].clone(),
459+
jwt_token: args.[<$prefix _jwt_token>].clone(),
460+
jwt_path: args.[<$prefix _jwt_path>],
461+
timeout: args.[<$prefix _timeout>],
462+
}
463+
}
464+
}
402465
}
403466
)*
404467
};
405468
}
406469

407-
define_rpc_args!((BuilderArgs, builder), (L2ClientArgs, l2));
470+
define_client_args!((BuilderArgs, builder), (L2ClientArgs, l2));
408471

409472
#[cfg(test)]
410473
pub mod tests {

crates/rollup-boost/src/flashblocks/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ pub use launcher::*;
44

55
mod primitives;
66
mod service;
7+
pub use service::*;
78

89
pub use primitives::*;
9-
pub use service::*;
1010

1111
mod inbound;
1212
mod outbound;

crates/rollup-boost/src/flashblocks/service.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ impl FlashblockBuilder {
164164
}
165165
}
166166

167-
#[derive(Clone)]
167+
#[derive(Clone, Debug)]
168168
pub struct FlashblocksService {
169169
client: RpcClient,
170170

crates/rollup-boost/src/payload.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ pub struct PayloadTrace {
239239
pub trace_id: Option<tracing::Id>,
240240
}
241241

242+
#[derive(Debug)]
242243
pub struct PayloadTraceContext {
243244
block_hash_to_payload_ids: Cache<B256, Vec<PayloadId>>,
244245
payload_id: Cache<PayloadId, PayloadTrace>,

crates/rollup-boost/src/probe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub struct ProbeLayer {
6262
}
6363

6464
impl ProbeLayer {
65-
pub(crate) fn new() -> (Self, Arc<Probes>) {
65+
pub fn new() -> (Self, Arc<Probes>) {
6666
let probes = Arc::new(Probes::default());
6767
(
6868
Self {

0 commit comments

Comments
 (0)