fix(providers): don't default to "latest" block ID for `eth_estimateGas` (#1657)

* Don't default to 'latest' block ID for eth_estimateGas

* Add changelog entry

* Amend comment
This commit is contained in:
Trevor Porter 2022-09-16 19:23:34 +01:00 committed by GitHub
parent 78e406b261
commit c568fd3934
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -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)

View File

@ -574,8 +574,14 @@ impl<P: JsonRpcClient> Middleware for Provider<P> {
block: Option<BlockId>,
) -> Result<U256, ProviderError> {
let tx = utils::serialize(tx);
let block = utils::serialize(&block.unwrap_or_else(|| BlockNumber::Latest.into()));
self.request("eth_estimateGas", [tx, block]).await
// 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)]
} else {
vec![tx]
};
self.request("eth_estimateGas", params).await
}
async fn create_access_list(