perf(rpc): validate reward percentiles before DB calls in eth_feeHistory (#22679)

This commit is contained in:
stevencartavia
2026-03-01 02:31:19 -06:00
committed by GitHub
parent ec6e3032f0
commit c52ff7045c
2 changed files with 12 additions and 14 deletions

View File

@@ -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`,

View File

@@ -80,9 +80,7 @@ where
let transactions = txs
.into_iter()
.map(|tx| recover_raw_transaction::<PoolPooledTx<Eth::Pool>>(&tx))
.collect::<Result<Vec<_>, _>>()?
.into_iter()
.collect::<Vec<_>>();
.collect::<Result<Vec<_>, _>>()?;
let block_id: alloy_rpc_types_eth::BlockId = state_block_number.into();
// Note: the block number is considered the `parent` block: <https://github.com/flashbots/mev-geth/blob/fddf97beec5877483f879a77b7dea2e58a58d653/internal/ethapi/api.go#L2104>