Skip to content

Commit

Permalink
Don't double RLP decode block timestamp; better logs
Browse files Browse the repository at this point in the history
  • Loading branch information
SamWilsn committed Oct 15, 2024
1 parent 3282ee5 commit a06fd1e
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/ethereum_spec_tools/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit a06fd1e

Please sign in to comment.