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

feat: make eth_call and eth_estimateGas default to using Pending block #1568

Merged
merged 2 commits into from
Oct 25, 2024
Merged
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
19 changes: 12 additions & 7 deletions crates/provider/src/provider/trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub trait Provider<T: Transport + Clone = BoxTransport, N: Network = Ethereum>:
///
/// This function returns [`EthCall`] which can be used to execute the
/// call, or to add [`StateOverride`] or a [`BlockId`]. If no overrides
/// or block ID is provided, the call will be executed on the latest block
/// or block ID is provided, the call will be executed on the pending block
/// with the current state.
///
/// [`StateOverride`]: alloy_rpc_types_eth::state::StateOverride
Expand All @@ -153,7 +153,7 @@ pub trait Provider<T: Transport + Clone = BoxTransport, N: Network = Ethereum>:
#[doc(alias = "eth_call")]
#[doc(alias = "call_with_overrides")]
fn call<'req>(&self, tx: &'req N::TransactionRequest) -> EthCall<'req, T, N, Bytes> {
EthCall::new(self.weak_client(), tx)
EthCall::new(self.weak_client(), tx).block(BlockNumberOrTag::Pending.into())
}

/// Executes an arbitrary number of transactions on top of the requested state.
Expand Down Expand Up @@ -185,18 +185,23 @@ pub trait Provider<T: Transport + Clone = BoxTransport, N: Network = Ethereum>:
self.client().request("eth_createAccessList", request).into()
}

/// This function returns an [`EthCall`] which can be used to get a gas estimate,
/// or to add [`StateOverride`] or a [`BlockId`]. If no overrides
/// or block ID is provided, the gas estimate will be computed for the latest block
/// with the current state.
/// Create an [`EthCall`] future to estimate the gas required for a
/// transaction.
///
/// The future can be used to specify a [`StateOverride`] or [`BlockId`]
/// before dispatching the call. If no overrides or block ID is provided,
/// the gas estimate will be computed for the pending block with the
/// current state.
///
/// [`StateOverride`]: alloy_rpc_types_eth::state::StateOverride
///
/// # Note
///
/// Not all client implementations support state overrides for eth_estimateGas.
fn estimate_gas<'req>(&self, tx: &'req N::TransactionRequest) -> EthCall<'req, T, N, U64, u64> {
EthCall::gas_estimate(self.weak_client(), tx).map_resp(utils::convert_u64)
EthCall::gas_estimate(self.weak_client(), tx)
.block(BlockNumberOrTag::Pending.into())
.map_resp(utils::convert_u64)
}

/// Estimates the EIP1559 `maxFeePerGas` and `maxPriorityFeePerGas` fields.
Expand Down