Skip to content

Commit c8b9d1a

Browse files
committed
fix(net):fix the issue of repeated request blocks
1 parent dcf8982 commit c8b9d1a

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

framework/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public void processMessage(PeerConnection peer, TronMessage msg) throws P2pExcep
6767

6868
if (peer.getSyncBlockRequested().containsKey(blockId)) {
6969
peer.getSyncBlockRequested().remove(blockId);
70+
peer.getSyncBlockInProcess().add(blockId);
7071
syncService.processBlock(peer, blockMessage);
7172
} else {
7273
Item item = new Item(blockId, InventoryType.BLOCK);

framework/src/main/java/org/tron/core/net/service/sync/SyncService.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ private void startFetchSyncBlock() {
225225
send.put(peer, new LinkedList<>());
226226
}
227227
for (BlockId blockId : peer.getSyncBlockToFetch()) {
228-
if (requestBlockIds.getIfPresent(blockId) == null) {
228+
if (requestBlockIds.getIfPresent(blockId) == null
229+
&& !peer.getSyncBlockInProcess().contains(blockId)) {
229230
requestBlockIds.put(blockId, peer);
230231
peer.getSyncBlockRequested().put(blockId, System.currentTimeMillis());
231232
send.get(peer).add(blockId);
@@ -266,6 +267,7 @@ private synchronized void handleSyncBlock() {
266267
}
267268
if (msg.getBlockId().getNum() <= solidNum) {
268269
blockWaitToProcess.remove(msg);
270+
peerConnection.getSyncBlockInProcess().remove(msg.getBlockId());
269271
return;
270272
}
271273
final boolean[] isFound = {false};
@@ -278,6 +280,7 @@ private synchronized void handleSyncBlock() {
278280
blockWaitToProcess.remove(msg);
279281
isProcessed[0] = true;
280282
processSyncBlock(msg.getBlockCapsule(), peerConnection);
283+
peerConnection.getSyncBlockInProcess().remove(msg.getBlockId());
281284
}
282285
}
283286
});

0 commit comments

Comments
 (0)