From 7472e02577f8aa16b174f14c76bb39f324edb7eb Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Wed, 22 Jun 2022 19:11:45 +0200 Subject: [PATCH] perf: only fallback to old feeHistory request on error (#1399) --- ethers-providers/src/provider.rs | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/ethers-providers/src/provider.rs b/ethers-providers/src/provider.rs index 95de17a3..76e1ffaf 100644 --- a/ethers-providers/src/provider.rs +++ b/ethers-providers/src/provider.rs @@ -1188,17 +1188,30 @@ impl Middleware for Provider

{ // The blockCount param is expected to be an unsigned integer up to geth v1.10.6. // Geth v1.10.7 onwards, this has been updated to a hex encoded form. Failure to // decode the param from client side would fallback to the old API spec. - self.request( - "eth_feeHistory", - [utils::serialize(&block_count), last_block.clone(), reward_percentiles.clone()], - ) - .await - .or(self - .request( + match self + .request::<_, FeeHistory>( "eth_feeHistory", - [utils::serialize(&block_count.as_u64()), last_block, reward_percentiles], + [utils::serialize(&block_count), last_block.clone(), reward_percentiles.clone()], ) - .await) + .await + { + success @ Ok(_) => success, + err @ Err(_) => { + let fallback = self + .request::<_, FeeHistory>( + "eth_feeHistory", + [utils::serialize(&block_count.as_u64()), last_block, reward_percentiles], + ) + .await; + + if fallback.is_err() { + // if the older fallback also resulted in an error, we return the error from the + // initial attempt + return err + } + fallback + } + } } }