From aff53ce36a579e7271b6a137540a106f48add158 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Sat, 6 May 2023 14:17:08 -0600 Subject: [PATCH] automatic retry for eth_getTransactionReceipt and eth_getTransactionByHash thanks for the report Lefteris @ Rotki --- web3_proxy/src/app/mod.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/web3_proxy/src/app/mod.rs b/web3_proxy/src/app/mod.rs index 0f4b30fa..e2e1e0df 100644 --- a/web3_proxy/src/app/mod.rs +++ b/web3_proxy/src/app/mod.rs @@ -1564,6 +1564,37 @@ impl Web3ProxyApp { JsonRpcForwardedResponse::from_value(json!(gas_estimate), request_id) } + "eth_getTransactionReceipt" | "eth_getTransactionByHash" => { + // try to get the transaction without specifying a min_block_height + let mut response = self + .balanced_rpcs + .try_proxy_connection( + authorization, + request, + Some(&request_metadata), + None, + None, + ) + .await?; + + // if we got "null", it is probably because the tx is old. retry requiring nodes with old block data + if let Some(ref result) = response.result { + if result.get() == "null" { + response = self + .balanced_rpcs + .try_proxy_connection( + authorization, + request, + Some(&request_metadata), + Some(&U64::one()), + None, + ) + .await?; + } + } + + response + } // TODO: eth_gasPrice that does awesome magic to predict the future "eth_hashrate" => JsonRpcForwardedResponse::from_value(json!(U64::zero()), request_id), "eth_mining" => {