From b3312a07afb23d4913a9635611856419cab3ba99 Mon Sep 17 00:00:00 2001 From: Trevor Porter Date: Thu, 1 Sep 2022 13:45:09 +0100 Subject: [PATCH 1/3] Don't default to 'latest' block ID for eth_estimateGas --- ethers-providers/src/provider.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ethers-providers/src/provider.rs b/ethers-providers/src/provider.rs index 0aec2f7bd..d03214a9b 100644 --- a/ethers-providers/src/provider.rs +++ b/ethers-providers/src/provider.rs @@ -574,8 +574,14 @@ impl Middleware for Provider

{ block: Option, ) -> Result { let tx = utils::serialize(tx); - let block = utils::serialize(&block.unwrap_or_else(|| BlockNumber::Latest.into())); - self.request("eth_estimateGas", [tx, block]).await + // Some chains (e.g. Optimism) don't support a block ID being passed as a param, + // so refrain from defaulting to BlockNumber::Latest. + let params = if let Some(block_id) = block { + vec![tx, utils::serialize(&block_id)] + } else { + vec![tx] + }; + self.request("eth_estimateGas", params).await } async fn create_access_list( From a063f98e9460b4c7b28fa1e183808a05defeaad5 Mon Sep 17 00:00:00 2001 From: Trevor Porter Date: Thu, 1 Sep 2022 14:12:32 +0100 Subject: [PATCH 2/3] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 939c41894..4bbad8102 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Unreleased +- Stop defaulting to the `"latest"` block in `eth_estimateGas` params [#1657](https://github.com/gakonst/ethers-rs/pull/1657) - Fix geth trace types for debug_traceTransaction rpc - Fix RLP decoding of legacy `Transaction` - Fix RLP encoding of `TransactionReceipt` [#1661](https://github.com/gakonst/ethers-rs/pull/1661) From fe97466bc6e7fe2d2f8ab09b48fff4b75459597f Mon Sep 17 00:00:00 2001 From: Trevor Porter Date: Fri, 16 Sep 2022 16:50:48 +0100 Subject: [PATCH 3/3] Amend comment --- ethers-providers/src/provider.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethers-providers/src/provider.rs b/ethers-providers/src/provider.rs index d03214a9b..0b26489e2 100644 --- a/ethers-providers/src/provider.rs +++ b/ethers-providers/src/provider.rs @@ -574,7 +574,7 @@ impl Middleware for Provider

{ block: Option, ) -> Result { let tx = utils::serialize(tx); - // Some chains (e.g. Optimism) don't support a block ID being passed as a param, + // Some nodes (e.g. old Optimism clients) don't support a block ID being passed as a param, // so refrain from defaulting to BlockNumber::Latest. let params = if let Some(block_id) = block { vec![tx, utils::serialize(&block_id)]