Skip to content

Commit

Permalink
proper CLI option for L1 support + printing L1 config for user
Browse files Browse the repository at this point in the history
  • Loading branch information
itegulov committed Feb 10, 2025
1 parent 5c6237d commit cf3c483
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 18 deletions.
16 changes: 11 additions & 5 deletions crates/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use anvil_zksync_config::constants::{
use anvil_zksync_config::types::{
AccountGenerator, CacheConfig, CacheType, Genesis, SystemContractsOptions,
};
use anvil_zksync_config::TestNodeConfig;
use anvil_zksync_config::{L1Config, TestNodeConfig};
use anvil_zksync_core::node::fork::ForkConfig;
use anvil_zksync_core::{
node::{InMemoryNode, VersionedState},
Expand Down Expand Up @@ -316,9 +316,13 @@ pub struct Cli {
#[arg(long, default_value = "fifo")]
pub order: TransactionOrder,

#[arg(long, help_heading = "L1")]
/// Port the spawned L1 anvil node will listen on
pub l1_anvil_port: Option<u16>,
/// Enable L1 support.
#[arg(long, help_heading = "UNSTABLE - L1")]
pub with_l1: bool,

/// Port the spawned L1 anvil node will listen on.
#[arg(long, requires = "with_l1", help_heading = "UNSTABLE - L1")]
pub l1_port: Option<u16>,
}

#[derive(Debug, Subcommand, Clone)]
Expand Down Expand Up @@ -508,7 +512,9 @@ impl Cli {
.with_dump_state(self.dump_state)
.with_preserve_historical_states(self.preserve_historical_states)
.with_load_state(self.load_state)
.with_l1_anvil_port(self.l1_anvil_port);
.with_l1_config(self.with_l1.then(|| L1Config {
port: self.l1_port.unwrap_or(8012),
}));

if self.emulate_evm && self.dev_system_contracts != Some(SystemContractsOptions::Local) {
return Err(eyre::eyre!(
Expand Down
6 changes: 3 additions & 3 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ async fn main() -> anyhow::Result<()> {
};

let mut node_service_tasks: Vec<Pin<Box<dyn Future<Output = anyhow::Result<()>>>>> = Vec::new();
let l1_sidecar = match config.l1_anvil_port {
Some(l1_anvil_port) => {
let (l1_sidecar, l1_sidecar_runner) = L1Sidecar::builtin(l1_anvil_port).await?;
let l1_sidecar = match config.l1_config.as_ref() {
Some(l1_config) => {
let (l1_sidecar, l1_sidecar_runner) = L1Sidecar::builtin(l1_config.port).await?;
node_service_tasks.push(Box::pin(l1_sidecar_runner.run()));
l1_sidecar
}
Expand Down
37 changes: 29 additions & 8 deletions crates/config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,14 @@ pub struct TestNodeConfig {
pub preserve_historical_states: bool,
/// State to load
pub load_state: Option<PathBuf>,
/// L1 configuration, disabled if `None`
pub l1_config: Option<L1Config>,
}

#[derive(Debug, Clone)]
pub struct L1Config {
/// Port the spawned L1 anvil node will listen on
pub l1_anvil_port: Option<u16>,
pub port: u16,
}

impl Default for TestNodeConfig {
Expand Down Expand Up @@ -208,7 +214,7 @@ impl Default for TestNodeConfig {
state_interval: None,
preserve_historical_states: false,
load_state: None,
l1_anvil_port: None,
l1_config: None,
}
}
}
Expand Down Expand Up @@ -361,9 +367,9 @@ impl TestNodeConfig {

tracing::info!("Node Configuration");
tracing::info!("========================");
tracing::info!("Port: {}", self.port);
tracing::info!("Port: {}", self.port);
tracing::info!(
"EVM Emulator: {}",
"EVM Emulator: {}",
if self.use_evm_emulator {
"Enabled".green()
} else {
Expand All @@ -379,13 +385,28 @@ impl TestNodeConfig {
}
);
tracing::info!(
"ZK OS: {}",
"ZK OS: {}",
if self.use_zkos {
"Enabled".green()
} else {
"Disabled".red()
}
);
tracing::info!(
"L1: {}",
if self.l1_config.is_some() {
"Enabled".green()
} else {
"Disabled".red()
}
);

if let Some(l1_config) = self.l1_config.as_ref() {
println!("\n");
tracing::info!("L1 Configuration");
tracing::info!("========================");
tracing::info!("Port: {}", l1_config.port);
}

println!("\n");
tracing::info!("========================================");
Expand Down Expand Up @@ -983,10 +1004,10 @@ impl TestNodeConfig {
self
}

/// Set the L1 anvil port
/// Set the L1 config
#[must_use]
pub fn with_l1_anvil_port(mut self, l1_anvil_port: Option<u16>) -> Self {
self.l1_anvil_port = l1_anvil_port;
pub fn with_l1_config(mut self, l1_config: Option<L1Config>) -> Self {
self.l1_config = l1_config;
self
}
}
2 changes: 1 addition & 1 deletion crates/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ pub mod constants;
pub mod types;
pub mod utils;

pub use config::{ForkPrintInfo, TestNodeConfig};
pub use config::{ForkPrintInfo, L1Config, TestNodeConfig};
2 changes: 1 addition & 1 deletion crates/l1_sidecar/src/anvil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl L1AnvilEnv {
break;
}
Err(err) if err.is_transport_error() => {
tracing::info!(?err, "L1 Anvil is not up yet; sleeping");
tracing::debug!(?err, "L1 Anvil is not up yet; sleeping");
tokio::time::sleep(Duration::from_millis(100)).await;
}
Err(err) => return Err(err.into()),
Expand Down

0 comments on commit cf3c483

Please sign in to comment.