From c52ff7045c0fa68b55ab12d9cb727422b6deb4da Mon Sep 17 00:00:00 2001 From: stevencartavia <112043913+stevencartavia@users.noreply.github.com> Date: Sun, 1 Mar 2026 02:31:19 -0600 Subject: [PATCH] perf(rpc): validate reward percentiles before DB calls in `eth_feeHistory` (#22679) --- crates/rpc/rpc-eth-api/src/helpers/fee.rs | 22 +++++++++++----------- crates/rpc/rpc/src/eth/bundle.rs | 4 +--- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/crates/rpc/rpc-eth-api/src/helpers/fee.rs b/crates/rpc/rpc-eth-api/src/helpers/fee.rs index b8e98db1fc..b74847fbfc 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/fee.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/fee.rs @@ -73,6 +73,17 @@ pub trait EthFees: return Err(EthApiError::InvalidRewardPercentiles.into()) } + // If reward percentiles were specified, we + // need to validate that they are monotonically + // increasing and 0 <= p <= 100 + // Note: The types used ensure that the percentiles are never < 0 + if let Some(percentiles) = &reward_percentiles && + (percentiles.iter().any(|p| *p < 0.0 || *p > 100.0) || + percentiles.windows(2).any(|w| w[0] > w[1])) + { + return Err(EthApiError::InvalidRewardPercentiles.into()) + } + // See https://github.com/ethereum/go-ethereum/blob/2754b197c935ee63101cbbca2752338246384fec/eth/gasprice/feehistory.go#L218C8-L225 let max_fee_history = if reward_percentiles.is_none() { self.gas_oracle().config().max_header_history @@ -118,17 +129,6 @@ pub trait EthFees: block_count = end_block_plus; } - // If reward percentiles were specified, we - // need to validate that they are monotonically - // increasing and 0 <= p <= 100 - // Note: The types used ensure that the percentiles are never < 0 - if let Some(percentiles) = &reward_percentiles && - (percentiles.iter().any(|p| *p < 0.0 || *p > 100.0) || - percentiles.windows(2).any(|w| w[0] > w[1])) - { - return Err(EthApiError::InvalidRewardPercentiles.into()) - } - // Fetch the headers and ensure we got all of them // // Treat a request for 1 block as a request for `newest_block..=newest_block`, diff --git a/crates/rpc/rpc/src/eth/bundle.rs b/crates/rpc/rpc/src/eth/bundle.rs index 1f7712dc24..c04b28410c 100644 --- a/crates/rpc/rpc/src/eth/bundle.rs +++ b/crates/rpc/rpc/src/eth/bundle.rs @@ -80,9 +80,7 @@ where let transactions = txs .into_iter() .map(|tx| recover_raw_transaction::>(&tx)) - .collect::, _>>()? - .into_iter() - .collect::>(); + .collect::, _>>()?; let block_id: alloy_rpc_types_eth::BlockId = state_block_number.into(); // Note: the block number is considered the `parent` block: