From 64d58456dafbd87f85af21b690b5e915732a125e Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Sat, 15 Jul 2023 16:48:18 +0200 Subject: [PATCH] fix: rpc cap block range correctly (#3791) Co-authored-by: Georgios Konstantopoulos --- crates/rpc/rpc/src/eth/api/fees.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/crates/rpc/rpc/src/eth/api/fees.rs b/crates/rpc/rpc/src/eth/api/fees.rs index c9a1513535..49b0291a11 100644 --- a/crates/rpc/rpc/src/eth/api/fees.rs +++ b/crates/rpc/rpc/src/eth/api/fees.rs @@ -67,9 +67,11 @@ where return Err(EthApiError::UnknownBlockNumber) }; - // Check that we would not be querying outside of genesis - if end_block < block_count { - return Err(EthApiError::InvalidBlockRange) + // need to add 1 to the end block to get the correct (inclusive) range + let end_block_plus = end_block + 1; + // Ensure that we would not be querying outside of genesis + if end_block_plus < block_count { + block_count = end_block_plus; } // If reward percentiles were specified, we need to validate that they are monotonically @@ -86,7 +88,8 @@ where // // Treat a request for 1 block as a request for `newest_block..=newest_block`, // otherwise `newest_block - 2 - let start_block = end_block - block_count + 1; + // SAFETY: We ensured that block count is capped + let start_block = end_block_plus - block_count; let headers = self.provider().sealed_headers_range(start_block..=end_block)?; if headers.len() != block_count as usize { return Err(EthApiError::InvalidBlockRange)