From 49dc487676dfaf80cff3281128b202eb40191e8a Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Tue, 22 Nov 2022 22:08:04 +0100 Subject: [PATCH] feat: add another rate limit retry check (#1881) --- ethers-providers/src/transports/retry.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ethers-providers/src/transports/retry.rs b/ethers-providers/src/transports/retry.rs index 947a0495..23d9e3a8 100644 --- a/ethers-providers/src/transports/retry.rs +++ b/ethers-providers/src/transports/retry.rs @@ -346,6 +346,12 @@ impl RetryPolicy for HttpRateLimitRetryPolicy { if *code == 429 { return true } + + // alternative alchemy error for specific IPs + if *code == -32016 && message.contains("rate limit") { + return true + } + match message.as_str() { // this is commonly thrown by infura and is apparently a load balancer issue, see also "header not found" => true, @@ -494,4 +500,14 @@ mod tests { let backoff = HttpRateLimitRetryPolicy.backoff_hint(&err); assert!(backoff.is_none()); } + + #[test] + fn test_alchemy_ip_rate_limit() { + let s = "{\"code\":-32016,\"message\":\"Your IP has exceeded its requests per second capacity. To increase your rate limits, please sign up for a free Alchemy account at https://www.alchemy.com/optimism.\"}"; + let err: JsonRpcError = serde_json::from_str(s).unwrap(); + let err = ClientError::JsonRpcError(err); + + let should_retry = HttpRateLimitRetryPolicy::default().should_retry(&err); + assert!(should_retry); + } }