Skip to content

Commit

Permalink
Merge #1464
Browse files Browse the repository at this point in the history
1464: Remove tGLM crunch r=Deniallugo a=Deniallugo



Co-authored-by: Danil Lugovskoy <[email protected]>
  • Loading branch information
bors-matterlabs-dev[bot] and Deniallugo authored Mar 22, 2021
2 parents 6ad3b35 + 0faa385 commit 740697d
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 206 deletions.
37 changes: 0 additions & 37 deletions core/bin/zksync_api/src/api_server/rest/v1/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
}
20 changes: 1 addition & 19 deletions core/bin/zksync_api/src/api_server/rpc_server/rpc_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,20 +161,9 @@ 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
let 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 {
Expand All @@ -183,13 +172,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)
}
Expand Down
16 changes: 1 addition & 15 deletions core/bin/zksync_api/src/api_server/rpc_server/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +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();

// TODO: Remove this code after Golem update [ZKS-173]
if let Some(balance) = balances.get("GNT").cloned() {
balances.insert("tGLM".to_string(), balance);
}
let balances: HashMap<_, _> = inner.balances.into_iter().collect();

Ok(Self {
balances,
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions core/bin/zksync_api/src/bin/dev-ticker-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -84,6 +85,7 @@ async fn handle_coingecko_token_list(_req: HttpRequest) -> Result<HttpResponse>
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"},
Expand All @@ -100,6 +102,7 @@ async fn handle_coingecko_token_price_query(req: HttpRequest) -> Result<HttpResp
Some("basic-attention-token") => 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);
Expand Down
27 changes: 3 additions & 24 deletions core/bin/zksync_api/src/signature_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -49,9 +48,8 @@ impl VerifiedTx {
pub async fn verify(
request_data: RequestData,
eth_checker: &EthereumChecker,
network: Network,
) -> Result<Self, TxAddError> {
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)?;

Expand Down Expand Up @@ -85,16 +83,9 @@ impl VerifiedTx {
async fn verify_eth_signature(
request_data: &RequestData,
eth_checker: &EthereumChecker,
network: Network,
) -> 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,
Expand All @@ -104,12 +95,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;
Expand Down Expand Up @@ -350,12 +335,11 @@ pub fn start_sign_checker_detached(
handle: Handle,
mut input: mpsc::Receiver<VerifySignatureRequest>,
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, &eth_checker, eth_network).await;
let resp = VerifiedTx::verify(data, &eth_checker).await;

response.send(resp).unwrap_or_default();
});
Expand All @@ -373,12 +357,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");
}
25 changes: 1 addition & 24 deletions core/bin/zksync_api/src/utils/token_db_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,7 @@ impl TokenDBCache {
storage: &mut StorageProcessor<'_>,
token_query: impl Into<TokenLike>,
) -> anyhow::Result<Option<Token>> {
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(
Expand Down
87 changes: 0 additions & 87 deletions sdk/zksync-rs/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,93 +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?;

assert_eq!(
get_ethereum_balance(&ethereum, sync_depositor_wallet.address(), &token_gnt).await?,
tglm_deposit_amount
);

assert_eq!(
get_ethereum_balance(&ethereum, 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_gnt,
200_000_000_000_000_000_000u128,
)
.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,
&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(())
}

Expand Down

0 comments on commit 740697d

Please sign in to comment.