Skip to content

Commit

Permalink
fix(eth-client): Make block params non-optional (#1882)
Browse files Browse the repository at this point in the history
## 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`.
  • Loading branch information
slowli authored May 8, 2024
1 parent a704bce commit 25df68e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
14 changes: 3 additions & 11 deletions core/lib/eth_client/src/clients/http/decl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,17 @@ pub(super) trait L1EthNamespace {
async fn get_transaction_count(
&self,
address: Address,
block: Option<web3::BlockNumber>,
block: web3::BlockNumber,
) -> RpcResult<U256>;

#[method(name = "gasPrice")]
async fn gas_price(&self) -> RpcResult<U256>;

#[method(name = "call")]
async fn call(
&self,
req: web3::CallRequest,
block: Option<web3::BlockId>,
) -> RpcResult<web3::Bytes>;
async fn call(&self, req: web3::CallRequest, block: web3::BlockId) -> RpcResult<web3::Bytes>;

#[method(name = "getBalance")]
async fn get_balance(
&self,
address: Address,
block: Option<web3::BlockNumber>,
) -> RpcResult<U256>;
async fn get_balance(&self, address: Address, block: web3::BlockNumber) -> RpcResult<U256>;

#[method(name = "getLogs")]
async fn get_logs(&self, filter: web3::Filter) -> RpcResult<Vec<web3::Log>>;
Expand Down
20 changes: 10 additions & 10 deletions core/lib/eth_client/src/clients/http/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ impl EthInterface for QueryClient {
) -> Result<U256, Error> {
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)
}
Expand Down Expand Up @@ -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)) => {
Expand Down Expand Up @@ -246,6 +242,7 @@ impl EthInterface for QueryClient {
block: Option<web3::BlockId>,
) -> Result<web3::Bytes, Error> {
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)
Expand All @@ -262,7 +259,10 @@ impl EthInterface for QueryClient {
async fn eth_balance(&self, address: Address) -> Result<U256, Error> {
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)
}
Expand Down

0 comments on commit 25df68e

Please sign in to comment.