Skip to content

Commit

Permalink
feat: Port test-node to most recent core revision (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
popzxc authored May 16, 2024
1 parent c62ac0c commit 7ed3e5d
Show file tree
Hide file tree
Showing 9 changed files with 284 additions and 1,689 deletions.
1,868 changes: 225 additions & 1,643 deletions Cargo.lock

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ categories = ["cryptography"]
publish = false # We don't want to publish our binaries.

[dependencies]
zksync_basic_types = { git = "https://github.com/matter-labs/zksync-era.git", rev = "e9d41a6927f832b5b3eb2a93e30c54d4bf090fe3" }
zksync_core = { git = "https://github.com/matter-labs/zksync-era.git", rev = "e9d41a6927f832b5b3eb2a93e30c54d4bf090fe3" }
multivm = { git = "https://github.com/matter-labs/zksync-era.git", rev = "e9d41a6927f832b5b3eb2a93e30c54d4bf090fe3" }
zksync_contracts = { git = "https://github.com/matter-labs/zksync-era.git", rev = "e9d41a6927f832b5b3eb2a93e30c54d4bf090fe3" }
zksync_types = { git = "https://github.com/matter-labs/zksync-era.git", rev = "e9d41a6927f832b5b3eb2a93e30c54d4bf090fe3" }
zksync_utils = { git = "https://github.com/matter-labs/zksync-era.git", rev = "e9d41a6927f832b5b3eb2a93e30c54d4bf090fe3" }
zksync_state = { git = "https://github.com/matter-labs/zksync-era.git", rev = "e9d41a6927f832b5b3eb2a93e30c54d4bf090fe3" }
zksync_web3_decl = { git = "https://github.com/matter-labs/zksync-era.git", rev = "e9d41a6927f832b5b3eb2a93e30c54d4bf090fe3" }
zksync_basic_types = { git = "https://github.com/matter-labs/zksync-era.git", rev = "e10bbdd1e863962552f37e768ae6af649353e4ea" }
zksync_node_fee_model = { git = "https://github.com/matter-labs/zksync-era.git", rev = "e10bbdd1e863962552f37e768ae6af649353e4ea" }
multivm = { git = "https://github.com/matter-labs/zksync-era.git", rev = "e10bbdd1e863962552f37e768ae6af649353e4ea" }
zksync_contracts = { git = "https://github.com/matter-labs/zksync-era.git", rev = "e10bbdd1e863962552f37e768ae6af649353e4ea" }
zksync_types = { git = "https://github.com/matter-labs/zksync-era.git", rev = "e10bbdd1e863962552f37e768ae6af649353e4ea" }
zksync_utils = { git = "https://github.com/matter-labs/zksync-era.git", rev = "e10bbdd1e863962552f37e768ae6af649353e4ea" }
zksync_state = { git = "https://github.com/matter-labs/zksync-era.git", rev = "e10bbdd1e863962552f37e768ae6af649353e4ea" }
zksync_web3_decl = { git = "https://github.com/matter-labs/zksync-era.git", rev = "e10bbdd1e863962552f37e768ae6af649353e4ea", features = [ "server", "client" ] }
sha3 = "0.10.6"


Expand Down Expand Up @@ -63,4 +63,4 @@ ethers = { version = "2.0.4", features = ["rustls"] }
sha3 = { git = "https://github.com/RustCrypto/hashes", tag = "sha3-v0.10.6" }

[profile.dev]
debug = 0
debug = 0
19 changes: 12 additions & 7 deletions src/fork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::{
collections::HashMap,
convert::{TryFrom, TryInto},
future::Future,
str::FromStr,
sync::{Arc, RwLock},
};

Expand All @@ -19,16 +20,18 @@ use zksync_types::{
TransactionDetails, TransactionVariant,
},
l2::L2Tx,
url::SensitiveUrl,
ProtocolVersionId, StorageKey,
};

use zksync_state::ReadStorage;
use zksync_utils::{bytecode::hash_bytecode, h256_to_u256};

use zksync_web3_decl::{
jsonrpsee::http_client::HttpClient, namespaces::EthNamespaceClient, types::Index,
client::{Client, L2},
namespaces::ZksNamespaceClient,
};
use zksync_web3_decl::{jsonrpsee::http_client::HttpClientBuilder, namespaces::ZksNamespaceClient};
use zksync_web3_decl::{namespaces::EthNamespaceClient, types::Index};

use crate::system_contracts;
use crate::{cache::CacheConfig, node::TEST_NODE_NETWORK_ID};
Expand Down Expand Up @@ -354,7 +357,7 @@ pub fn supported_versions_to_string() -> String {
impl ForkDetails<HttpForkSource> {
pub async fn from_url_and_miniblock_and_chain(
url: &str,
client: HttpClient,
client: Client<L2>,
miniblock: u64,
chain_id: Option<L2ChainId>,
cache_config: CacheConfig,
Expand Down Expand Up @@ -447,17 +450,19 @@ impl ForkDetails<HttpForkSource> {

impl<S: ForkSource> ForkDetails<S> {
/// Return URL and HTTP client for a given fork name.
pub fn fork_to_url_and_client(fork: &str) -> (&str, HttpClient) {
pub fn fork_to_url_and_client(fork: &str) -> (&str, Client<L2>) {
let url = match fork {
"mainnet" => "https://mainnet.era.zksync.io:443",
"sepolia-testnet" => "https://sepolia.era.zksync.dev:443",
"goerli-testnet" => "https://testnet.era.zksync.dev:443",
_ => fork,
};

let client = HttpClientBuilder::default()
.build(url)
.expect("Unable to create a client for fork");
let parsed_url = SensitiveUrl::from_str(url)
.unwrap_or_else(|_| panic!("Unable to parse client URL: {}", &url));
let client = Client::http(parsed_url)
.unwrap_or_else(|_| panic!("Unable to create a client for fork: {}", &url))
.build();

(url, client)
}
Expand Down
22 changes: 15 additions & 7 deletions src/http_fork_source.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
use std::sync::{Arc, RwLock};
use std::{
str::FromStr,
sync::{Arc, RwLock},
};

use crate::{
cache::{Cache, CacheConfig},
fork::{block_on, ForkSource},
};
use eyre::Context;
use zksync_basic_types::{H256, U256};
use zksync_types::api::{BridgeAddresses, Transaction};
use zksync_web3_decl::types::Token;
use zksync_types::{
api::{BridgeAddresses, Transaction},
url::SensitiveUrl,
};
use zksync_web3_decl::{
jsonrpsee::http_client::{HttpClient, HttpClientBuilder},
client::Client,
namespaces::{EthNamespaceClient, ZksNamespaceClient},
types::Index,
};
use zksync_web3_decl::{client::L2, types::Token};

#[derive(Debug, Clone)]
/// Fork source that gets the data via HTTP requests.
Expand All @@ -31,10 +37,12 @@ impl HttpForkSource {
}
}

pub fn create_client(&self) -> HttpClient {
HttpClientBuilder::default()
.build(self.fork_url.clone())
pub fn create_client(&self) -> Client<L2> {
let url = SensitiveUrl::from_str(&self.fork_url)
.unwrap_or_else(|_| panic!("Unable to parse client URL: {}", &self.fork_url));
Client::http(url)
.unwrap_or_else(|_| panic!("Unable to create a client for fork: {}", self.fork_url))
.build()
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/namespaces/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use jsonrpc_derive::rpc;
use zksync_types::{
api::{BlockIdVariant, BlockNumber, Transaction, TransactionReceipt, TransactionVariant},
transaction_request::CallRequest,
web3::types::{FeeHistory, Index, SyncState},
Address, Bytes, H256, U256, U64,
web3::{Bytes, FeeHistory, Index, SyncState},
Address, H256, U256, U64,
};
use zksync_web3_decl::types::{Block, Filter, FilterChanges, Log};

Expand Down
28 changes: 14 additions & 14 deletions src/node/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use futures::FutureExt;
use itertools::Itertools;
use multivm::interface::{ExecutionResult, TxExecutionMode};
use multivm::vm_latest::constants::ETH_CALL_GAS_LIMIT;
use zksync_basic_types::{web3, AccountTreeId, Address, Bytes, H160, H256, U256, U64};
use zksync_basic_types::{
web3::{self, Bytes},
AccountTreeId, Address, H160, H256, U256, U64,
};
use zksync_state::ReadStorage;
use zksync_types::{
api::{Block, BlockIdVariant, BlockNumber, TransactionVariant},
Expand Down Expand Up @@ -58,7 +61,7 @@ impl<S: ForkSource + std::fmt::Debug + Clone + Send + Sync + 'static> EthNamespa
&self,
req: zksync_types::transaction_request::CallRequest,
_block: Option<BlockIdVariant>,
) -> RpcResult<zksync_basic_types::Bytes> {
) -> RpcResult<Bytes> {
match L2Tx::from_request(req.into(), MAX_TX_SIZE) {
Ok(mut tx) => {
tx.common_data.fee.gas_limit = ETH_CALL_GAS_LIMIT.into();
Expand Down Expand Up @@ -244,12 +247,12 @@ impl<S: ForkSource + std::fmt::Debug + Clone + Send + Sync + 'static> EthNamespa
/// # Returns
///
/// A `BoxFuture` containing the result of the operation, which is a `jsonrpc_core::Result` containing
/// the code as a `zksync_basic_types::Bytes` object.
/// the code as a `Bytes` object.
fn get_code(
&self,
address: zksync_basic_types::Address,
_block: Option<BlockIdVariant>,
) -> RpcResult<zksync_basic_types::Bytes> {
) -> RpcResult<Bytes> {
let inner = self.get_inner().clone();

Box::pin(async move {
Expand Down Expand Up @@ -349,10 +352,7 @@ impl<S: ForkSource + std::fmt::Debug + Clone + Send + Sync + 'static> EthNamespa
/// # Returns
///
/// A future that resolves to the hash of the transaction if successful, or an error if the transaction is invalid or execution fails.
fn send_raw_transaction(
&self,
tx_bytes: zksync_basic_types::Bytes,
) -> RpcResult<zksync_basic_types::H256> {
fn send_raw_transaction(&self, tx_bytes: Bytes) -> RpcResult<zksync_basic_types::H256> {
let chain_id = match self.get_inner().read() {
Ok(reader) => reader.fork_storage.chain_id,
Err(_) => {
Expand Down Expand Up @@ -1105,7 +1105,7 @@ impl<S: ForkSource + std::fmt::Debug + Clone + Send + Sync + 'static> EthNamespa
fn get_transaction_by_block_hash_and_index(
&self,
block_hash: zksync_basic_types::H256,
index: zksync_basic_types::web3::types::Index,
index: zksync_basic_types::web3::Index,
) -> RpcResult<Option<zksync_types::api::Transaction>> {
let inner = self.get_inner().clone();

Expand Down Expand Up @@ -1172,7 +1172,7 @@ impl<S: ForkSource + std::fmt::Debug + Clone + Send + Sync + 'static> EthNamespa
fn get_transaction_by_block_number_and_index(
&self,
block_number: BlockNumber,
index: zksync_basic_types::web3::types::Index,
index: zksync_basic_types::web3::Index,
) -> RpcResult<Option<zksync_types::api::Transaction>> {
let inner = self.get_inner().clone();

Expand Down Expand Up @@ -1347,7 +1347,7 @@ impl<S: ForkSource + std::fmt::Debug + Clone + Send + Sync + 'static> EthNamespa
base_fee_per_gas.push(*base_fee_per_gas.last().unwrap());

Ok(FeeHistory {
oldest_block: web3::types::BlockNumber::Number(oldest_block.into()),
oldest_block: web3::BlockNumber::Number(oldest_block.into()),
base_fee_per_gas,
gas_used_ratio,
reward,
Expand Down Expand Up @@ -1509,7 +1509,7 @@ mod tests {

assert_eq!(
fee_history.oldest_block,
web3::types::BlockNumber::Number(U64::from(0))
web3::BlockNumber::Number(U64::from(0))
);
assert_eq!(
fee_history.base_fee_per_gas,
Expand All @@ -1530,7 +1530,7 @@ mod tests {

assert_eq!(
fee_history.oldest_block,
web3::types::BlockNumber::Number(U64::from(0))
web3::BlockNumber::Number(U64::from(0))
);
assert_eq!(
fee_history.base_fee_per_gas,
Expand Down Expand Up @@ -1561,7 +1561,7 @@ mod tests {
assert_eq!(latest_block, U64::from(2));
assert_eq!(
fee_history.oldest_block,
web3::types::BlockNumber::Number(U64::from(1))
web3::BlockNumber::Number(U64::from(1))
);
assert_eq!(
fee_history.base_fee_per_gas,
Expand Down
2 changes: 1 addition & 1 deletion src/node/fee_model.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::fmt::Debug;
use zksync_core::fee_model::BatchFeeModelInputProvider;
use zksync_node_fee_model::BatchFeeModelInputProvider;
use zksync_types::fee_model::{FeeModelConfigV2, FeeParams, FeeParamsV2};
use zksync_types::L1_GAS_PER_PUBDATA_BYTE;

Expand Down
8 changes: 4 additions & 4 deletions src/node/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ use multivm::{
};
use std::convert::TryInto;
use zksync_basic_types::{
web3::signing::keccak256, AccountTreeId, Address, Bytes, L1BatchNumber, L2BlockNumber, H160,
H256, U256, U64,
web3::keccak256, web3::Bytes, AccountTreeId, Address, L1BatchNumber, L2BlockNumber, H160, H256,
U256, U64,
};
use zksync_contracts::BaseSystemContracts;
use zksync_core::fee_model::BatchFeeModelInputProvider;
use zksync_node_fee_model::BatchFeeModelInputProvider;
use zksync_state::{ReadStorage, StoragePtr, WriteStorage};
use zksync_types::{
api::{Block, DebugCall, Log, TransactionReceipt, TransactionVariant},
Expand Down Expand Up @@ -1080,7 +1080,7 @@ impl<S: ForkSource + std::fmt::Debug + Clone> InMemoryNode<S> {
match &tx_result.result {
ExecutionResult::Success { output } => {
tracing::info!("Call: {}", "SUCCESS".green());
let output_bytes = zksync_basic_types::Bytes::from(output.clone());
let output_bytes = zksync_basic_types::web3::Bytes::from(output.clone());
tracing::info!("Output: {}", serde_json::to_string(&output_bytes).unwrap());
}
ExecutionResult::Revert { output } => {
Expand Down
4 changes: 2 additions & 2 deletions src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -781,15 +781,15 @@ impl ForkSource for &ExternalStorage {
fn get_transaction_by_block_hash_and_index(
&self,
_block_hash: H256,
_index: zksync_basic_types::web3::types::Index,
_index: zksync_basic_types::web3::Index,
) -> eyre::Result<Option<zksync_types::api::Transaction>> {
todo!()
}

fn get_transaction_by_block_number_and_index(
&self,
_block_number: zksync_types::api::BlockNumber,
_index: zksync_basic_types::web3::types::Index,
_index: zksync_basic_types::web3::Index,
) -> eyre::Result<Option<zksync_types::api::Transaction>> {
todo!()
}
Expand Down

0 comments on commit 7ed3e5d

Please sign in to comment.