Skip to content
Closed
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
6 changes: 2 additions & 4 deletions crates/builder/op-rbuilder/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
// THE SOFTWARE.

use std::{env, error::Error};

use vergen::{BuildBuilder, CargoBuilder, Emitter};
use vergen_git2::Git2Builder;

Expand All @@ -32,10 +33,7 @@ fn main() -> Result<(), Box<dyn Error>> {

emitter.add_instructions(&build_builder)?;

let cargo_builder = CargoBuilder::default()
.features(true)
.target_triple(true)
.build()?;
let cargo_builder = CargoBuilder::default().features(true).target_triple(true).build()?;

emitter.add_instructions(&cargo_builder)?;

Expand Down
9 changes: 5 additions & 4 deletions crates/builder/op-rbuilder/src/args/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use crate::{
builders::BuilderMode,
metrics::{LONG_VERSION, SHORT_VERSION},
};
use clap_builder::{CommandFactory, FromArgMatches};
pub use op::{FlashblocksArgs, OpRbuilderArgs, TelemetryArgs};
use playground::PlaygroundOptions;
use reth_optimism_cli::{chainspec::OpChainSpecParser, commands::Commands};

use crate::{
builders::BuilderMode,
metrics::{LONG_VERSION, SHORT_VERSION},
};

mod op;
mod playground;

Expand Down
84 changes: 20 additions & 64 deletions crates/builder/op-rbuilder/src/args/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@

//! clap [Args](clap::Args) for optimism rollup configuration

use crate::{
flashtestations::args::FlashtestationsArgs, gas_limiter::args::GasLimiterArgs,
tx_signer::Signer,
};
use std::path::PathBuf;

use alloy_primitives::Address;
use anyhow::{Result, anyhow};
use clap::Parser;
use reth_optimism_cli::commands::Commands;
use reth_optimism_node::args::RollupArgs;
use std::path::PathBuf;

use crate::{
flashtestations::args::FlashtestationsArgs, gas_limiter::args::GasLimiterArgs,
tx_signer::Signer,
};

/// Parameters for rollup configuration
#[derive(Debug, Clone, PartialEq, Eq, clap::Args)]
Expand All @@ -27,11 +29,7 @@ pub struct OpRbuilderArgs {
pub builder_signer: Option<Signer>,

/// chain block time in milliseconds
#[arg(
long = "rollup.chain-block-time",
default_value = "1000",
env = "CHAIN_BLOCK_TIME"
)]
#[arg(long = "rollup.chain-block-time", default_value = "1000", env = "CHAIN_BLOCK_TIME")]
pub chain_block_time: u64,

/// max gas a transaction can use
Expand Down Expand Up @@ -78,9 +76,7 @@ pub struct OpRbuilderArgs {
impl Default for OpRbuilderArgs {
fn default() -> Self {
let args = crate::args::Cli::parse_from(["dummy", "node"]);
let Commands::Node(node_command) = args.command else {
unreachable!()
};
let Commands::Node(node_command) = args.command else { unreachable!() };
node_command.ext
}
}
Expand All @@ -104,56 +100,32 @@ pub struct FlashblocksArgs {
///
/// The default value will change in the future once the flashblocks
/// feature is stable.
#[arg(
long = "flashblocks.enabled",
default_value = "false",
env = "ENABLE_FLASHBLOCKS"
)]
#[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"
)]
#[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"
)]
#[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 = "flashblocks.block-time",
default_value = "250",
env = "FLASHBLOCK_BLOCK_TIME"
)]
#[arg(long = "flashblocks.block-time", default_value = "250", env = "FLASHBLOCK_BLOCK_TIME")]
pub flashblocks_block_time: u64,

/// Builder would always thry to produce fixed number of flashblocks without regard to time of
/// FCU arrival.
/// In cases of late FCU it could lead to partially filled blocks.
#[arg(
long = "flashblocks.fixed",
default_value = "false",
env = "FLASHBLOCK_FIXED"
)]
#[arg(long = "flashblocks.fixed", default_value = "false", env = "FLASHBLOCK_FIXED")]
pub flashblocks_fixed: bool,

/// Time by which blocks would be completed earlier in milliseconds.
///
/// This time used to account for latencies, this time would be deducted from total block
/// building time before calculating number of fbs.
#[arg(
long = "flashblocks.leeway-time",
default_value = "75",
env = "FLASHBLOCK_LEEWAY_TIME"
)]
#[arg(long = "flashblocks.leeway-time", default_value = "75", env = "FLASHBLOCK_LEEWAY_TIME")]
pub flashblocks_leeway_time: u64,

/// Whether to disable state root calculation for each flashblock
Expand Down Expand Up @@ -191,9 +163,7 @@ pub struct FlashblocksArgs {
impl Default for FlashblocksArgs {
fn default() -> Self {
let args = crate::args::Cli::parse_from(["dummy", "node"]);
let Commands::Node(node_command) = args.command else {
unreachable!()
};
let Commands::Node(node_command) = args.command else { unreachable!() };
node_command.ext.flashblocks
}
}
Expand All @@ -209,27 +179,17 @@ pub struct FlashblocksP2pArgs {
pub p2p_enabled: bool,

/// Port for the flashblocks p2p node
#[arg(
long = "flashblocks.p2p_port",
env = "FLASHBLOCK_P2P_PORT",
default_value = "9009"
)]
#[arg(long = "flashblocks.p2p_port", env = "FLASHBLOCK_P2P_PORT", default_value = "9009")]
pub p2p_port: u16,

/// Path to the file containing a hex-encoded libp2p private key.
/// If the file does not exist, a new key will be generated.
#[arg(
long = "flashblocks.p2p_private_key_file",
env = "FLASHBLOCK_P2P_PRIVATE_KEY_FILE"
)]
#[arg(long = "flashblocks.p2p_private_key_file", env = "FLASHBLOCK_P2P_PRIVATE_KEY_FILE")]
pub p2p_private_key_file: Option<String>,

/// Comma-separated list of multiaddrs of known Flashblocks peers
/// Example: "/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ,/ip4/104.131.131.82/udp/4001/quic-v1/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ"
#[arg(
long = "flashblocks.p2p_known_peers",
env = "FLASHBLOCK_P2P_KNOWN_PEERS"
)]
#[arg(long = "flashblocks.p2p_known_peers", env = "FLASHBLOCK_P2P_KNOWN_PEERS")]
pub p2p_known_peers: Option<String>,

/// Maximum number of peers for the flashblocks p2p node
Expand All @@ -253,10 +213,6 @@ pub struct TelemetryArgs {
pub otlp_headers: Option<String>,

/// Inverted sampling frequency in blocks. 1 - each block, 100 - every 100th block.
#[arg(
long = "telemetry.sampling-ratio",
env = "SAMPLING_RATIO",
default_value = "100"
)]
#[arg(long = "telemetry.sampling-ratio", env = "SAMPLING_RATIO", default_value = "100")]
pub sampling_ratio: u64,
}
50 changes: 18 additions & 32 deletions crates/builder/op-rbuilder/src/args/playground.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,26 @@
//! directory to use. This is useful for testing against different playground
//! configurations.

use alloy_primitives::hex;
use clap::{CommandFactory, parser::ValueSource};
use core::{
net::{IpAddr, Ipv4Addr, SocketAddr},
ops::Range,
time::Duration,
};
use std::{
fs::read_to_string,
path::{Path, PathBuf},
sync::Arc,
};

use alloy_primitives::hex;
use clap::{CommandFactory, parser::ValueSource};
use eyre::{Result, eyre};
use reth_cli::chainspec::ChainSpecParser;
use reth_network_peers::TrustedPeer;
use reth_optimism_chainspec::OpChainSpec;
use reth_optimism_cli::{chainspec::OpChainSpecParser, commands::Commands};
use secp256k1::SecretKey;
use serde_json::Value;
use std::{
fs::read_to_string,
path::{Path, PathBuf},
sync::Arc,
};
use url::{Host, Url};

use super::Cli;
Expand Down Expand Up @@ -80,10 +81,7 @@ impl PlaygroundOptions {
/// Creates a new `PlaygroundOptions` instance with the specified genesis path.
pub(super) fn new(path: &Path) -> Result<Self> {
if !path.exists() {
return Err(eyre!(
"Playground data directory {} does not exist",
path.display()
));
return Err(eyre!("Playground data directory {} does not exist", path.display()));
}

let chain = OpChainSpecParser::parse(&existing_path(path, "l2-genesis.json")?)?;
Expand Down Expand Up @@ -127,9 +125,8 @@ impl PlaygroundOptions {
// either via the command line or an environment variable. Otherwise, don't
// override the user provided values.
let matches = Cli::command().get_matches();
let matches = matches
.subcommand_matches("node")
.expect("validated that we are in the node command");
let matches =
matches.subcommand_matches("node").expect("validated that we are in the node command");

if matches.value_source("chain").is_default() {
node.chain = self.chain;
Expand Down Expand Up @@ -223,9 +220,7 @@ fn extract_chain_block_time(basepath: &Path) -> Result<Duration> {

fn extract_deterministic_p2p_key(basepath: &Path) -> Result<SecretKey> {
let key = read_to_string(existing_path(basepath, "enode-key-1.txt")?)?;
Ok(SecretKey::from_slice(
&hex::decode(key).map_err(|e| eyre!("Invalid hex key: {e}"))?,
)?)
Ok(SecretKey::from_slice(&hex::decode(key).map_err(|e| eyre!("Invalid hex key: {e}"))?)?)
}

fn read_docker_compose(basepath: &Path) -> Result<serde_yaml::Value> {
Expand All @@ -238,9 +233,7 @@ fn extract_service_command_flag(basepath: &Path, service: &str, flag: &str) -> R
let docker_compose = read_docker_compose(basepath)?;
let args = docker_compose["services"][service]["command"]
.as_sequence()
.ok_or(eyre!(
"docker-compose.yaml is missing command line arguments for {service}"
))?
.ok_or(eyre!("docker-compose.yaml is missing command line arguments for {service}"))?
.iter()
.map(|s| {
s.as_str().ok_or_else(|| {
Expand All @@ -254,9 +247,8 @@ fn extract_service_command_flag(basepath: &Path, service: &str, flag: &str) -> R
.position(|arg| *arg == flag)
.ok_or_else(|| eyre!("docker_compose: {flag} not found on {service} service"))?;

let value = args
.get(index + 1)
.ok_or_else(|| eyre!("docker_compose: {flag} value not found"))?;
let value =
args.get(index + 1).ok_or_else(|| eyre!("docker_compose: {flag} value not found"))?;

Ok(value.to_string())
}
Expand All @@ -274,9 +266,7 @@ fn extract_trusted_peer_port(basepath: &Path) -> Result<u16> {
// command line arguments used to start the op-geth service

let Some(opgeth_args) = docker_compose["services"]["op-geth"]["command"][1].as_str() else {
return Err(eyre!(
"docker-compose.yaml is missing command line arguments for op-geth"
));
return Err(eyre!("docker-compose.yaml is missing command line arguments for op-geth"));
};

let opgeth_args = opgeth_args.split_whitespace().collect::<Vec<_>>();
Expand All @@ -289,16 +279,12 @@ fn extract_trusted_peer_port(basepath: &Path) -> Result<u16> {
.get(port_param_position + 1)
.ok_or_else(|| eyre!("docker_compose: --port value not found"))?;

let port_value = port_value
.parse::<u16>()
.map_err(|e| eyre!("Invalid port value: {e}"))?;
let port_value = port_value.parse::<u16>().map_err(|e| eyre!("Invalid port value: {e}"))?;

// now we need to find the external port of the op-geth service from the docker-compose.yaml
// ports mapping used to start the op-geth service
let Some(opgeth_ports) = docker_compose["services"]["op-geth"]["ports"].as_sequence() else {
return Err(eyre!(
"docker-compose.yaml is missing ports mapping for op-geth"
));
return Err(eyre!("docker-compose.yaml is missing ports mapping for op-geth"));
};
let ports_mapping = opgeth_ports
.iter()
Expand Down
4 changes: 1 addition & 3 deletions crates/builder/op-rbuilder/src/bin/tester/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ pub async fn run_system(validation: bool) -> eyre::Result<()> {
let mut driver = ChainDriver::<Http>::remote(provider, engine_api);

if validation {
driver = driver
.with_validation_node(ExternalNode::reth().await?)
.await?;
driver = driver.with_validation_node(ExternalNode::reth().await?).await?;
}

// Infinite loop generating blocks
Expand Down
Loading
Loading