From 9f7d28b53804250457afb967094ffc592a3193a9 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Thu, 12 Jan 2023 22:40:47 -0800 Subject: [PATCH] retry if we get the method X is not available --- TODO.md | 1 + web3_proxy/src/rpcs/connections.rs | 36 ++++++++++++++++++++---------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/TODO.md b/TODO.md index 1a35095c..6ca8ddf9 100644 --- a/TODO.md +++ b/TODO.md @@ -298,6 +298,7 @@ These are not yet ordered. There might be duplicates. We might not actually need - [x] ip detection needs work so that everything doesnt show up as 172.x.x.x - i think this was done, but am not positive. - [x] if private txs are disabled, only send trasactions to some of our servers. we were DOSing ourselves with transactions and slowing down sync +- [x] retry if we get "the method X is not available" - [-] let users choose a % of reverts to log (or maybe x/second). someone like curve logging all reverts will be a BIG database very quickly - this must be opt-in and spawned in the background since it will slow things down and will make their calls less private - [ ] automatic pruning of old revert logs once too many are collected diff --git a/web3_proxy/src/rpcs/connections.rs b/web3_proxy/src/rpcs/connections.rs index fef01b73..a6cd18a9 100644 --- a/web3_proxy/src/rpcs/connections.rs +++ b/web3_proxy/src/rpcs/connections.rs @@ -725,22 +725,34 @@ impl Web3Connections { } // some errors should be retried on other nodes - if error.code == -32000 { - let error_msg = error.message.as_str(); + match error.code { + -32000 => { + let error_msg = error.message.as_str(); - // TODO: regex? - let retry_prefixes = [ - "header not found", - "header for hash not found", - "missing trie node", - "node not started", - "RPC timeout", - ]; - for retry_prefix in retry_prefixes { - if error_msg.starts_with(retry_prefix) { + // TODO: regex? + let retry_prefixes = [ + "header not found", + "header for hash not found", + "missing trie node", + "node not started", + "RPC timeout", + ]; + for retry_prefix in retry_prefixes { + if error_msg.starts_with(retry_prefix) { + continue; + } + } + } + -32601 => { + let error_msg = error.message.as_str(); + + if error_msg.starts_with("the method") + && error_msg.ends_with("is not available") + { continue; } } + _ => {} } } else { // trace!(?response, "rpc success");