Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/matter-labs/anvil-zksync in…
Browse files Browse the repository at this point in the history
…to anvil-set-chain-id
  • Loading branch information
Romsters committed Dec 10, 2024
2 parents b4980c3 + 0903206 commit 2ceac7b
Show file tree
Hide file tree
Showing 106 changed files with 776 additions and 1,300 deletions.
832 changes: 67 additions & 765 deletions Cargo.lock

Large diffs are not rendered by default.

93 changes: 46 additions & 47 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,80 +1,79 @@
[package]
name = "anvil-zksync"
[workspace]
members = [
"crates/cli",
"crates/config",
"crates/core",
]
resolver = "2"

[profile.dev]
debug = 0

[workspace.package]
version = "0.2.1"
edition = "2018"
edition = "2021"
authors = ["The Matter Labs Team <[email protected]>"]
homepage = "https://zksync.io/"
repository = "https://github.com/matter-labs/anvil-zksync"
license = "MIT OR Apache-2.0"
keywords = ["blockchain", "zksync"]
categories = ["cryptography"]
publish = false # We don't want to publish our binaries.

[dependencies]
[workspace.dependencies]
#########################
# ZKsync dependencies #
#########################
zksync_multivm = { git = "https://github.com/matter-labs/zksync-era.git", rev = "6c034f6e180cc92e99766f14c8840c90efa56cec" }
zksync_contracts = { git = "https://github.com/matter-labs/zksync-era.git", rev = "6c034f6e180cc92e99766f14c8840c90efa56cec" }
zksync_types = { git = "https://github.com/matter-labs/zksync-era.git", rev = "6c034f6e180cc92e99766f14c8840c90efa56cec" }
zksync_utils = { git = "https://github.com/matter-labs/zksync-era.git", rev = "6c034f6e180cc92e99766f14c8840c90efa56cec" }
zksync_vm_interface = { git = "https://github.com/matter-labs/zksync-era.git", rev = "6c034f6e180cc92e99766f14c8840c90efa56cec" }
zksync_web3_decl = { git = "https://github.com/matter-labs/zksync-era.git", rev = "6c034f6e180cc92e99766f14c8840c90efa56cec", features = [
"server",
] }

# alloy
#########################
# External dependencies #
#########################
anyhow = "1.0"
alloy-signer-local = { version = "0.5.4", features = ["mnemonic"] }
alloy-signer = { version = "0.5.4", default-features = false }

openssl-sys = { version = "0.9", features = ["vendored"] }

anyhow = "1.0"
tokio = { version = "1", features = ["time", "rt"] }
bigdecimal = { version = "0.3.0", features = ["serde"] }
chrono = { version = "0.4.31", default-features = false }
clap = { version = "4.2.4", features = ["derive", "env"] }
colored = "2"
ethabi = "16.0.0"
eyre = "0.6"
flate2 = "1.0"
futures = { version = "0.3", features = ["compat"] }
once_cell = "1.7"

hex = "0.4"
indexmap = "2.0.1"
itertools = "0.13"
jsonrpc-http-server = { git = "https://github.com/matter-labs/jsonrpc.git", branch = "master" }
jsonrpc-core = { git = "https://github.com/matter-labs/jsonrpc.git", branch = "master" }
jsonrpc-core-client = { git = "https://github.com/matter-labs/jsonrpc.git", branch = "master" }
jsonrpc-derive = { git = "https://github.com/matter-labs/jsonrpc.git", branch = "master" }

clap = { version = "4.2.4", features = ["derive", "env"] }
lazy_static = "1.4"
once_cell = "1.7"
rand = "0.8"
reqwest = { version = "0.11", features = ["blocking"] }
rustc-hash = "1.1.0"
serde = { version = "1.0", features = ["derive"] }
tracing = { version = "0.1.26", features = ["log"] }
serde_json = "1.0"
thiserror = "1"
time = "0.3.36"
tokio = { version = "1", features = ["full", "tracing"] }
tracing = { version = "0.1", features = ["log"] }
tracing-subscriber = { version = "0.3", features = [
"fmt",
"env-filter",
"time",
"json",
"local-time",
] }
colored = "2.0"
lazy_static = "1.4"
eyre = "0.6"
serde_json = "1.0.67"
bigdecimal = { version = "0.3.0", features = ["serde"] }
hex = "0.4"
ethabi = "16.0.0"
itertools = "0.10.5"
rustc-hash = "1.1.0"
indexmap = "2.0.1"
chrono = { version = "0.4.31", default-features = false }
time = "0.3.36"
rand = "0.8"
flate2 = "1.0"
thiserror = "1"

[dev-dependencies]
httptest = "0.15.4"
tempdir = "0.3.7"
maplit = "1.0.2"
zksync-web3-rs = "0.1.1"
ethers = { version = "2.0.4", features = ["rustls"] }
jsonschema = "0.26.0"
schemars = "0.8.21"
openrpc-types = "0.4.0"
alloy = { version = "0.5", features = ["full"] }
test-log = "0.2.16"
fs2 = "0.4.3"
test-case = "3.3.1"

[profile.dev]
debug = 0
#########################
# Local dependencies #
#########################
anvil_zksync_config = { path = "crates/config" }
anvil_zksync_core = { path = "crates/core" }
35 changes: 35 additions & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[package]
name = "anvil-zksync" # Compatible with the legacy bin crate name
description = "anvil-zksync CLI"
version.workspace = true
edition.workspace = true
authors.workspace = true
homepage.workspace = true
repository.workspace = true
license.workspace = true
keywords.workspace = true
categories.workspace = true

[dependencies]
anvil_zksync_core.workspace = true
anvil_zksync_config.workspace = true

zksync_types.workspace = true
zksync_web3_decl.workspace = true

alloy-signer-local.workspace = true
anyhow.workspace = true
clap.workspace = true
colored.workspace = true
eyre.workspace = true
hex.workspace = true
itertools.workspace = true
jsonrpc-core.workspace = true
jsonrpc-http-server.workspace = true
futures.workspace = true
rand.workspace = true
serde.workspace = true
serde_json.workspace = true
tokio.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fs;

use crate::fork::ForkSource;
use crate::node::InMemoryNode;
use anvil_zksync_core::fork::ForkSource;
use anvil_zksync_core::node::InMemoryNode;
use eyre::Context;
use hex::FromHex;
use serde::Deserialize;
Expand Down
30 changes: 14 additions & 16 deletions src/config/cli.rs → crates/cli/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
use std::env;
use std::time::Duration;

use clap::{arg, command, Parser, Subcommand};
use rand::{rngs::StdRng, SeedableRng};
use zksync_types::{H256, U256};

use super::DEFAULT_DISK_CACHE_DIR;
use crate::config::constants::{DEFAULT_MNEMONIC, TEST_NODE_NETWORK_ID};
use crate::config::{
AccountGenerator, CacheConfig, CacheType, Genesis, ShowCalls, ShowGasDetails, ShowStorageLogs,
ShowVMDetails, TestNodeConfig,
};
use crate::observability::LogLevel;
use crate::system_contracts::Options as SystemContractsOptions;
use crate::utils::parse_genesis_file;
use alloy_signer_local::coins_bip39::{English, Mnemonic};
use anvil_zksync_config::constants::{
DEFAULT_DISK_CACHE_DIR, DEFAULT_MNEMONIC, TEST_NODE_NETWORK_ID,
};
use anvil_zksync_config::types::{
AccountGenerator, CacheConfig, CacheType, Genesis, LogLevel, ShowCalls, ShowGasDetails,
ShowStorageLogs, ShowVMDetails, SystemContractsOptions,
};
use anvil_zksync_config::TestNodeConfig;
use clap::{arg, command, Parser, Subcommand};
use rand::{rngs::StdRng, SeedableRng};
use std::env;
use std::net::IpAddr;
use std::time::Duration;
use zksync_types::{H256, U256};

#[derive(Debug, Parser, Clone)]
#[command(
Expand Down Expand Up @@ -433,7 +431,7 @@ fn duration_from_secs_f64(s: &str) -> Result<Duration, String> {

#[cfg(test)]
mod tests {
use crate::config::cli::Cli;
use super::Cli;
use clap::Parser;
use std::{
env,
Expand Down
File renamed without changes.
92 changes: 38 additions & 54 deletions src/main.rs → crates/cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,62 +1,46 @@
use crate::observability::Observability;
use anvil_zksync::config::constants::DEFAULT_L1_GAS_PRICE;
use anyhow::anyhow;
use bytecode_override::override_bytecodes;
use clap::Parser;
use config::cli::{Cli, Command};
use config::constants::{
use crate::bytecode_override::override_bytecodes;
use crate::cli::{Cli, Command};
use crate::utils::update_with_fork_details;
use anvil_zksync_config::constants::{
DEFAULT_ESTIMATE_GAS_PRICE_SCALE_FACTOR, DEFAULT_ESTIMATE_GAS_SCALE_FACTOR,
DEFAULT_FAIR_PUBDATA_PRICE, DEFAULT_L2_GAS_PRICE, LEGACY_RICH_WALLETS, RICH_WALLETS,
TEST_NODE_NETWORK_ID,
DEFAULT_FAIR_PUBDATA_PRICE, DEFAULT_L1_GAS_PRICE, DEFAULT_L2_GAS_PRICE, LEGACY_RICH_WALLETS,
RICH_WALLETS, TEST_NODE_NETWORK_ID,
};
use config::ForkPrintInfo;
use fork::{ForkDetails, ForkSource};
use http_fork_source::HttpForkSource;
use logging_middleware::LoggingMiddleware;
use tracing_subscriber::filter::LevelFilter;

mod bootloader_debug;
mod bytecode_override;
mod cache;
mod config;
mod console_log;
mod deps;
mod filters;
mod fork;
mod formatter;
mod http_fork_source;
mod logging_middleware;
mod namespaces;
mod node;
mod observability;
mod resolver;
mod system_contracts;
mod testing;
mod utils;

use node::InMemoryNode;
use std::fs::File;
use std::{env, net::SocketAddr, str::FromStr};
use zksync_types::fee_model::{FeeModelConfigV2, FeeParams};
use zksync_web3_decl::namespaces::ZksNamespaceClient;

use anvil_zksync_config::types::SystemContractsOptions;
use anvil_zksync_config::ForkPrintInfo;
use anvil_zksync_core::fork::{ForkDetails, ForkSource};
use anvil_zksync_core::http_fork_source::HttpForkSource;
use anvil_zksync_core::namespaces::{
AnvilNamespaceT, ConfigurationApiNamespaceT, DebugNamespaceT, EthNamespaceT,
EthTestNodeNamespaceT, EvmNamespaceT, HardhatNamespaceT, NetNamespaceT, Web3NamespaceT,
ZksNamespaceT,
};
use anvil_zksync_core::node::{
BlockProducer, BlockSealer, BlockSealerMode, ImpersonationManager, InMemoryNode,
TimestampManager, TxPool,
};
use anvil_zksync_core::observability::Observability;
use anvil_zksync_core::system_contracts::SystemContracts;
use anyhow::anyhow;
use clap::Parser;
use futures::{
channel::oneshot,
future::{self},
FutureExt,
};
use jsonrpc_core::MetaIoHandler;
use logging_middleware::LoggingMiddleware;
use std::fs::File;
use std::{env, net::SocketAddr, str::FromStr};
use tracing_subscriber::filter::LevelFilter;
use zksync_types::fee_model::{FeeModelConfigV2, FeeParams};
use zksync_types::H160;
use zksync_web3_decl::namespaces::ZksNamespaceClient;

use crate::namespaces::{
AnvilNamespaceT, ConfigurationApiNamespaceT, DebugNamespaceT, EthNamespaceT,
EthTestNodeNamespaceT, EvmNamespaceT, HardhatNamespaceT, NetNamespaceT, Web3NamespaceT,
ZksNamespaceT,
};
use crate::node::{
BlockProducer, BlockSealer, BlockSealerMode, ImpersonationManager, TimestampManager, TxPool,
};
use crate::system_contracts::SystemContracts;
mod bytecode_override;
mod cli;
mod logging_middleware;
mod utils;

#[allow(clippy::too_many_arguments)]
async fn build_json_http<
Expand Down Expand Up @@ -103,7 +87,7 @@ async fn build_json_http<
let server = builder.start_http(&addr).unwrap();

server.wait();
let _ = sender;
drop(sender);
});

tokio::spawn(recv.map(drop))
Expand Down Expand Up @@ -212,7 +196,7 @@ async fn main() -> anyhow::Result<()> {
.await
};

config.update_with_fork_details(fork_details_result).await?
update_with_fork_details(&mut config, fork_details_result).await?
}
Command::ReplayTx(replay_tx) => {
let fork_details_result = ForkDetails::from_network_tx(
Expand All @@ -222,7 +206,7 @@ async fn main() -> anyhow::Result<()> {
)
.await;

config.update_with_fork_details(fork_details_result).await?
update_with_fork_details(&mut config, fork_details_result).await?
}
};

Expand All @@ -249,7 +233,7 @@ async fn main() -> anyhow::Result<()> {

if matches!(
config.system_contracts_options,
system_contracts::Options::Local
SystemContractsOptions::Local
) {
if let Some(path) = env::var_os("ZKSYNC_HOME") {
tracing::info!("+++++ Reading local contracts from {:?} +++++", path);
Expand Down Expand Up @@ -292,7 +276,7 @@ async fn main() -> anyhow::Result<()> {
} else if let Some(block_time) = config.block_time {
BlockSealerMode::fixed_time(config.max_transactions, block_time)
} else {
BlockSealerMode::immediate(config.max_transactions)
BlockSealerMode::immediate(config.max_transactions, pool.add_tx_listener())
};
let block_sealer = BlockSealer::new(sealing_mode);

Expand Down
Loading

0 comments on commit 2ceac7b

Please sign in to comment.