From c8b9d1a2c03058f93e2014b30f3351a2ba9fe782 Mon Sep 17 00:00:00 2001 From: chengtx01 Date: Tue, 23 May 2023 17:49:35 +0800 Subject: [PATCH] fix(net):fix the issue of repeated request blocks --- .../org/tron/core/net/messagehandler/BlockMsgHandler.java | 1 + .../java/org/tron/core/net/service/sync/SyncService.java | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/framework/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java b/framework/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java index 6613ebfc581..9bb746346a6 100644 --- a/framework/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java +++ b/framework/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java @@ -67,6 +67,7 @@ public void processMessage(PeerConnection peer, TronMessage msg) throws P2pExcep if (peer.getSyncBlockRequested().containsKey(blockId)) { peer.getSyncBlockRequested().remove(blockId); + peer.getSyncBlockInProcess().add(blockId); syncService.processBlock(peer, blockMessage); } else { Item item = new Item(blockId, InventoryType.BLOCK); diff --git a/framework/src/main/java/org/tron/core/net/service/sync/SyncService.java b/framework/src/main/java/org/tron/core/net/service/sync/SyncService.java index 9476b32fa46..eef6c7efc88 100644 --- a/framework/src/main/java/org/tron/core/net/service/sync/SyncService.java +++ b/framework/src/main/java/org/tron/core/net/service/sync/SyncService.java @@ -225,7 +225,8 @@ private void startFetchSyncBlock() { send.put(peer, new LinkedList<>()); } for (BlockId blockId : peer.getSyncBlockToFetch()) { - if (requestBlockIds.getIfPresent(blockId) == null) { + if (requestBlockIds.getIfPresent(blockId) == null + && !peer.getSyncBlockInProcess().contains(blockId)) { requestBlockIds.put(blockId, peer); peer.getSyncBlockRequested().put(blockId, System.currentTimeMillis()); send.get(peer).add(blockId); @@ -266,6 +267,7 @@ private synchronized void handleSyncBlock() { } if (msg.getBlockId().getNum() <= solidNum) { blockWaitToProcess.remove(msg); + peerConnection.getSyncBlockInProcess().remove(msg.getBlockId()); return; } final boolean[] isFound = {false}; @@ -278,6 +280,7 @@ private synchronized void handleSyncBlock() { blockWaitToProcess.remove(msg); isProcessed[0] = true; processSyncBlock(msg.getBlockCapsule(), peerConnection); + peerConnection.getSyncBlockInProcess().remove(msg.getBlockId()); } } });