Skip to content

chore: simplify rollup-boost args #358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 3 additions & 4 deletions crates/rollup-boost/src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use clap::Parser;
use rollup_boost::Args;
use rollup_boost::init_tracing;

use dotenvy::dotenv;
use rollup_boost::RollupBoostArgs;
use rollup_boost::init_tracing;

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

let args = Args::parse();
let args = RollupBoostArgs::parse();
init_tracing(&args)?;
args.run().await
}
67 changes: 10 additions & 57 deletions crates/rollup-boost/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use alloy_rpc_types_engine::JwtSecret;
use clap::{Parser, Subcommand};
use clap::Parser;
use eyre::bail;
use jsonrpsee::{RpcModule, server::Server};
use parking_lot::Mutex;
Expand All @@ -13,8 +13,7 @@ use tokio::signal::unix::{SignalKind, signal as unix_signal};
use tracing::{Level, info};

use crate::{
BlockSelectionPolicy, DebugClient, Flashblocks, FlashblocksArgs, ProxyLayer, RollupBoostServer,
RpcClient,
BlockSelectionPolicy, Flashblocks, FlashblocksArgs, ProxyLayer, RollupBoostServer, RpcClient,
client::rpc::{BuilderArgs, L2ClientArgs},
debug_api::ExecutionMode,
get_version, init_metrics,
Expand All @@ -24,10 +23,7 @@ use crate::{

#[derive(Clone, Parser, Debug)]
#[clap(author, version = get_version(), about)]
pub struct Args {
#[command(subcommand)]
pub command: Option<Commands>,

pub struct RollupBoostArgs {
#[clap(flatten)]
pub builder: BuilderArgs,

Expand Down Expand Up @@ -101,37 +97,12 @@ pub struct Args {
pub flashblocks: FlashblocksArgs,
}

impl Args {
impl RollupBoostArgs {
pub async fn run(self) -> eyre::Result<()> {
let _ = rustls::crypto::ring::default_provider().install_default();

let debug_addr = format!("{}:{}", self.debug_host, self.debug_server_port);

// Handle commands if present
if let Some(cmd) = self.command {
let debug_addr = format!("http://{debug_addr}");
return match cmd {
Commands::Debug { command } => match command {
DebugCommands::SetExecutionMode { execution_mode } => {
let client = DebugClient::new(debug_addr.as_str())?;
let result = client.set_execution_mode(execution_mode).await?;
println!("Response: {:?}", result.execution_mode);

Ok(())
}
DebugCommands::ExecutionMode {} => {
let client = DebugClient::new(debug_addr.as_str())?;
let result = client.get_execution_mode().await?;
println!("Execution mode: {:?}", result.execution_mode);

Ok(())
}
},
};
}

init_metrics(&self)?;

let debug_addr = format!("{}:{}", self.debug_host, self.debug_server_port);
let l2_client_args = self.l2_client;

let l2_auth_jwt = if let Some(secret) = l2_client_args.l2_jwt_token {
Expand Down Expand Up @@ -169,17 +140,18 @@ impl Args {
let execution_mode = Arc::new(Mutex::new(self.execution_mode));

let (rpc_module, health_handle): (RpcModule<()>, _) = if self.flashblocks.flashblocks {
let inbound_url = self.flashblocks.flashblocks_builder_url;
let flashblocks_args = self.flashblocks;
let inbound_url = flashblocks_args.flashblocks_builder_url;
let outbound_addr = SocketAddr::new(
IpAddr::from_str(&self.flashblocks.flashblocks_host)?,
self.flashblocks.flashblocks_port,
IpAddr::from_str(&flashblocks_args.flashblocks_host)?,
flashblocks_args.flashblocks_port,
);

let builder_client = Arc::new(Flashblocks::run(
builder_client.clone(),
inbound_url,
outbound_addr,
self.flashblocks.flashblock_builder_ws_reconnect_ms,
flashblocks_args.flashblock_builder_ws_reconnect_ms,
)?);

let rollup_boost = RollupBoostServer::new(
Expand Down Expand Up @@ -228,7 +200,6 @@ impl Args {
builder_args.builder_timeout,
));

// NOTE: clean this up
let server = Server::builder()
.set_http_middleware(http_middleware)
.build(format!("{}:{}", self.rpc_host, self.rpc_port).parse::<SocketAddr>()?)
Expand Down Expand Up @@ -280,21 +251,3 @@ impl std::str::FromStr for LogFormat {
}
}
}

#[derive(Clone, Subcommand, Debug)]
pub enum Commands {
/// Debug commands
Debug {
#[command(subcommand)]
command: DebugCommands,
},
}

#[derive(Clone, Subcommand, Debug)]
pub enum DebugCommands {
/// Set the execution mode
SetExecutionMode { execution_mode: ExecutionMode },

/// Get the execution mode
ExecutionMode {},
}
2 changes: 1 addition & 1 deletion crates/rollup-boost/src/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl RpcClient {
timeout: u64,
payload_source: PayloadSource,
) -> Result<Self, RpcClientError> {
let version = format!("{}-{}", CARGO_PKG_VERSION, VERGEN_GIT_SHA);
let version = format!("{CARGO_PKG_VERSION}-{VERGEN_GIT_SHA}");
let mut headers = HeaderMap::new();
headers.insert("User-Agent", version.parse().unwrap());

Expand Down
2 changes: 1 addition & 1 deletion crates/rollup-boost/src/debug_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub struct GetExecutionModeResponse {
}

#[rpc(server, client, namespace = "debug")]
trait DebugApi {
pub trait DebugApi {
#[method(name = "setExecutionMode")]
async fn set_execution_mode(
&self,
Expand Down
4 changes: 2 additions & 2 deletions crates/rollup-boost/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ use hyper_util::rt::TokioIo;
use jsonrpsee::http_client::HttpBody;
use metrics_exporter_prometheus::PrometheusHandle;

use crate::cli::Args;
use crate::cli::RollupBoostArgs;

pub fn init_metrics(args: &Args) -> Result<()> {
pub fn init_metrics(args: &RollupBoostArgs) -> Result<()> {
if args.metrics {
let recorder = PrometheusBuilder::new().build_recorder();
let handle = recorder.handle();
Expand Down
10 changes: 5 additions & 5 deletions crates/rollup-boost/src/tests/common/services/rollup_boost.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{fs::File, time::Duration};

use crate::Args;
use crate::RollupBoostArgs;
use clap::Parser;
use tokio::task::JoinHandle;
use tracing::subscriber::DefaultGuard;
Expand All @@ -10,13 +10,13 @@ use crate::tests::common::{TEST_DATA, get_available_port};

#[derive(Debug)]
pub struct RollupBoost {
args: Args,
args: RollupBoostArgs,
pub _handle: JoinHandle<eyre::Result<()>>,
pub _tracing_guard: DefaultGuard,
}

impl RollupBoost {
pub fn args(&self) -> &Args {
pub fn args(&self) -> &RollupBoostArgs {
&self.args
}

Expand All @@ -41,12 +41,12 @@ impl RollupBoost {

#[derive(Clone, Debug)]
pub struct RollupBoostConfig {
pub args: Args,
pub args: RollupBoostArgs,
}

impl Default for RollupBoostConfig {
fn default() -> Self {
let mut args = Args::parse_from([
let mut args = RollupBoostArgs::parse_from([
"rollup-boost",
&format!("--l2-jwt-path={}/jwt_secret.hex", *TEST_DATA),
&format!("--builder-jwt-path={}/jwt_secret.hex", *TEST_DATA),
Expand Down
4 changes: 2 additions & 2 deletions crates/rollup-boost/src/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use tracing_subscriber::filter::Targets;
use tracing_subscriber::fmt::writer::BoxMakeWriter;
use tracing_subscriber::layer::SubscriberExt;

use crate::cli::{Args, LogFormat};
use crate::cli::{LogFormat, RollupBoostArgs};

/// Span attribute keys that should be recorded as metric labels.
///
Expand Down Expand Up @@ -99,7 +99,7 @@ impl SpanProcessor for MetricsSpanProcessor {
}
}

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

Expand Down
10 changes: 5 additions & 5 deletions crates/websocket-proxy/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ impl std::fmt::Display for AuthenticationParseError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
NoData() => write!(f, "No API Keys Provided"),
MissingApplicationArgument(arg) => write!(f, "Missing application argument: [{}]", arg),
MissingAPIKeyArgument(app) => write!(f, "Missing API Key argument: [{}]", app),
TooManyComponents(app) => write!(f, "Too many components: [{}]", app),
MissingApplicationArgument(arg) => write!(f, "Missing application argument: [{arg}]"),
MissingAPIKeyArgument(app) => write!(f, "Missing API Key argument: [{app}]"),
TooManyComponents(app) => write!(f, "Too many components: [{app}]"),
DuplicateApplicationArgument(app) => {
write!(f, "Duplicate application argument: [{}]", app)
write!(f, "Duplicate application argument: [{app}]")
}
DuplicateAPIKeyArgument(app) => write!(f, "Duplicate API key: [{}]", app),
DuplicateAPIKeyArgument(app) => write!(f, "Duplicate API key: [{app}]"),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/websocket-proxy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ async fn main() {
match auth::Authentication::try_from(api_keys) {
Ok(auth) => Some(auth),
Err(e) => {
panic!("Failed to parse API Keys: {}", e)
panic!("Failed to parse API Keys: {e}")
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion crates/websocket-proxy/src/rate_limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ impl RateLimit for RedisRateLimit {

if total_ip_connections >= self.per_ip_limit {
return Err(RateLimitError::Limit {
reason: format!("Per-IP connection limit reached for {}", addr),
reason: format!("Per-IP connection limit reached for {addr}"),
});
}

Expand Down
Loading