Skip to content
Merged
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
2 changes: 1 addition & 1 deletion crates/op-rbuilder/src/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl CliExt for Cli {
/// Currently supports `Standard` and `Flashblocks` modes.
fn builder_mode(&self) -> BuilderMode {
if let Commands::Node(ref node_command) = self.command {
if node_command.ext.enable_flashblocks {
if node_command.ext.flashblocks.enabled {
return BuilderMode::Flashblocks;
}
}
Expand Down
73 changes: 47 additions & 26 deletions crates/op-rbuilder/src/args/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,14 @@ pub struct OpRbuilderArgs {
#[arg(long = "rollup.builder-secret-key", env = "BUILDER_SECRET_KEY")]
pub builder_signer: Option<Signer>,

/// When set to true, the builder will build flashblocks
/// and will build standard blocks at the chain block time.
///
/// The default value will change in the future once the flashblocks
/// feature is stable.
#[arg(
long = "rollup.enable-flashblocks",
default_value = "false",
env = "ENABLE_FLASHBLOCKS"
)]
pub enable_flashblocks: bool,

/// Websocket port for flashblock payload builder
#[arg(
long = "rollup.flashblocks-ws-url",
env = "FLASHBLOCKS_WS_URL",
default_value = "127.0.0.1:1111"
)]
pub flashblocks_ws_url: String,
/// chain block time in milliseconds
#[arg(
long = "rollup.chain-block-time",
default_value = "1000",
env = "CHAIN_BLOCK_TIME"
)]
pub chain_block_time: u64,
/// flashblock block time in milliseconds
#[arg(
long = "rollup.flashblock-block-time",
default_value = "250",
env = "FLASHBLOCK_BLOCK_TIME"
)]
pub flashblock_block_time: u64,

/// Signals whether to log pool transaction events
#[arg(long = "builder.log-pool-transactions", default_value = "false")]
pub log_pool_transactions: bool,
Expand All @@ -71,6 +46,9 @@ pub struct OpRbuilderArgs {
env = "PLAYGROUND_DIR",
)]
pub playground: Option<PathBuf>,

#[command(flatten)]
pub flashblocks: FlashblocksArgs,
}

fn expand_path(s: &str) -> Result<PathBuf, String> {
Expand All @@ -80,3 +58,46 @@ fn expand_path(s: &str) -> Result<PathBuf, String> {
.parse()
.map_err(|e| format!("invalid path after expansion: {e}"))
}

/// Parameters for Flashblocks configuration
/// The names in the struct are prefixed with `flashblocks` to avoid conflicts
/// with the standard block building configuration since these args are flattened
/// into the main `OpRbuilderArgs` struct with the other rollup/node args.
#[derive(Debug, Clone, Default, PartialEq, Eq, clap::Args)]
pub struct FlashblocksArgs {
/// When set to true, the builder will build flashblocks
/// and will build standard blocks at the chain block time.
///
/// The default value will change in the future once the flashblocks
/// feature is stable.
#[arg(
long = "flashblocks.enabled",
default_value = "false",
env = "ENABLE_FLASHBLOCKS"
)]
pub enabled: bool,

/// The port that we bind to for the websocket server that provides flashblocks
#[arg(
long = "flashblocks.port",
env = "FLASHBLOCKS_WS_PORT",
default_value = "1111"
)]
pub flashblocks_port: u16,

/// The address that we bind to for the websocket server that provides flashblocks
#[arg(
long = "flashblocks.addr",
env = "FLASHBLOCKS_WS_ADDR",
default_value = "127.0.0.1"
)]
pub flashblocks_addr: String,

/// flashblock block time in milliseconds
#[arg(
long = "flashblock.block-time",
default_value = "250",
env = "FLASHBLOCK_BLOCK_TIME"
)]
pub flashblocks_block_time: u64,
}
11 changes: 5 additions & 6 deletions crates/op-rbuilder/src/builders/flashblocks/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ impl TryFrom<OpRbuilderArgs> for FlashblocksConfig {
type Error = eyre::Report;

fn try_from(args: OpRbuilderArgs) -> Result<Self, Self::Error> {
let ws_addr = args
.flashblocks_ws_url
.parse()
.map_err(|_| eyre::eyre!("Invalid flashblocks websocket address"))?;

let interval = Duration::from_millis(args.flashblock_block_time);
let interval = Duration::from_millis(args.flashblocks.flashblocks_block_time);

let ws_addr = SocketAddr::new(
args.flashblocks.flashblocks_addr.parse()?,
args.flashblocks.flashblocks_port,
);
Ok(Self { ws_addr, interval })
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/op-rbuilder/src/tests/flashblocks/smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::tests::TestHarnessBuilder;
#[ignore = "Flashblocks tests need more work"]
async fn chain_produces_blocks() -> eyre::Result<()> {
let harness = TestHarnessBuilder::new("flashbots_chain_produces_blocks")
.with_flashblocks_ws_url("ws://localhost:1239")
.with_flashblocks_port(1239)
.with_chain_block_time(2000)
.with_flashbots_block_time(200)
.build()
Expand Down
12 changes: 6 additions & 6 deletions crates/op-rbuilder/src/tests/framework/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use uuid::Uuid;
pub struct TestHarnessBuilder {
name: String,
use_revert_protection: bool,
flashblocks_ws_url: Option<String>,
flashblocks_port: Option<u16>,
chain_block_time: Option<u64>,
flashbots_block_time: Option<u64>,
namespaces: Option<String>,
Expand All @@ -34,7 +34,7 @@ impl TestHarnessBuilder {
Self {
name: name.to_string(),
use_revert_protection: false,
flashblocks_ws_url: None,
flashblocks_port: None,
chain_block_time: None,
flashbots_block_time: None,
namespaces: None,
Expand All @@ -47,8 +47,8 @@ impl TestHarnessBuilder {
self
}

pub fn with_flashblocks_ws_url(mut self, url: &str) -> Self {
self.flashblocks_ws_url = Some(url.to_string());
pub fn with_flashblocks_port(mut self, port: u16) -> Self {
self.flashblocks_port = Some(port);
self
}

Expand Down Expand Up @@ -96,8 +96,8 @@ impl TestHarnessBuilder {
.with_revert_protection(self.use_revert_protection)
.with_namespaces(self.namespaces)
.with_extra_params(self.extra_params);
if let Some(flashblocks_ws_url) = self.flashblocks_ws_url {
op_rbuilder_config = op_rbuilder_config.with_flashblocks_ws_url(&flashblocks_ws_url);
if let Some(flashblocks_port) = self.flashblocks_port {
op_rbuilder_config = op_rbuilder_config.with_flashblocks_port(flashblocks_port);
}

if let Some(chain_block_time) = self.chain_block_time {
Expand Down
16 changes: 8 additions & 8 deletions crates/op-rbuilder/src/tests/framework/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct OpRbuilderConfig {
http_port: Option<u16>,
network_port: Option<u16>,
builder_private_key: Option<String>,
flashblocks_ws_url: Option<String>,
flashblocks_port: Option<u16>,
Copy link
Contributor Author

@ferranbt ferranbt May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using port here since we do not really have any utility to change the bind address during tests.

chain_block_time: Option<u64>,
flashbots_block_time: Option<u64>,
with_revert_protection: Option<bool>,
Expand Down Expand Up @@ -71,8 +71,8 @@ impl OpRbuilderConfig {
self
}

pub fn with_flashblocks_ws_url(mut self, url: &str) -> Self {
self.flashblocks_ws_url = Some(url.to_string());
pub fn with_flashblocks_port(mut self, port: u16) -> Self {
self.flashblocks_port = Some(port);
self
}

Expand Down Expand Up @@ -152,11 +152,11 @@ impl Service for OpRbuilderConfig {
.arg(http_port.to_string());
}

if let Some(flashblocks_ws_url) = &self.flashblocks_ws_url {
cmd.arg("--rollup.enable-flashblocks").arg("true");

cmd.arg("--rollup.flashblocks-ws-url")
.arg(flashblocks_ws_url);
if let Some(flashblocks_port) = &self.flashblocks_port {
cmd.arg("--flashblocks.enabled").arg("true");
cmd.arg("--flashblocks.addr").arg("127.0.0.1");
cmd.arg("--flashblocks.port")
.arg(flashblocks_port.to_string());
}

if let Some(chain_block_time) = self.chain_block_time {
Expand Down
Loading