Skip to content

Commit e7c82d1

Browse files
committed
Merge branch 'develop' into feature/add_TVMNewCommand_stest_back
2 parents 04bb609 + 45454c3 commit e7c82d1

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

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

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -230,26 +230,28 @@ private synchronized void handleSyncBlock() {
230230

231231
isProcessed[0] = false;
232232

233-
blockWaitToProcess.forEach((msg, peerConnection) -> {
234-
if (peerConnection.isDisconnect()) {
235-
blockWaitToProcess.remove(msg);
236-
invalid(msg.getBlockId());
237-
return;
238-
}
239-
final boolean[] isFound = {false};
240-
tronNetDelegate.getActivePeer().stream()
241-
.filter(peer -> msg.getBlockId().equals(peer.getSyncBlockToFetch().peek()))
242-
.forEach(peer -> {
243-
peer.getSyncBlockToFetch().pop();
244-
peer.getSyncBlockInProcess().add(msg.getBlockId());
245-
isFound[0] = true;
246-
});
247-
if (isFound[0]) {
248-
blockWaitToProcess.remove(msg);
249-
isProcessed[0] = true;
250-
processSyncBlock(msg.getBlockCapsule());
251-
}
252-
});
233+
synchronized (tronNetDelegate.getBlockLock()) {
234+
blockWaitToProcess.forEach((msg, peerConnection) -> {
235+
if (peerConnection.isDisconnect()) {
236+
blockWaitToProcess.remove(msg);
237+
invalid(msg.getBlockId());
238+
return;
239+
}
240+
final boolean[] isFound = {false};
241+
tronNetDelegate.getActivePeer().stream()
242+
.filter(peer -> msg.getBlockId().equals(peer.getSyncBlockToFetch().peek()))
243+
.forEach(peer -> {
244+
peer.getSyncBlockToFetch().pop();
245+
peer.getSyncBlockInProcess().add(msg.getBlockId());
246+
isFound[0] = true;
247+
});
248+
if (isFound[0]) {
249+
blockWaitToProcess.remove(msg);
250+
isProcessed[0] = true;
251+
processSyncBlock(msg.getBlockCapsule());
252+
}
253+
});
254+
}
253255
}
254256
}
255257

0 commit comments

Comments
 (0)