Skip to content

Commit

Permalink
Merge dev
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonD3 committed Mar 2, 2021
2 parents 880d0dd + 32d05b2 commit 056fee2
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 139 deletions.
4 changes: 4 additions & 0 deletions changelog/core.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ All notable changes to the core components will be documented in this file.

- (`loadtest`): `zksync_fee` has been moved to `[main_wallet]` section from the `[network]` section.
- A special balancer for FeeTicker was replaced with a generic balancer.
- (`eth_client`): `web3` field was made private in `ETHDirectClient`. `testkit` and `loadtest` don't use it directly
now.
- (`api_server`): Make `submit_txs_batch` send only one signature request.

### Added

- (`loadtest`): Added `zksync_fee` option into the `[scenario]` section to set fee for each scenario individually, added
`fee_token` option into the `[main_wallet]` section to set token that is used to pay fees for the main wallet
operations.
- (`eth_client`): Added `get_tx`, `create_contract` methods to `EthereumGateway`, `get_web3_transport` method to
ETHDirectClient.

### Fixed

Expand Down
25 changes: 20 additions & 5 deletions core/lib/eth_client/src/clients/http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use web3::{
},
transports::Http,
types::{
Address, BlockId, BlockNumber, Bytes, Filter, Log, TransactionReceipt, H160, H256, U256,
U64,
Address, BlockId, BlockNumber, Bytes, Filter, Log, Transaction, TransactionId,
TransactionReceipt, H160, H256, U256, U64,
},
Web3,
};
Expand All @@ -33,9 +33,7 @@ pub struct ETHDirectClient<S: EthereumSigner> {
contract: ethabi::Contract,
pub chain_id: u8,
pub gas_price_factor: f64,
// It's public only for testkit
// TODO avoid public (ZKS-376)
pub web3: Web3<Http>,
web3: Web3<Http>,
}

impl<S: EthereumSigner> fmt::Debug for ETHDirectClient<S> {
Expand Down Expand Up @@ -80,6 +78,10 @@ impl<S: EthereumSigner> ETHDirectClient<S> {
self.main_contract_with_address(self.contract_addr)
}

pub fn create_contract(&self, address: Address, contract: ethabi::Contract) -> Contract<Http> {
Contract::new(self.web3.eth(), address, contract)
}

pub async fn pending_nonce(&self) -> Result<U256, anyhow::Error> {
let start = Instant::now();
let count = self
Expand Down Expand Up @@ -393,4 +395,17 @@ impl<S: EthereumSigner> ETHDirectClient<S> {
f.encode_input(&params.into_tokens())
.expect("failed to encode parameters")
}

pub fn get_web3_transport(&self) -> &Http {
self.web3.transport()
}

pub async fn get_tx(&self, hash: H256) -> Result<Option<Transaction>, anyhow::Error> {
let tx = self
.web3
.eth()
.transaction(TransactionId::Hash(hash))
.await?;
Ok(tx)
}
}
15 changes: 14 additions & 1 deletion core/lib/eth_client/src/clients/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use std::collections::{HashMap, HashSet};
use tokio::sync::RwLock;
use web3::contract::tokens::{Detokenize, Tokenize};
use web3::contract::Options;
use web3::types::{BlockId, Filter, Log, U64};
use web3::transports::Http;
use web3::types::{BlockId, Filter, Log, Transaction, U64};

use zksync_types::{TransactionReceipt, H160, H256, U256};

Expand Down Expand Up @@ -232,4 +233,16 @@ impl MockEthereum {
{
todo!()
}

pub fn create_contract(
&self,
_address: Address,
_contract: ethabi::Contract,
) -> web3::contract::Contract<Http> {
unreachable!()
}

pub async fn get_tx(&self, _hash: H256) -> Result<Option<Transaction>, anyhow::Error> {
unreachable!()
}
}
16 changes: 15 additions & 1 deletion core/lib/eth_client/src/clients/multiplexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use ethabi::Contract;
use web3::{
contract::tokens::{Detokenize, Tokenize},
contract::Options,
types::{Address, BlockId, Filter, Log, U64},
transports::Http,
types::{Address, BlockId, Filter, Log, Transaction, U64},
};

use zksync_eth_signer::PrivateKeySigner;
Expand Down Expand Up @@ -54,6 +55,15 @@ impl MultiplexerEthereumClient {
self
}

pub fn create_contract(
&self,
address: Address,
contract: ethabi::Contract,
) -> web3::contract::Contract<Http> {
let client = self.clients.first().expect("Should be at least one client");
client.1.create_contract(address, contract)
}

pub async fn pending_nonce(&self) -> Result<U256, anyhow::Error> {
multiple_call!(self, pending_nonce());
}
Expand Down Expand Up @@ -182,4 +192,8 @@ impl MultiplexerEthereumClient {
let (_, client) = self.clients.first().expect("Should be exactly one client");
client.encode_tx_data(func, params)
}

pub async fn get_tx(&self, hash: H256) -> Result<Option<Transaction>, anyhow::Error> {
multiple_call!(self, get_tx(hash));
}
}
17 changes: 15 additions & 2 deletions core/lib/eth_client/src/ethereum_gateway.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use web3::contract::tokens::{Detokenize, Tokenize};
use web3::contract::Options;
use web3::types::{Address, BlockId, Filter, Log, U64};
use web3::contract::{Contract, Options};
use web3::transports::Http;
use web3::types::{Address, BlockId, Filter, Log, Transaction, U64};

use std::fmt::Debug;
use zksync_config::ZkSyncConfig;
Expand Down Expand Up @@ -250,6 +251,18 @@ impl EthereumGateway {
}
}

pub fn create_contract(&self, address: Address, contract: ethabi::Contract) -> Contract<Http> {
match self {
EthereumGateway::Multiplexed(c) => c.create_contract(address, contract),
EthereumGateway::Direct(c) => c.create_contract(address, contract),
EthereumGateway::Mock(c) => c.create_contract(address, contract),
}
}

pub async fn get_tx(&self, hash: H256) -> anyhow::Result<Option<Transaction>> {
delegate_call!(self.get_tx(hash))
}

pub fn get_mut_mock(&mut self) -> Option<&mut MockEthereum> {
match self {
EthereumGateway::Mock(m) => Some(m),
Expand Down
14 changes: 5 additions & 9 deletions core/tests/loadtest/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ use zksync::{
provider::Provider,
types::BlockStatus,
utils::{biguint_to_u256, closest_packable_fee_amount, u256_to_biguint},
web3::{
contract::{Contract, Options},
types::H256,
},
web3::{contract::Options, types::H256},
EthereumProvider, Network, RpcProvider, Wallet,
};
use zksync_eth_signer::PrivateKeySigner;
Expand Down Expand Up @@ -172,11 +169,10 @@ impl MainWallet {
.resolve(token_name.into())
.ok_or(ClientError::UnknownToken)?;

let contract = Contract::new(
self.eth_provider.client().web3.eth(),
token.address,
ierc20_contract(),
);
let contract = self
.eth_provider
.client()
.create_contract(token.address, ierc20_contract());

let balance = contract
.query("balanceOf", self.address(), None, Options::default(), None)
Expand Down
Loading

0 comments on commit 056fee2

Please sign in to comment.