fix: ensure we can handle pending target for feeHistory (#9904)

This commit is contained in:
Matthias Seitz
2024-07-30 18:00:33 +02:00
committed by GitHub
parent e4ae2a7ac1
commit 65720c9fc1

View File

@ -50,7 +50,7 @@ pub trait EthFees: LoadFee {
fn fee_history(
&self,
mut block_count: u64,
newest_block: BlockNumberOrTag,
mut newest_block: BlockNumberOrTag,
reward_percentiles: Option<Vec<f64>>,
) -> impl Future<Output = Result<FeeHistory, Self::Error>> + Send {
async move {
@ -74,6 +74,13 @@ pub trait EthFees: LoadFee {
block_count = max_fee_history
}
if newest_block.is_pending() {
// cap the target block since we don't have fee history for the pending block
newest_block = BlockNumberOrTag::Latest;
// account for missing pending block
block_count = block_count.saturating_sub(1);
}
let Some(end_block) = LoadFee::provider(self)
.block_number_for_id(newest_block.into())
.map_err(Self::Error::from_eth_err)?