From a06fd1e011a7738774ba6e7f35321a8c07e979cd Mon Sep 17 00:00:00 2001 From: Sam Wilson Date: Tue, 15 Oct 2024 11:23:50 -0400 Subject: [PATCH] Don't double RLP decode block timestamp; better logs --- src/ethereum_spec_tools/sync.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/ethereum_spec_tools/sync.py b/src/ethereum_spec_tools/sync.py index 353aa1d277..7aba21cf73 100644 --- a/src/ethereum_spec_tools/sync.py +++ b/src/ethereum_spec_tools/sync.py @@ -95,13 +95,13 @@ def set_block(self, block_number: Uint, block_timestamp: U256) -> None: def advance_block(self, timestamp: U256) -> bool: """Increment the block number, return `True` if the fork changed.""" self.block_number += Uint(1) - if self.next_fork is not None and self.next_fork.has_activated( + new_fork = False + while self.next_fork is not None and self.next_fork.has_activated( self.block_number, timestamp ): self.active_fork_index += 1 - return True - else: - return False + new_fork = True + return new_fork class BlockDownloader(ForkTracking): @@ -278,11 +278,22 @@ def fetch_blocks_debug( assert not isinstance(decoded_block, bytes) assert not isinstance(decoded_block[0], bytes) assert isinstance(decoded_block[0][11], bytes) - timestamp = rlp.decode_to(U256, decoded_block[0][11]) + timestamp = U256.from_be_bytes(decoded_block[0][11]) self.advance_block(timestamp) - blocks.append( - rlp.decode_to(self.module("blocks").Block, block_rlp) - ) + try: + blocks.append( + rlp.decode_to( + self.module("blocks").Block, block_rlp + ) + ) + except Exception: + self.log.exception( + "failed to decode block %d with timestamp %d", + self.block_number, + timestamp, + ) + raise + return blocks def load_transaction(self, t: Any) -> Any: