From b0154c50c3d6e089c790e1c75d875aef32f95e4b Mon Sep 17 00:00:00 2001 From: Danil Lugovskoy Date: Mon, 22 Mar 2021 16:46:21 +0300 Subject: [PATCH 1/7] Remove tGLM crunch --- .../src/api_server/rest/v1/tokens.rs | 37 ------------------- .../src/api_server/rpc_server/rpc_impl.rs | 17 --------- .../src/api_server/rpc_server/types.rs | 14 ------- .../zksync_api/src/bin/dev-ticker-server.rs | 3 ++ core/bin/zksync_api/src/signature_checker.rs | 12 ------ .../zksync_api/src/utils/token_db_cache.rs | 25 +------------ sdk/zksync-rs/tests/integration.rs | 18 --------- 7 files changed, 4 insertions(+), 122 deletions(-) diff --git a/core/bin/zksync_api/src/api_server/rest/v1/tokens.rs b/core/bin/zksync_api/src/api_server/rest/v1/tokens.rs index 84057acddc..343b94a26d 100644 --- a/core/bin/zksync_api/src/api_server/rest/v1/tokens.rs +++ b/core/bin/zksync_api/src/api_server/rest/v1/tokens.rs @@ -287,41 +287,4 @@ mod tests { server.stop().await; Ok(()) } - - // Test special case for Golem: tGLM token name should be alias for the GNT. - // By the way, since `TokenDBCache` is shared between this API implementation - // and the old RPC code, there is no need to write a test for the old implementation. - // - // TODO: Remove this case after Golem update [ZKS-173] - #[actix_rt::test] - #[cfg_attr( - not(feature = "api_test"), - ignore = "Use `zk test rust-api` command to perform this test" - )] - async fn gnt_as_tglm_alias() -> anyhow::Result<()> { - let cfg = TestServerConfig::default(); - cfg.fill_database().await?; - - let fee_ticker = dummy_fee_ticker(&[]); - let (client, server) = cfg.start_server(move |cfg| { - api_scope(cfg.pool.clone(), TokenDBCache::new(), fee_ticker.clone()) - }); - - // Get Golem token as GNT. - let golem_gnt = client - .token_by_id(&TokenLike::from("GNT")) - .await? - .expect("Golem token should be exist"); - // Get Golem token as GMT. - let golem_tglm = client - .token_by_id(&TokenLike::from("tGLM")) - .await? - .expect("Golem token should be exist"); - // Check that GNT is alias to GMT. - assert_eq!(golem_gnt, golem_tglm); - assert_eq!(*golem_gnt.id, 16); - - server.stop().await; - Ok(()) - } } diff --git a/core/bin/zksync_api/src/api_server/rpc_server/rpc_impl.rs b/core/bin/zksync_api/src/api_server/rpc_server/rpc_impl.rs index a34939d539..fbd2da9bd6 100644 --- a/core/bin/zksync_api/src/api_server/rpc_server/rpc_impl.rs +++ b/core/bin/zksync_api/src/api_server/rpc_server/rpc_impl.rs @@ -161,20 +161,10 @@ impl RpcApp { Error::internal_error() })?; - // HACK: Special case for the Golem: - // - // Currently, their token on Rinkeby is called GNT, but it's being renamed to the tGLM. - // - // TODO: Remove this case after Golem update [ZKS-173] let mut has_gnt = None; let mut result: HashMap<_, _> = tokens .drain() .map(|(id, token)| { - // TODO: Remove this case after Golem update [ZKS-173] - if token.symbol == "GNT" { - has_gnt = Some(token.clone()); - } - if *id == 0 { ("ETH".to_string(), token) } else { @@ -183,13 +173,6 @@ impl RpcApp { }) .collect(); - // So if we have `GNT` token in response we should also add `GLM` alias. - // TODO: Remove this case after Golem update [ZKS-173] - if let Some(mut token) = has_gnt { - token.symbol = "tGLM".to_string(); - result.insert(token.symbol.clone(), token); - } - metrics::histogram!("api.rpc.tokens", start.elapsed()); Ok(result) } diff --git a/core/bin/zksync_api/src/api_server/rpc_server/types.rs b/core/bin/zksync_api/src/api_server/rpc_server/types.rs index c3ed54bdcb..5cddc4b8e5 100644 --- a/core/bin/zksync_api/src/api_server/rpc_server/types.rs +++ b/core/bin/zksync_api/src/api_server/rpc_server/types.rs @@ -47,11 +47,6 @@ impl ResponseAccountState { // so here we use `HashMap` as well for the consistency. let mut balances: HashMap<_, _> = inner.balances.into_iter().collect(); - // TODO: Remove this code after Golem update [ZKS-173] - if let Some(balance) = balances.get("GNT").cloned() { - balances.insert("tGLM".to_string(), balance); - } - Ok(Self { balances, nonce: inner.nonce, @@ -104,15 +99,6 @@ impl DepositingAccountBalances { let expected_accept_block = op.received_on_block + pending_ops.confirmations_for_eth_event; - // TODO: Remove this code after Golem update [ZKS-173] - if token_symbol == "GNT" { - let balance = balances - .entry("tGLM".to_string()) - .or_insert_with(DepositingFunds::default); - - balance.amount += BigUint::from(op.amount); - } - let balance = balances .entry(token_symbol) .or_insert_with(DepositingFunds::default); diff --git a/core/bin/zksync_api/src/bin/dev-ticker-server.rs b/core/bin/zksync_api/src/bin/dev-ticker-server.rs index 9a157a1025..8131837e8a 100644 --- a/core/bin/zksync_api/src/bin/dev-ticker-server.rs +++ b/core/bin/zksync_api/src/bin/dev-ticker-server.rs @@ -57,6 +57,7 @@ async fn handle_coinmarketcap_token_price_query( "wBTC" => BigDecimal::from(9000), "BAT" => BigDecimal::try_from(0.2).unwrap(), "DAI" => BigDecimal::from(1), + "tGLM" => BigDecimal::from(1), _ => BigDecimal::from(0), }; let random_multiplier = thread_rng().gen_range(0.9, 1.1); @@ -84,6 +85,7 @@ async fn handle_coingecko_token_list(_req: HttpRequest) -> Result let resp = json!([ {"id": "ethereum", "symbol": "eth", "name": "Ethereum"}, {"id": "dai", "symbol":"dai", "name": "Dai"}, + {"id": "glm", "symbol":"glm", "name": "Golem"}, {"id": "gnt", "symbol":"gnt", "name": "Golem"}, {"id": "basic-attention-token", "symbol": "bat", "name": "Basic Attention Token"}, {"id": "wrapped-bitcoin", "symbol": "wbtc", "name": "Wrapped Bitcoin"}, @@ -100,6 +102,7 @@ async fn handle_coingecko_token_price_query(req: HttpRequest) -> Result BigDecimal::try_from(0.2).unwrap(), Some("dai") => BigDecimal::from(1), Some("gnt") => BigDecimal::from(1), + Some("glm") => BigDecimal::from(1), _ => BigDecimal::from(0), }; let random_multiplier = thread_rng().gen_range(0.9, 1.1); diff --git a/core/bin/zksync_api/src/signature_checker.rs b/core/bin/zksync_api/src/signature_checker.rs index 493ff0299c..330ec8b510 100644 --- a/core/bin/zksync_api/src/signature_checker.rs +++ b/core/bin/zksync_api/src/signature_checker.rs @@ -89,12 +89,6 @@ async fn verify_eth_signature( ) -> Result<(), TxAddError> { match request_data { RequestData::Tx(request) => { - // TODO: Remove this code after Golem update [ZKS-173] - if (network == Network::Rinkeby || network == Network::Localhost) - && request.token.symbol == "GNT" - { - return Ok(()); - } verify_eth_signature_single_tx( &request.tx, request.sender, @@ -104,12 +98,6 @@ async fn verify_eth_signature( .await?; } RequestData::Batch(request) => { - // TODO: Remove this code after Golem update [ZKS-173] - if (network == Network::Rinkeby || network == Network::Localhost) - && request.tokens.iter().any(|t| t.symbol == "GNT") - { - return Ok(()); - } let accounts = &request.senders; let tokens = &request.tokens; let txs = &request.txs; diff --git a/core/bin/zksync_api/src/utils/token_db_cache.rs b/core/bin/zksync_api/src/utils/token_db_cache.rs index 23b0dd8825..07a34d5c97 100644 --- a/core/bin/zksync_api/src/utils/token_db_cache.rs +++ b/core/bin/zksync_api/src/utils/token_db_cache.rs @@ -22,30 +22,7 @@ impl TokenDBCache { storage: &mut StorageProcessor<'_>, token_query: impl Into, ) -> anyhow::Result> { - let token_query = token_query.into(); - // HACK: Special case for the Golem: - // - // Currently, their token on Rinkeby is called GNT, but it's being renamed to the GLM. - // So, for some period of time, we should consider GLM token name as an alias to the GNT token. - // - // TODO: Remove this case after Golem update [ZKS-173] - match token_query { - TokenLike::Symbol(symbol) if symbol == "tGLM" => { - // Try to lookup Golem token as "tGLM". - if let Some(token) = self - .get_token_impl(storage, TokenLike::Symbol(symbol)) - .await? - { - // If such token exists, use it. - Ok(Some(token)) - } else { - // Otherwise to lookup Golem token as "GNT". - self.get_token_impl(storage, TokenLike::Symbol("GNT".to_string())) - .await - } - } - other => self.get_token_impl(storage, other).await, - } + self.get_token_impl(storage, token_query.into()).await } async fn get_token_impl( diff --git a/sdk/zksync-rs/tests/integration.rs b/sdk/zksync-rs/tests/integration.rs index d7ad7a2312..1b8b8662ab 100644 --- a/sdk/zksync-rs/tests/integration.rs +++ b/sdk/zksync-rs/tests/integration.rs @@ -636,17 +636,6 @@ async fn comprehensive_test() -> Result<(), anyhow::Error> { ) .await?; - // Test for tGLM token in ETH signatures workaround - // TODO: Remove this code after Golem update [ZKS-173] - let token_gnt = sync_depositor_wallet - .tokens - .resolve("GNT".into()) - .ok_or_else(|| anyhow::anyhow!("Error resolve token"))?; - let token_tglm = sync_depositor_wallet - .tokens - .resolve("tGLM".into()) - .ok_or_else(|| anyhow::anyhow!("Error resolve token"))?; - let tglm_deposit_amount = U256::from(10).pow(18.into()) * 10000; // 10000 tGLM transfer_to("tGLM", tglm_deposit_amount, sync_depositor_wallet.address()).await?; @@ -670,13 +659,6 @@ async fn comprehensive_test() -> Result<(), anyhow::Error> { ) .await?; test_change_pubkey(&alice_wallet2, "GNT").await?; - test_transfer( - &alice_wallet2, - &bob_wallet1, - "GNT", - 20_000_000_000_000_000_000u128, - ) - .await?; // Check that sending transaction using tGLM token name works and transaction gets processed by server. test_transfer( &alice_wallet2, From 0e6b19f0dd4c9c2d89cbae9751fd2009ec2d73ca Mon Sep 17 00:00:00 2001 From: Danil Lugovskoy Date: Mon, 22 Mar 2021 17:09:01 +0300 Subject: [PATCH 2/7] Fix integration test --- sdk/zksync-rs/tests/integration.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sdk/zksync-rs/tests/integration.rs b/sdk/zksync-rs/tests/integration.rs index 1b8b8662ab..98671ecccb 100644 --- a/sdk/zksync-rs/tests/integration.rs +++ b/sdk/zksync-rs/tests/integration.rs @@ -603,6 +603,11 @@ async fn comprehensive_test() -> Result<(), anyhow::Error> { .resolve("DAI".into()) .ok_or_else(|| anyhow::anyhow!("Error resolve token"))?; + let token_tglm = sync_depositor_wallet + .tokens + .resolve("tGLM".into()) + .ok_or_else(|| anyhow::anyhow!("Error resolve token"))?; + let dai_deposit_amount = U256::from(10).pow(18.into()) * 10000; // 10000 DAI // Move ETH to wallets so they will have some funds for L1 transactions. @@ -639,11 +644,6 @@ async fn comprehensive_test() -> Result<(), anyhow::Error> { let tglm_deposit_amount = U256::from(10).pow(18.into()) * 10000; // 10000 tGLM transfer_to("tGLM", tglm_deposit_amount, sync_depositor_wallet.address()).await?; - assert_eq!( - get_ethereum_balance(ðereum, sync_depositor_wallet.address(), &token_gnt).await?, - tglm_deposit_amount - ); - assert_eq!( get_ethereum_balance(ðereum, sync_depositor_wallet.address(), &token_tglm).await?, tglm_deposit_amount @@ -654,7 +654,7 @@ async fn comprehensive_test() -> Result<(), anyhow::Error> { test_deposit( &sync_depositor_wallet, &mut alice_wallet2, - &token_gnt, + &token_tglm, 200_000_000_000_000_000_000u128, ) .await?; From 457d423fbb1961a817a749ef505e077d207198f1 Mon Sep 17 00:00:00 2001 From: Danil Lugovskoy Date: Mon, 22 Mar 2021 17:20:36 +0300 Subject: [PATCH 3/7] Make clippy happy --- core/bin/zksync_api/src/api_server/rpc_server/rpc_impl.rs | 1 - core/bin/zksync_api/src/api_server/rpc_server/types.rs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/core/bin/zksync_api/src/api_server/rpc_server/rpc_impl.rs b/core/bin/zksync_api/src/api_server/rpc_server/rpc_impl.rs index fbd2da9bd6..4986836fdb 100644 --- a/core/bin/zksync_api/src/api_server/rpc_server/rpc_impl.rs +++ b/core/bin/zksync_api/src/api_server/rpc_server/rpc_impl.rs @@ -161,7 +161,6 @@ impl RpcApp { Error::internal_error() })?; - let mut has_gnt = None; let mut result: HashMap<_, _> = tokens .drain() .map(|(id, token)| { diff --git a/core/bin/zksync_api/src/api_server/rpc_server/types.rs b/core/bin/zksync_api/src/api_server/rpc_server/types.rs index 5cddc4b8e5..1a316d96e1 100644 --- a/core/bin/zksync_api/src/api_server/rpc_server/types.rs +++ b/core/bin/zksync_api/src/api_server/rpc_server/types.rs @@ -45,7 +45,7 @@ impl ResponseAccountState { // Old code used `HashMap` as well and didn't rely on the particular order, // so here we use `HashMap` as well for the consistency. - let mut balances: HashMap<_, _> = inner.balances.into_iter().collect(); + let balances: HashMap<_, _> = inner.balances.into_iter().collect(); Ok(Self { balances, From e247f1da95e213e4f7cc05d3ceb8a4f5431c20d0 Mon Sep 17 00:00:00 2001 From: Danil Lugovskoy Date: Mon, 22 Mar 2021 17:25:53 +0300 Subject: [PATCH 4/7] Make clippy happy --- core/bin/zksync_api/src/api_server/rpc_server/rpc_impl.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/bin/zksync_api/src/api_server/rpc_server/rpc_impl.rs b/core/bin/zksync_api/src/api_server/rpc_server/rpc_impl.rs index 4986836fdb..c286cdcb47 100644 --- a/core/bin/zksync_api/src/api_server/rpc_server/rpc_impl.rs +++ b/core/bin/zksync_api/src/api_server/rpc_server/rpc_impl.rs @@ -161,7 +161,7 @@ impl RpcApp { Error::internal_error() })?; - let mut result: HashMap<_, _> = tokens + let result: HashMap<_, _> = tokens .drain() .map(|(id, token)| { if *id == 0 { From c98c24a6d605789ce97a6885689f923fdbcae6cf Mon Sep 17 00:00:00 2001 From: Danil Lugovskoy Date: Mon, 22 Mar 2021 18:07:39 +0300 Subject: [PATCH 5/7] Delete all tests with tglm --- sdk/zksync-rs/tests/integration.rs | 69 ------------------------------ 1 file changed, 69 deletions(-) diff --git a/sdk/zksync-rs/tests/integration.rs b/sdk/zksync-rs/tests/integration.rs index 98671ecccb..64851e896c 100644 --- a/sdk/zksync-rs/tests/integration.rs +++ b/sdk/zksync-rs/tests/integration.rs @@ -603,11 +603,6 @@ async fn comprehensive_test() -> Result<(), anyhow::Error> { .resolve("DAI".into()) .ok_or_else(|| anyhow::anyhow!("Error resolve token"))?; - let token_tglm = sync_depositor_wallet - .tokens - .resolve("tGLM".into()) - .ok_or_else(|| anyhow::anyhow!("Error resolve token"))?; - let dai_deposit_amount = U256::from(10).pow(18.into()) * 10000; // 10000 DAI // Move ETH to wallets so they will have some funds for L1 transactions. @@ -641,70 +636,6 @@ async fn comprehensive_test() -> Result<(), anyhow::Error> { ) .await?; - let tglm_deposit_amount = U256::from(10).pow(18.into()) * 10000; // 10000 tGLM - transfer_to("tGLM", tglm_deposit_amount, sync_depositor_wallet.address()).await?; - - assert_eq!( - get_ethereum_balance(ðereum, sync_depositor_wallet.address(), &token_tglm).await?, - tglm_deposit_amount - ); - - let mut alice_wallet2 = make_wallet(provider.clone(), eth_random_account_credentials()).await?; - - test_deposit( - &sync_depositor_wallet, - &mut alice_wallet2, - &token_tglm, - 200_000_000_000_000_000_000u128, - ) - .await?; - test_change_pubkey(&alice_wallet2, "GNT").await?; - // Check that sending transaction using tGLM token name works and transaction gets processed by server. - test_transfer( - &alice_wallet2, - &bob_wallet1, - "tGLM", - 20_000_000_000_000_000_000u128, - ) - .await?; - - // Test batch with single transaction - let total_fee = alice_wallet2 - .provider - .get_tx_fee(TxFeeTypes::Transfer, bob_wallet1.address(), "tGLM") - .await? - .total_fee; - - let mut nonce = alice_wallet2.account_info().await?.committed.nonce; - let (transfer, signature) = alice_wallet2 - .signer - .sign_transfer( - token_tglm.clone(), - 20_000_000_000_000_000_000u128.into(), - total_fee, - bob_wallet1.address(), - nonce, - Default::default(), - ) - .await?; - *nonce += 1; - - let signed_transfers = vec![( - ZkSyncTx::Transfer(Box::new(transfer.clone())), - signature.clone(), - )]; - - let tx_hashes = alice_wallet2 - .provider - .send_txs_batch(signed_transfers, None) - .await?; - let batch_handle = SyncTransactionHandle::new(tx_hashes[0], alice_wallet2.provider.clone()); - - batch_handle - .commit_timeout(Duration::from_secs(180)) - .wait_for_commit() - .await?; - Ok(()) } From 35bc46cf2aa14dafc181cc9ae2556889aa98095c Mon Sep 17 00:00:00 2001 From: Danil Lugovskoy Date: Mon, 22 Mar 2021 18:20:19 +0300 Subject: [PATCH 6/7] Remove redundant network --- core/bin/zksync_api/src/signature_checker.rs | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/core/bin/zksync_api/src/signature_checker.rs b/core/bin/zksync_api/src/signature_checker.rs index 330ec8b510..c5b5e701ac 100644 --- a/core/bin/zksync_api/src/signature_checker.rs +++ b/core/bin/zksync_api/src/signature_checker.rs @@ -49,9 +49,8 @@ impl VerifiedTx { pub async fn verify( request_data: RequestData, eth_checker: &EthereumChecker, - network: Network, ) -> Result { - verify_eth_signature(&request_data, eth_checker, network).await?; + verify_eth_signature(&request_data, eth_checker).await?; let mut tx_variant = request_data.get_tx_variant(); verify_tx_correctness(&mut tx_variant)?; @@ -85,7 +84,6 @@ impl VerifiedTx { async fn verify_eth_signature( request_data: &RequestData, eth_checker: &EthereumChecker, - network: Network, ) -> Result<(), TxAddError> { match request_data { RequestData::Tx(request) => { @@ -338,12 +336,11 @@ pub fn start_sign_checker_detached( handle: Handle, mut input: mpsc::Receiver, eth_checker: EthereumChecker, - eth_network: Network, ) { while let Some(VerifySignatureRequest { data, response }) = input.next().await { let eth_checker = eth_checker.clone(); handle.spawn(async move { - let resp = VerifiedTx::verify(data, ð_checker, eth_network).await; + let resp = VerifiedTx::verify(data, ð_checker).await; response.send(resp).unwrap_or_default(); }); @@ -361,12 +358,7 @@ pub fn start_sign_checker_detached( .build() .expect("failed to build runtime for signature processor"); let handle = runtime.handle().clone(); - runtime.block_on(checker_routine( - handle, - input, - eth_checker, - config.chain.eth.network, - )); + runtime.block_on(checker_routine(handle, input, eth_checker)); }) .expect("failed to start signature checker thread"); } From 0faa3855e73fc752794e09d8166b5faf7c2c45fe Mon Sep 17 00:00:00 2001 From: Danil Lugovskoy Date: Mon, 22 Mar 2021 18:31:10 +0300 Subject: [PATCH 7/7] Delete network --- core/bin/zksync_api/src/signature_checker.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/core/bin/zksync_api/src/signature_checker.rs b/core/bin/zksync_api/src/signature_checker.rs index c5b5e701ac..cda2fdb055 100644 --- a/core/bin/zksync_api/src/signature_checker.rs +++ b/core/bin/zksync_api/src/signature_checker.rs @@ -23,7 +23,6 @@ use zksync_types::{ use crate::{eth_checker::EthereumChecker, tx_error::TxAddError}; use zksync_config::ZkSyncConfig; use zksync_eth_client::EthereumGateway; -use zksync_types::network::Network; use zksync_utils::panic_notify::ThreadPanicNotify; /// `TxVariant` is used to form a verify request. It is possible to wrap