From 90d6440c5a09bf2bd33425e78b3b5faf925e1c00 Mon Sep 17 00:00:00 2001 From: tim Date: Mon, 10 Feb 2025 21:55:01 -0400 Subject: [PATCH] rpc connection bugfix --- src/dexorder/blockchain/connection.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/dexorder/blockchain/connection.py b/src/dexorder/blockchain/connection.py index 512ee5c..e5b170d 100644 --- a/src/dexorder/blockchain/connection.py +++ b/src/dexorder/blockchain/connection.py @@ -206,17 +206,22 @@ async def archive_intercept_middleware(make_request, w3): # Only intercept relevant methods expected_args = ARCHIVE_METHODS.get(method,-1) is_archive_method = len(params) == expected_args + block_height = None if is_archive_method: block_identifier = params[-1] - block_identifier = int(block_identifier, 16) if type(block_identifier) is str else int(params[-1]) # we don't expect hex strings - if block_identifier <= w3.archive_fault_height: - # this block is at least as old as another block that already failed to fetch history from this RPC - raise ArchiveException(method, block_identifier) + if block_identifier != 'latest': + block_identifier = int(block_identifier, 16) if type(block_identifier) is str else int(params[-1]) + if block_identifier <= w3.archive_fault_height: + # this block is at least as old as another block that already failed to fetch history from this RPC + raise ArchiveException(method, block_identifier) resp = await make_request(method, params) if is_archive_method and 'error' in resp and resp['error']['code'] in ARCHIVE_ERRORS: - # noinspection PyUnboundLocalVariable - w3.archive_fault_height = max(w3.archive_fault_height, block_identifier) - raise ArchiveException(method, block_identifier) + if block_height is None: + # noinspection PyUnboundLocalVariable + raise Exception(f'Got an archive fault using a block_identifier of {block_identifier}') + # noinspection PyTypeChecker + w3.archive_fault_height = max(w3.archive_fault_height, block_height) + raise ArchiveException(method, block_height) resp = await make_request(method, params) return resp @@ -305,7 +310,6 @@ class RetryHTTPProvider (AsyncHTTPProvider): try: async with self.in_flight: await self.rate_allowed.wait() - log.debug(f'Requesting RPC call {method}') return await super().make_request(method, params) except ClientResponseError as e: if e.status != 429: