Skip to content

Commit

Permalink
Merge pull request #5234 from chengtx01/optimize_sync
Browse files Browse the repository at this point in the history
fix(net):optimize sync service
  • Loading branch information
jwrct authored May 24, 2023
2 parents dcf8982 + c8b9d1a commit ad1a1b3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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};
Expand All @@ -278,6 +280,7 @@ private synchronized void handleSyncBlock() {
blockWaitToProcess.remove(msg);
isProcessed[0] = true;
processSyncBlock(msg.getBlockCapsule(), peerConnection);
peerConnection.getSyncBlockInProcess().remove(msg.getBlockId());
}
}
});
Expand Down

0 comments on commit ad1a1b3

Please sign in to comment.