Skip to content

Commit

Permalink
fix typo, cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonD3 committed Oct 2, 2023
1 parent 06926ee commit 9333993
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub mod bootloader_debug;
pub mod configuration_api;
pub mod console_log;
pub mod deps;
pub mod eth_test;
pub mod filters;
pub mod fork;
pub mod formatter;
Expand All @@ -54,7 +55,6 @@ pub mod resolver;
pub mod system_contracts;
pub mod utils;
pub mod zks;
pub mod eth_test;

mod cache;
mod testing;
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ mod cache;
mod configuration_api;
mod console_log;
mod deps;
mod evm;
mod eth_test;
mod evm;
mod filters;
mod fork;
mod formatter;
Expand Down Expand Up @@ -53,11 +53,11 @@ use futures::{
use jsonrpc_core::MetaIoHandler;
use zksync_basic_types::{L2ChainId, H160, H256};

use crate::eth_test::EthTestNodeNamespaceT;
use crate::{configuration_api::ConfigurationApiNamespace, node::TEST_NODE_NETWORK_ID};
use zksync_core::api_server::web3::backend_jsonrpc::namespaces::{
eth::EthNamespaceT, net::NetNamespaceT, zks::ZksNamespaceT,
};
use crate::eth_test::EthTestNodeNamespaceT;

/// List of wallets (address, private key) that we seed with tokens at start.
pub const RICH_WALLETS: [(&str, &str); 10] = [
Expand Down
44 changes: 29 additions & 15 deletions src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use std::{
sync::{Arc, RwLock},
};

use crate::eth_test::EthTestNodeNamespaceT;
use vm::{
constants::{
BLOCK_GAS_LIMIT, BLOCK_OVERHEAD_PUBDATA, ETH_CALL_GAS_LIMIT, MAX_PUBDATA_PER_BLOCK,
Expand Down Expand Up @@ -66,7 +67,6 @@ use zksync_web3_decl::{
error::Web3Error,
types::{FeeHistory, Filter, FilterChanges},
};
use crate::eth_test::EthTestNodeNamespaceT;

/// Max possible size of an ABI encoded tx (in bytes).
pub const MAX_TX_SIZE: usize = 1_000_000;
Expand Down Expand Up @@ -288,7 +288,7 @@ impl<S: std::fmt::Debug + ForkSource> InMemoryNodeInner<S> {
&self,
storage: StoragePtr<ST>,
) -> (L1BatchEnv, BlockContext) {
// TOOD: is this hack fine?
// TODO: is this hack fine?
let last_l2_block = load_last_l2_block(storage).unwrap_or_else(|| vm::L2Block {
number: 0,
timestamp: 0,
Expand Down Expand Up @@ -438,9 +438,15 @@ impl<S: std::fmt::Debug + ForkSource> InMemoryNodeInner<S> {
let impersonating = if self
.impersonated_accounts
.contains(&l2_tx.common_data.initiator_address)
{ true } else { false };
{
true
} else {
false
};
let system_env = self.create_system_env(
self.system_contracts.contracts_for_fee_estimate(impersonating).clone(),
self.system_contracts
.contracts_for_fee_estimate(impersonating)
.clone(),
execution_mode,
);

Expand Down Expand Up @@ -681,7 +687,7 @@ pub struct InMemoryNode<S> {
impl<S> Clone for InMemoryNode<S> {
fn clone(&self) -> Self {
Self {
inner: self.inner.clone()
inner: self.inner.clone(),
}
}
}
Expand Down Expand Up @@ -2521,7 +2527,9 @@ impl<S: Send + Sync + 'static + ForkSource + std::fmt::Debug> EthNamespaceT for
}
}

impl<S: Send + Sync + 'static + ForkSource + std::fmt::Debug> EthTestNodeNamespaceT for InMemoryNode<S> {
impl<S: Send + Sync + 'static + ForkSource + std::fmt::Debug> EthTestNodeNamespaceT
for InMemoryNode<S>
{
/// Sends a transaction to the L2 network. Can be used for the impersonated account.
///
/// # Arguments
Expand Down Expand Up @@ -2556,7 +2564,10 @@ impl<S: Send + Sync + 'static + ForkSource + std::fmt::Debug> EthTestNodeNamespa
}
};
// v = 27 corresponds to 0
let bytes = tx_req.get_signed_bytes(&PackedEthSignature::from_rsv(&H256::default(), &H256::default(), 0), chain_id);
let bytes = tx_req.get_signed_bytes(
&PackedEthSignature::from_rsv(&H256::default(), &H256::default(), 0),
chain_id,
);
let mut l2_tx: L2Tx = match L2Tx::from_request(tx_req, MAX_TX_SIZE) {
Ok(tx) => tx,
Err(e) => {
Expand All @@ -2570,18 +2581,21 @@ impl<S: Send + Sync + 'static + ForkSource + std::fmt::Debug> EthTestNodeNamespa
return futures::future::err(into_jsrpc_error(Web3Error::InvalidTransactionData(
zksync_types::ethabi::Error::InvalidData,
)))
.boxed();
.boxed();
};

match self.inner.read() {
Ok(reader) => {
if !reader.impersonated_accounts.contains(&l2_tx.common_data.initiator_address) {
return futures::future::err(into_jsrpc_error(Web3Error::InvalidTransactionData(
zksync_types::ethabi::Error::InvalidData,
)))
.boxed()
if !reader
.impersonated_accounts
.contains(&l2_tx.common_data.initiator_address)
{
return futures::future::err(into_jsrpc_error(
Web3Error::InvalidTransactionData(zksync_types::ethabi::Error::InvalidData),
))
.boxed();
}
},
}
Err(_) => {
return futures::future::err(into_jsrpc_error(Web3Error::InternalError)).boxed()
}
Expand All @@ -2595,7 +2609,7 @@ impl<S: Send + Sync + 'static + ForkSource + std::fmt::Debug> EthTestNodeNamespa
error_message,
l2_tx.hash().as_bytes().to_vec(),
)))
.boxed()
.boxed()
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/system_contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ impl SystemContracts {
self.contracts(TxExecutionMode::EstimateFee, impersonating)
}

pub fn contracts(&self, execution_mode: TxExecutionMode, impersonating: bool) -> &BaseSystemContracts {
pub fn contracts(
&self,
execution_mode: TxExecutionMode,
impersonating: bool,
) -> &BaseSystemContracts {
match (execution_mode, impersonating) {
// 'real' contracts, that do all the checks.
(TxExecutionMode::VerifyExecute, false) => &self.baseline_contracts,
Expand Down Expand Up @@ -179,4 +183,4 @@ pub fn baseline_impersonating_contracts(options: &Options) -> BaseSystemContract
Options::Local => read_proved_batch_bootloader_bytecode(),
};
bsc_load_with_bootloader(bootloader_bytecode, options)
}
}

0 comments on commit 9333993

Please sign in to comment.