diff --git a/golem/ethereum/node.py b/golem/ethereum/node.py index f820fae35f..75e7172357 100644 --- a/golem/ethereum/node.py +++ b/golem/ethereum/node.py @@ -3,7 +3,7 @@ from typing import List -from web3 import Web3, HTTPProvider +from web3 import Web3 from golem.ethereum.web3.providers import ProviderProxy from golem.report import report_calls, Component diff --git a/golem/ethereum/web3/providers.py b/golem/ethereum/web3/providers.py index bf73c416c4..44b6e836dd 100644 --- a/golem/ethereum/web3/providers.py +++ b/golem/ethereum/web3/providers.py @@ -53,7 +53,7 @@ def make_request(self, method, params): 'GETH: request successful %s (%r, %r) -- result = %r', self.provider.endpoint_uri, method, params, response ) - except (ConnectionError, ValueError, + except (ConnectionError, socket.error, CannotHandleRequest) as exc: retries += 1 self._register_retry() @@ -91,8 +91,8 @@ def _create_remote_rpc_provider(self): def _handle_remote_rpc_provider_failure(self, method: str, final: bool): if final: raise Exception( - "GETH: Node limit exhausted, request failed. method='%s'", - method + "GETH: Node limit exhausted, request failed." + f" method='{method}'", ) logger.warning( "GETH: '%s' request failed on '%s', " diff --git a/tests/golem/ethereum/web3/test_providers.py b/tests/golem/ethereum/web3/test_providers.py index aca9666faf..7f4aaec9ef 100644 --- a/tests/golem/ethereum/web3/test_providers.py +++ b/tests/golem/ethereum/web3/test_providers.py @@ -1,3 +1,4 @@ +# pylint: disable=protected-access import datetime import time from unittest import TestCase @@ -11,6 +12,7 @@ SINGLE_QUERY_RETRY_LIMIT, ) + @patch('web3.providers.rpc.HTTPProvider') class TestProviders(TestCase): def setUp(self): @@ -50,6 +52,25 @@ def test_unrecoverable_errors(self, *_): SINGLE_QUERY_RETRY_LIMIT * len(self._nodes_list) ) + @patch( + 'golem.ethereum.web3.providers.HTTPProvider.make_request', + side_effect=ValueError({ + 'code': -32000, + 'message': 'missing trie node 32de5daba1d1013d41aca01c66772685576afb925779aa35d4d5a9de6e41d8c0 (path )', # noqa pylint: disable=line-too-long + }), + ) + def test_non_connection_error(self, *_): + result = None + with self.assertRaises(ValueError): + result = self.proxy.make_request("a", []) + + self.assertEqual(result, None) + self.proxy.provider.make_request.assert_called_once_with("a", []) + self.assertEqual( + self.proxy.provider.make_request.call_count, + 1, + ) + def test_first_retry(self, *_): with freezegun.freeze_time(datetime.datetime.utcnow()): now = time.time() @@ -73,7 +94,7 @@ def test_subsequent_distant_retry(self, *_): now = time.time() frt = now - RETRY_COUNT_INTERVAL - 1 self.proxy._first_retry_time = frt - self._retries = 2 + self.proxy._retries = 2 self.proxy._register_retry() self.assertEqual(self.proxy._first_retry_time, now)