@@ -230,26 +230,28 @@ private synchronized void handleSyncBlock() {
230
230
231
231
isProcessed [0 ] = false ;
232
232
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
+ }
253
255
}
254
256
}
255
257
0 commit comments