Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions ethers-providers/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down