diff --git a/eth_defi/middleware.py b/eth_defi/middleware.py index 0ef64302..786de839 100644 --- a/eth_defi/middleware.py +++ b/eth_defi/middleware.py @@ -77,22 +77,18 @@ #: See GoEthereum error codes https://github.com/ethereum/go-ethereum/blob/master/rpc/errors.go #: DEFAULT_RETRYABLE_RPC_ERROR_CODES = ( - # The node provider has corrupted database or something GoEthereum # cannot handle gracefully. # ValueError: {'message': 'Internal JSON-RPC error.', 'code': -32603} -32603, - # ValueError: {'code': -32000, 'message': 'nonce too low'}. # Might happen when we are broadcasting multiple transactions through multiple RPC providers # using eth_sendRawTransaction # One provide has not yet seeing a transaction broadcast through the other provider. -32000, - # ValueError: {'code': -32003, 'message': 'nonce too low'}. # Anvil variant for nonce too low, same as above -32003, - # Some error we are getting from LlamaNodes eth_getLogs RPC that we do not know what it is all about # {'code': -32043, 'message': 'Requested data is not available'} -32043, diff --git a/eth_defi/provider/fallback.py b/eth_defi/provider/fallback.py index 0dbf864f..da203fd6 100644 --- a/eth_defi/provider/fallback.py +++ b/eth_defi/provider/fallback.py @@ -102,7 +102,6 @@ def __init__( self.backoff = backoff self.retries = retries - #: provider number -> API name -> call count mappings. # This tracks completed API requests. self.api_call_counts = defaultdict(Counter) @@ -178,15 +177,7 @@ def make_request(self, method: RPCEndpoint, params: Any) -> RPCResponse: new_provider_name = get_provider_name(self.get_active_provider()) if i < self.retries: - logger.log(self.switchover_noisiness, "Encountered JSON-RPC retryable error %s when calling method %s.\n" "Switching providers %s -> %s\n" "Retrying in %f seconds, retry #%d / %d", - e, - method, - old_provider_name, - new_provider_name, - current_sleep, - i, - self.retries - ) + logger.log(self.switchover_noisiness, "Encountered JSON-RPC retryable error %s when calling method %s.\n" "Switching providers %s -> %s\n" "Retrying in %f seconds, retry #%d / %d", e, method, old_provider_name, new_provider_name, current_sleep, i, self.retries) time.sleep(current_sleep) current_sleep *= self.backoff self.retry_count += 1 @@ -197,4 +188,4 @@ def make_request(self, method: RPCEndpoint, params: Any) -> RPCResponse: logger.info("Will not retry on %s, method %s, as not a retryable exception %s: %s", old_provider_name, method, e.__class__, e) raise # Not retryable exception - raise AssertionError("Should never be reached") \ No newline at end of file + raise AssertionError("Should never be reached") diff --git a/tests/rpc/test_fallback_provider.py b/tests/rpc/test_fallback_provider.py index 7f08a73c..2b303cb3 100644 --- a/tests/rpc/test_fallback_provider.py +++ b/tests/rpc/test_fallback_provider.py @@ -90,7 +90,7 @@ def test_fallback_double_fault(fallback_provider: FallbackProvider, provider_1, with pytest.raises(requests.exceptions.ConnectionError): web3.eth.block_number - assert fallback_provider.retry_count == 5 + assert fallback_provider.retry_count == 6 def test_fallback_double_fault_recovery(fallback_provider: FallbackProvider, provider_1, provider_2): @@ -137,13 +137,13 @@ def test_fallback_nonce_too_low(web3, deployer: str): user = Account.create() hot_wallet = HotWallet(user) - tx1_hash = web3.eth.send_transaction({"from": deployer, "to": user.address, "value": 5*10**18}) + tx1_hash = web3.eth.send_transaction({"from": deployer, "to": user.address, "value": 5 * 10**18}) assert_transaction_success_with_explanation(web3, tx1_hash) hot_wallet.sync_nonce(web3) # First send a transaction with a correct nonce - tx2 = {"chainId": web3.eth.chain_id, "from": user.address, "to": deployer, "value": 1*10**18, "gas": 30_000} + tx2 = {"chainId": web3.eth.chain_id, "from": user.address, "to": deployer, "value": 1 * 10**18, "gas": 30_000} HotWallet.fill_in_gas_price(web3, tx2) signed_tx2 = hot_wallet.sign_transaction_with_new_nonce(tx2) assert signed_tx2.nonce == 0 @@ -157,7 +157,7 @@ def test_fallback_nonce_too_low(web3, deployer: str): # Then send a transaction with too low nonce. # We are not interested that the transaction goes thru, only # that it is retried. - tx3 = {"chainId": web3.eth.chain_id, "from": user.address, "to": deployer, "value": 1*10**18, "gas": 30_000} + tx3 = {"chainId": web3.eth.chain_id, "from": user.address, "to": deployer, "value": 1 * 10**18, "gas": 30_000} HotWallet.fill_in_gas_price(web3, tx3) hot_wallet.current_nonce = 0 # Spoof nonce signed_tx3 = hot_wallet.sign_transaction_with_new_nonce(tx3) @@ -167,4 +167,4 @@ def test_fallback_nonce_too_low(web3, deployer: str): # nonce too low happens during RPC call tx3_hash = web3.eth.send_raw_transaction(signed_tx3.rawTransaction) - assert fallback_provider.api_retry_counts[0]["eth_sendRawTransaction"] == 3 # 5 attempts, 3 retries, the last retry does not count + assert fallback_provider.api_retry_counts[0]["eth_sendRawTransaction"] == 3 # 5 attempts, 3 retries, the last retry does not count