perf: only fallback to old feeHistory request on error (#1399)

This commit is contained in:
Matthias Seitz 2022-06-22 19:11:45 +02:00 committed by GitHub
parent 4d5deb4259
commit 7472e02577
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 9 deletions

View File

@ -1188,17 +1188,30 @@ impl<P: JsonRpcClient> Middleware for Provider<P> {
// 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
}
}
}
}