Skip to content

Commit 767f5c5

Browse files
committed
Merge remote-tracking branch 'origin/main' into daniyar/async-block-sealer
2 parents ad3b8a3 + 16c4d6d commit 767f5c5

File tree

5 files changed

+107
-52
lines changed

5 files changed

+107
-52
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "era_test_node"
3-
version = "0.1.0-alpha.33"
3+
version = "0.1.0-alpha.34"
44
edition = "2018"
55
authors = ["The Matter Labs Team <[email protected]>"]
66
homepage = "https://zksync.io/"

src/config/cli.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,10 @@ pub struct ForkArgs {
233233
/// - http://XXX:YY
234234
#[arg(
235235
long,
236-
help = "Network to fork from (e.g., mainnet, sepolia-testnet, etc.)."
236+
alias = "network",
237+
help = "Network to fork from (e.g., http://XXX:YY, mainnet, sepolia-testnet)."
237238
)]
238-
pub network: String,
239+
pub fork_url: String,
239240
// Fork at a given L2 miniblock height.
240241
// If not set - will use the current finalized block from the network.
241242
#[arg(
@@ -245,6 +246,17 @@ pub struct ForkArgs {
245246
alias = "fork-at"
246247
)]
247248
pub fork_block_number: Option<u64>,
249+
250+
/// Fetch state from a specific transaction hash over a remote endpoint.
251+
///
252+
/// See --fork-url.
253+
#[arg(
254+
long,
255+
requires = "fork_url",
256+
value_name = "TRANSACTION",
257+
conflicts_with = "fork_block_number"
258+
)]
259+
pub fork_transaction_hash: Option<H256>,
248260
}
249261

250262
#[derive(Debug, Parser, Clone)]
@@ -258,9 +270,10 @@ pub struct ReplayArgs {
258270
/// - http://XXX:YY
259271
#[arg(
260272
long,
261-
help = "Network to fork from (e.g., mainnet, sepolia-testnet, etc.)."
273+
alias = "network",
274+
help = "Network to fork from (e.g., http://XXX:YY, mainnet, sepolia-testnet)."
262275
)]
263-
pub network: String,
276+
pub fork_url: String,
264277
/// Transaction hash to replay.
265278
#[arg(help = "Transaction hash to replay.")]
266279
pub tx: H256,

src/config/mod.rs

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use std::net::{IpAddr, Ipv4Addr};
2-
1+
use crate::fork::ForkDetails;
32
use crate::{observability, system_contracts};
3+
use anyhow::anyhow;
4+
use std::net::{IpAddr, Ipv4Addr};
45

56
use crate::config::{
67
cache::{CacheConfig, CacheType},
@@ -414,6 +415,12 @@ impl TestNodeConfig {
414415
self.chain_id.unwrap_or(TEST_NODE_NETWORK_ID)
415416
}
416417

418+
/// Update the chain ID
419+
pub fn update_chain_id(&mut self, chain_id: Option<u32>) -> &mut Self {
420+
self.chain_id = chain_id;
421+
self
422+
}
423+
417424
/// Set the system contracts configuration option
418425
#[must_use]
419426
pub fn with_system_contracts(mut self, option: Option<system_contracts::Options>) -> Self {
@@ -470,6 +477,12 @@ impl TestNodeConfig {
470477
self.l1_gas_price.unwrap_or(DEFAULT_L1_GAS_PRICE)
471478
}
472479

480+
/// Update the L1 gas price
481+
pub fn update_l1_gas_price(&mut self, price: Option<u64>) -> &mut Self {
482+
self.l1_gas_price = price;
483+
self
484+
}
485+
473486
/// Set the L2 gas price
474487
#[must_use]
475488
pub fn with_l2_gas_price(mut self, price: Option<u64>) -> Self {
@@ -484,6 +497,12 @@ impl TestNodeConfig {
484497
self.l2_gas_price.unwrap_or(DEFAULT_L2_GAS_PRICE)
485498
}
486499

500+
/// Update the L2 gas price
501+
pub fn update_l2_gas_price(&mut self, price: Option<u64>) -> &mut Self {
502+
self.l2_gas_price = price;
503+
self
504+
}
505+
487506
/// Set the L1 pubdata price
488507
#[must_use]
489508
pub fn with_l1_pubdata_price(mut self, price: Option<u64>) -> Self {
@@ -496,6 +515,12 @@ impl TestNodeConfig {
496515
self.l1_pubdata_price.unwrap_or(DEFAULT_FAIR_PUBDATA_PRICE)
497516
}
498517

518+
/// Update the L1 pubdata price
519+
pub fn update_l1_pubdata_price(&mut self, price: Option<u64>) -> &mut Self {
520+
self.l1_pubdata_price = price;
521+
self
522+
}
523+
499524
/// Set the log level
500525
#[must_use]
501526
pub fn with_log_level(mut self, level: Option<LogLevel>) -> Self {
@@ -581,6 +606,12 @@ impl TestNodeConfig {
581606
.unwrap_or(DEFAULT_ESTIMATE_GAS_SCALE_FACTOR)
582607
}
583608

609+
/// Update the gas limit scale factor
610+
pub fn update_gas_limit_scale(&mut self, scale: Option<f32>) -> &mut Self {
611+
self.limit_scale_factor = scale;
612+
self
613+
}
614+
584615
/// Set the price scale factor
585616
#[must_use]
586617
pub fn with_price_scale(mut self, scale: Option<f64>) -> Self {
@@ -596,6 +627,12 @@ impl TestNodeConfig {
596627
.unwrap_or(DEFAULT_ESTIMATE_GAS_PRICE_SCALE_FACTOR)
597628
}
598629

630+
/// Updates the price scale factor
631+
pub fn update_price_scale(&mut self, scale: Option<f64>) -> &mut Self {
632+
self.price_scale_factor = scale;
633+
self
634+
}
635+
599636
/// Set the detail level of VM execution logs
600637
#[must_use]
601638
pub fn with_vm_log_detail(mut self, detail: Option<ShowVMDetails>) -> Self {
@@ -686,6 +723,28 @@ impl TestNodeConfig {
686723
self.health_check_endpoint
687724
}
688725

726+
/// Updates the configuration from fork details.
727+
pub async fn update_with_fork_details(
728+
&mut self,
729+
fork_details_result: Result<ForkDetails, eyre::Report>,
730+
) -> Result<Option<ForkDetails>, anyhow::Error> {
731+
match fork_details_result {
732+
Ok(fd) => {
733+
self.update_l1_gas_price(Some(fd.l1_gas_price))
734+
.update_l2_gas_price(Some(fd.l2_fair_gas_price))
735+
.update_l1_pubdata_price(Some(fd.fair_pubdata_price))
736+
.update_price_scale(Some(fd.estimate_gas_price_scale_factor))
737+
.update_gas_limit_scale(Some(fd.estimate_gas_scale_factor))
738+
.update_chain_id(Some(fd.chain_id.as_u64() as u32));
739+
Ok(Some(fd))
740+
}
741+
Err(error) => {
742+
tracing::error!("Error while attempting to fork: {:?}", error);
743+
Err(anyhow!(error))
744+
}
745+
}
746+
}
747+
689748
/// Set the block time
690749
#[must_use]
691750
pub fn with_block_time(mut self, block_time: Option<Duration>) -> Self {

src/main.rs

Lines changed: 27 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use bytecode_override::override_bytecodes;
44
use clap::Parser;
55
use config::cli::{Cli, Command};
66
use config::constants::{
7-
DEFAULT_ESTIMATE_GAS_PRICE_SCALE_FACTOR, DEFAULT_ESTIMATE_GAS_SCALE_FACTOR, LEGACY_RICH_WALLETS,
7+
DEFAULT_ESTIMATE_GAS_PRICE_SCALE_FACTOR, DEFAULT_ESTIMATE_GAS_SCALE_FACTOR,
8+
LEGACY_RICH_WALLETS, RICH_WALLETS,
89
};
910
use config::ForkPrintInfo;
1011
use fork::{ForkDetails, ForkSource};
@@ -156,54 +157,30 @@ async fn main() -> anyhow::Result<()> {
156157
}
157158
}
158159
Command::Fork(fork) => {
159-
match ForkDetails::from_network(
160-
&fork.network,
161-
fork.fork_block_number,
162-
&config.cache_config,
163-
)
164-
.await
165-
{
166-
Ok(fd) => {
167-
// Update the config here
168-
config = config
169-
.with_l1_gas_price(Some(fd.l1_gas_price))
170-
.with_l2_gas_price(Some(fd.l2_fair_gas_price))
171-
.with_l1_pubdata_price(Some(fd.fair_pubdata_price))
172-
.with_price_scale(Some(fd.estimate_gas_price_scale_factor))
173-
.with_gas_limit_scale(Some(fd.estimate_gas_scale_factor))
174-
.with_chain_id(Some(fd.chain_id.as_u64() as u32));
175-
Some(fd)
176-
}
177-
Err(error) => {
178-
tracing::error!("cannot fork: {:?}", error);
179-
return Err(anyhow!(error));
180-
}
181-
}
160+
let fork_details_result = if let Some(tx_hash) = fork.fork_transaction_hash {
161+
// If fork_transaction_hash is provided, use from_network_tx
162+
ForkDetails::from_network_tx(&fork.fork_url, tx_hash, &config.cache_config).await
163+
} else {
164+
// Otherwise, use from_network
165+
ForkDetails::from_network(
166+
&fork.fork_url,
167+
fork.fork_block_number,
168+
&config.cache_config,
169+
)
170+
.await
171+
};
172+
173+
config.update_with_fork_details(fork_details_result).await?
182174
}
183175
Command::ReplayTx(replay_tx) => {
184-
match ForkDetails::from_network_tx(
185-
&replay_tx.network,
176+
let fork_details_result = ForkDetails::from_network_tx(
177+
&replay_tx.fork_url,
186178
replay_tx.tx,
187179
&config.cache_config,
188180
)
189-
.await
190-
{
191-
Ok(fd) => {
192-
// Update the config here
193-
config = config
194-
.with_l1_gas_price(Some(fd.l1_gas_price))
195-
.with_l2_gas_price(Some(fd.l2_fair_gas_price))
196-
.with_l1_pubdata_price(Some(fd.fair_pubdata_price))
197-
.with_price_scale(Some(fd.estimate_gas_price_scale_factor))
198-
.with_gas_limit_scale(Some(fd.estimate_gas_scale_factor))
199-
.with_chain_id(Some(fd.chain_id.as_u64() as u32));
200-
Some(fd)
201-
}
202-
Err(error) => {
203-
tracing::error!("cannot replay: {:?}", error);
204-
return Err(anyhow!(error));
205-
}
206-
}
181+
.await;
182+
183+
config.update_with_fork_details(fork_details_result).await?
207184
}
208185
};
209186

@@ -293,10 +270,16 @@ async fn main() -> anyhow::Result<()> {
293270
let address = H160::from_slice(signer.address().as_ref());
294271
node.set_rich_account(address, config.genesis_balance);
295272
}
273+
// sets legacy rich wallets
296274
for wallet in LEGACY_RICH_WALLETS.iter() {
297275
let address = wallet.0;
298276
node.set_rich_account(H160::from_str(address).unwrap(), config.genesis_balance);
299277
}
278+
// sets additional legacy rich wallets
279+
for wallet in RICH_WALLETS.iter() {
280+
let address = wallet.0;
281+
node.set_rich_account(H160::from_str(address).unwrap(), config.genesis_balance);
282+
}
300283

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

0 commit comments

Comments
 (0)