Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into daniyar/async-block-s…
Browse files Browse the repository at this point in the history
…ealer
  • Loading branch information
itegulov committed Nov 27, 2024
2 parents ad3b8a3 + 16c4d6d commit 767f5c5
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 52 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "era_test_node"
version = "0.1.0-alpha.33"
version = "0.1.0-alpha.34"
edition = "2018"
authors = ["The Matter Labs Team <[email protected]>"]
homepage = "https://zksync.io/"
Expand Down
21 changes: 17 additions & 4 deletions src/config/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,10 @@ pub struct ForkArgs {
/// - http://XXX:YY
#[arg(
long,
help = "Network to fork from (e.g., mainnet, sepolia-testnet, etc.)."
alias = "network",
help = "Network to fork from (e.g., http://XXX:YY, mainnet, sepolia-testnet)."
)]
pub network: String,
pub fork_url: String,
// Fork at a given L2 miniblock height.
// If not set - will use the current finalized block from the network.
#[arg(
Expand All @@ -245,6 +246,17 @@ pub struct ForkArgs {
alias = "fork-at"
)]
pub fork_block_number: Option<u64>,

/// Fetch state from a specific transaction hash over a remote endpoint.
///
/// See --fork-url.
#[arg(
long,
requires = "fork_url",
value_name = "TRANSACTION",
conflicts_with = "fork_block_number"
)]
pub fork_transaction_hash: Option<H256>,
}

#[derive(Debug, Parser, Clone)]
Expand All @@ -258,9 +270,10 @@ pub struct ReplayArgs {
/// - http://XXX:YY
#[arg(
long,
help = "Network to fork from (e.g., mainnet, sepolia-testnet, etc.)."
alias = "network",
help = "Network to fork from (e.g., http://XXX:YY, mainnet, sepolia-testnet)."
)]
pub network: String,
pub fork_url: String,
/// Transaction hash to replay.
#[arg(help = "Transaction hash to replay.")]
pub tx: H256,
Expand Down
63 changes: 61 additions & 2 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::net::{IpAddr, Ipv4Addr};

use crate::fork::ForkDetails;
use crate::{observability, system_contracts};
use anyhow::anyhow;
use std::net::{IpAddr, Ipv4Addr};

use crate::config::{
cache::{CacheConfig, CacheType},
Expand Down Expand Up @@ -414,6 +415,12 @@ impl TestNodeConfig {
self.chain_id.unwrap_or(TEST_NODE_NETWORK_ID)
}

/// Update the chain ID
pub fn update_chain_id(&mut self, chain_id: Option<u32>) -> &mut Self {
self.chain_id = chain_id;
self
}

/// Set the system contracts configuration option
#[must_use]
pub fn with_system_contracts(mut self, option: Option<system_contracts::Options>) -> Self {
Expand Down Expand Up @@ -470,6 +477,12 @@ impl TestNodeConfig {
self.l1_gas_price.unwrap_or(DEFAULT_L1_GAS_PRICE)
}

/// Update the L1 gas price
pub fn update_l1_gas_price(&mut self, price: Option<u64>) -> &mut Self {
self.l1_gas_price = price;
self
}

/// Set the L2 gas price
#[must_use]
pub fn with_l2_gas_price(mut self, price: Option<u64>) -> Self {
Expand All @@ -484,6 +497,12 @@ impl TestNodeConfig {
self.l2_gas_price.unwrap_or(DEFAULT_L2_GAS_PRICE)
}

/// Update the L2 gas price
pub fn update_l2_gas_price(&mut self, price: Option<u64>) -> &mut Self {
self.l2_gas_price = price;
self
}

/// Set the L1 pubdata price
#[must_use]
pub fn with_l1_pubdata_price(mut self, price: Option<u64>) -> Self {
Expand All @@ -496,6 +515,12 @@ impl TestNodeConfig {
self.l1_pubdata_price.unwrap_or(DEFAULT_FAIR_PUBDATA_PRICE)
}

/// Update the L1 pubdata price
pub fn update_l1_pubdata_price(&mut self, price: Option<u64>) -> &mut Self {
self.l1_pubdata_price = price;
self
}

/// Set the log level
#[must_use]
pub fn with_log_level(mut self, level: Option<LogLevel>) -> Self {
Expand Down Expand Up @@ -581,6 +606,12 @@ impl TestNodeConfig {
.unwrap_or(DEFAULT_ESTIMATE_GAS_SCALE_FACTOR)
}

/// Update the gas limit scale factor
pub fn update_gas_limit_scale(&mut self, scale: Option<f32>) -> &mut Self {
self.limit_scale_factor = scale;
self
}

/// Set the price scale factor
#[must_use]
pub fn with_price_scale(mut self, scale: Option<f64>) -> Self {
Expand All @@ -596,6 +627,12 @@ impl TestNodeConfig {
.unwrap_or(DEFAULT_ESTIMATE_GAS_PRICE_SCALE_FACTOR)
}

/// Updates the price scale factor
pub fn update_price_scale(&mut self, scale: Option<f64>) -> &mut Self {
self.price_scale_factor = scale;
self
}

/// Set the detail level of VM execution logs
#[must_use]
pub fn with_vm_log_detail(mut self, detail: Option<ShowVMDetails>) -> Self {
Expand Down Expand Up @@ -686,6 +723,28 @@ impl TestNodeConfig {
self.health_check_endpoint
}

/// Updates the configuration from fork details.
pub async fn update_with_fork_details(
&mut self,
fork_details_result: Result<ForkDetails, eyre::Report>,
) -> Result<Option<ForkDetails>, anyhow::Error> {
match fork_details_result {
Ok(fd) => {
self.update_l1_gas_price(Some(fd.l1_gas_price))
.update_l2_gas_price(Some(fd.l2_fair_gas_price))
.update_l1_pubdata_price(Some(fd.fair_pubdata_price))
.update_price_scale(Some(fd.estimate_gas_price_scale_factor))
.update_gas_limit_scale(Some(fd.estimate_gas_scale_factor))
.update_chain_id(Some(fd.chain_id.as_u64() as u32));
Ok(Some(fd))
}
Err(error) => {
tracing::error!("Error while attempting to fork: {:?}", error);
Err(anyhow!(error))
}
}
}

/// Set the block time
#[must_use]
pub fn with_block_time(mut self, block_time: Option<Duration>) -> Self {
Expand Down
71 changes: 27 additions & 44 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use bytecode_override::override_bytecodes;
use clap::Parser;
use config::cli::{Cli, Command};
use config::constants::{
DEFAULT_ESTIMATE_GAS_PRICE_SCALE_FACTOR, DEFAULT_ESTIMATE_GAS_SCALE_FACTOR, LEGACY_RICH_WALLETS,
DEFAULT_ESTIMATE_GAS_PRICE_SCALE_FACTOR, DEFAULT_ESTIMATE_GAS_SCALE_FACTOR,
LEGACY_RICH_WALLETS, RICH_WALLETS,
};
use config::ForkPrintInfo;
use fork::{ForkDetails, ForkSource};
Expand Down Expand Up @@ -156,54 +157,30 @@ async fn main() -> anyhow::Result<()> {
}
}
Command::Fork(fork) => {
match ForkDetails::from_network(
&fork.network,
fork.fork_block_number,
&config.cache_config,
)
.await
{
Ok(fd) => {
// Update the config here
config = config
.with_l1_gas_price(Some(fd.l1_gas_price))
.with_l2_gas_price(Some(fd.l2_fair_gas_price))
.with_l1_pubdata_price(Some(fd.fair_pubdata_price))
.with_price_scale(Some(fd.estimate_gas_price_scale_factor))
.with_gas_limit_scale(Some(fd.estimate_gas_scale_factor))
.with_chain_id(Some(fd.chain_id.as_u64() as u32));
Some(fd)
}
Err(error) => {
tracing::error!("cannot fork: {:?}", error);
return Err(anyhow!(error));
}
}
let fork_details_result = if let Some(tx_hash) = fork.fork_transaction_hash {
// If fork_transaction_hash is provided, use from_network_tx
ForkDetails::from_network_tx(&fork.fork_url, tx_hash, &config.cache_config).await
} else {
// Otherwise, use from_network
ForkDetails::from_network(
&fork.fork_url,
fork.fork_block_number,
&config.cache_config,
)
.await
};

config.update_with_fork_details(fork_details_result).await?
}
Command::ReplayTx(replay_tx) => {
match ForkDetails::from_network_tx(
&replay_tx.network,
let fork_details_result = ForkDetails::from_network_tx(
&replay_tx.fork_url,
replay_tx.tx,
&config.cache_config,
)
.await
{
Ok(fd) => {
// Update the config here
config = config
.with_l1_gas_price(Some(fd.l1_gas_price))
.with_l2_gas_price(Some(fd.l2_fair_gas_price))
.with_l1_pubdata_price(Some(fd.fair_pubdata_price))
.with_price_scale(Some(fd.estimate_gas_price_scale_factor))
.with_gas_limit_scale(Some(fd.estimate_gas_scale_factor))
.with_chain_id(Some(fd.chain_id.as_u64() as u32));
Some(fd)
}
Err(error) => {
tracing::error!("cannot replay: {:?}", error);
return Err(anyhow!(error));
}
}
.await;

config.update_with_fork_details(fork_details_result).await?
}
};

Expand Down Expand Up @@ -293,10 +270,16 @@ async fn main() -> anyhow::Result<()> {
let address = H160::from_slice(signer.address().as_ref());
node.set_rich_account(address, config.genesis_balance);
}
// sets legacy rich wallets
for wallet in LEGACY_RICH_WALLETS.iter() {
let address = wallet.0;
node.set_rich_account(H160::from_str(address).unwrap(), config.genesis_balance);
}
// sets additional legacy rich wallets
for wallet in RICH_WALLETS.iter() {
let address = wallet.0;
node.set_rich_account(H160::from_str(address).unwrap(), config.genesis_balance);
}

let mut threads = future::join_all(config.host.iter().map(|host| {
let addr = SocketAddr::new(*host, config.port);
Expand Down

0 comments on commit 767f5c5

Please sign in to comment.