Skip to content

Commit

Permalink
CHIA-1087: log the rate at which blocks are added during long sync (#…
Browse files Browse the repository at this point in the history
…18442)

log the rate at which blocks are added during long sync
  • Loading branch information
arvidn authored Aug 14, 2024
1 parent 5df8e81 commit da01437
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion chia/full_node/full_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,9 @@ async def validate_block_batches(
) -> None:
fork_info: Optional[ForkInfo] = None

block_rate = 0
block_rate_time = time.monotonic()
block_rate_height = -1
while True:
res: Optional[Tuple[WSChiaConnection, List[FullBlock]]] = await inner_batch_queue.get()
if res is None:
Expand All @@ -1111,6 +1114,9 @@ async def validate_block_batches(
start_height = blocks[0].height
end_height = blocks[-1].height

if block_rate_height == -1:
block_rate_height = start_height

# in case we're validating a reorg fork (i.e. not extending the
# main chain), we need to record the coin set from that fork in
# fork_info. Otherwise validation is very expensive, especially
Expand Down Expand Up @@ -1142,7 +1148,13 @@ async def validate_block_batches(
if success is False:
await peer.close(600)
raise ValueError(f"Failed to validate block batch {start_height} to {end_height}")
self.log.info(f"Added blocks {start_height} to {end_height}")
if end_height - block_rate_height > 100:
now = time.monotonic()
block_rate = int((end_height - block_rate_height) // (now - block_rate_time))
block_rate_time = now
block_rate_height = end_height

self.log.info(f"Added blocks {start_height} to {end_height} ({block_rate} blocks/s)")
peak = self.blockchain.get_peak()
if state_change_summary is not None:
assert peak is not None
Expand Down

0 comments on commit da01437

Please sign in to comment.