From 59bbeff1c1fac5508e95324cea90f4b5d1ade579 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20F=C3=BCrderer?= Date: Sun, 22 Mar 2026 20:41:53 +0100 Subject: [PATCH] Improve the block transfer logic - Fix a bug where the blockchain could not be synced completely when block transfers happened in parallel - Sum up multiple received blocks in the log output --- node.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/node.py b/node.py index 5cf7149..3b855b8 100755 --- a/node.py +++ b/node.py @@ -198,6 +198,7 @@ def transfer_block(addr, node, receive_observer, b): if existing_block is not None: if existing_block.valid: break + block_list.append(request_block_hash) request_block_hash = existing_block.previous_hash if request_block_hash == 32*b"\0": break @@ -212,11 +213,16 @@ def transfer_block(addr, node, receive_observer, b): request_block_hash = b.get_block(block_hash).previous_hash if request_block_hash == 32*b"\0": break + new_block_count = 0 for block_hash in reversed(block_list): if not b.get_block(block_hash).validate(b): - return + break if b.set_latest_block(block_hash): - log("Got a new block") + new_block_count += 1 + if new_block_count == 1: + log("Got a new block") + elif new_block_count > 1: + log(f"Got {new_block_count} new blocks") except NoReponseException: pass