From 25df68ebe0877180114a72f486e3a6a26a40131d Mon Sep 17 00:00:00 2001 From: Alex Ostrovski Date: Wed, 8 May 2024 17:52:52 +0300 Subject: [PATCH] fix(eth-client): Make block params non-optional (#1882) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## What ❔ Fixes passing `null` parameters where RPC providers don't expect them. ## Why ❔ Without the fix, L1 client is broken. ## Checklist - [x] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [x] Code has been formatted via `zk fmt` and `zk lint`. - [ ] Spellcheck has been run via `zk spellcheck`. - [ ] Linkcheck has been run via `zk linkcheck`. --- core/lib/eth_client/src/clients/http/decl.rs | 14 +++---------- core/lib/eth_client/src/clients/http/query.rs | 20 +++++++++---------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/core/lib/eth_client/src/clients/http/decl.rs b/core/lib/eth_client/src/clients/http/decl.rs index 1dbda9d22649..7887e1bdee09 100644 --- a/core/lib/eth_client/src/clients/http/decl.rs +++ b/core/lib/eth_client/src/clients/http/decl.rs @@ -30,25 +30,17 @@ pub(super) trait L1EthNamespace { async fn get_transaction_count( &self, address: Address, - block: Option, + block: web3::BlockNumber, ) -> RpcResult; #[method(name = "gasPrice")] async fn gas_price(&self) -> RpcResult; #[method(name = "call")] - async fn call( - &self, - req: web3::CallRequest, - block: Option, - ) -> RpcResult; + async fn call(&self, req: web3::CallRequest, block: web3::BlockId) -> RpcResult; #[method(name = "getBalance")] - async fn get_balance( - &self, - address: Address, - block: Option, - ) -> RpcResult; + async fn get_balance(&self, address: Address, block: web3::BlockNumber) -> RpcResult; #[method(name = "getLogs")] async fn get_logs(&self, filter: web3::Filter) -> RpcResult>; diff --git a/core/lib/eth_client/src/clients/http/query.rs b/core/lib/eth_client/src/clients/http/query.rs index 89b793d463f9..922248487e09 100644 --- a/core/lib/eth_client/src/clients/http/query.rs +++ b/core/lib/eth_client/src/clients/http/query.rs @@ -69,10 +69,7 @@ impl EthInterface for QueryClient { ) -> Result { COUNTERS.call[&(Method::NonceAtForAccount, self.component)].inc(); let latency = LATENCIES.direct[&Method::NonceAtForAccount].start(); - let nonce = self - .web3 - .get_transaction_count(account, Some(block)) - .await?; + let nonce = self.web3.get_transaction_count(account, block).await?; latency.observe(); Ok(nonce) } @@ -203,11 +200,10 @@ impl EthInterface for QueryClient { access_list: None, }; - let err = self - .web3 - .call(call_request, receipt.block_number.map(Into::into)) - .await - .err(); + let block_number = receipt + .block_number + .map_or_else(|| web3::BlockNumber::Latest.into(), Into::into); + let err = self.web3.call(call_request, block_number).await.err(); let failure_info = match err { Some(ClientError::Call(call_err)) => { @@ -246,6 +242,7 @@ impl EthInterface for QueryClient { block: Option, ) -> Result { let latency = LATENCIES.direct[&Method::CallContractFunction].start(); + let block = block.unwrap_or_else(|| web3::BlockNumber::Latest.into()); let output_bytes = self.web3.call(request, block).await?; latency.observe(); Ok(output_bytes) @@ -262,7 +259,10 @@ impl EthInterface for QueryClient { async fn eth_balance(&self, address: Address) -> Result { COUNTERS.call[&(Method::EthBalance, self.component)].inc(); let latency = LATENCIES.direct[&Method::EthBalance].start(); - let balance = self.web3.get_balance(address, None).await?; + let balance = self + .web3 + .get_balance(address, web3::BlockNumber::Latest) + .await?; latency.observe(); Ok(balance) }