2121import org .tron .common .utils .Pair ;
2222import org .tron .core .capsule .BlockCapsule ;
2323import org .tron .core .capsule .BlockCapsule .BlockId ;
24- import org .tron .core .config .Parameter .NetConstants ;
2524import org .tron .core .config .args .Args ;
2625import org .tron .core .exception .P2pException ;
2726import org .tron .core .exception .P2pException .TypeEnum ;
@@ -65,6 +64,8 @@ public class SyncService {
6564 @ Setter
6665 private volatile boolean fetchFlag = false ;
6766
67+ private final long syncFetchBatchNum = Args .getInstance ().getSyncFetchBatchNum ();
68+
6869 public void init () {
6970 fetchExecutor .scheduleWithFixedDelay (() -> {
7071 try {
@@ -132,7 +133,7 @@ public void processBlock(PeerConnection peer, BlockMessage blockMessage) {
132133 handleFlag = true ;
133134 if (peer .isIdle ()) {
134135 if (peer .getRemainNum () > 0
135- && peer .getSyncBlockToFetch ().size () <= NetConstants . SYNC_FETCH_BATCH_NUM ) {
136+ && peer .getSyncBlockToFetch ().size () <= syncFetchBatchNum ) {
136137 syncNext (peer );
137138 } else {
138139 fetchFlag = true ;
@@ -250,6 +251,7 @@ private synchronized void handleSyncBlock() {
250251 }
251252
252253 final boolean [] isProcessed = {true };
254+ long solidNum = tronNetDelegate .getSolidBlockId ().getNum ();
253255
254256 while (isProcessed [0 ]) {
255257
@@ -262,6 +264,10 @@ private synchronized void handleSyncBlock() {
262264 invalid (msg .getBlockId (), peerConnection );
263265 return ;
264266 }
267+ if (msg .getBlockId ().getNum () <= solidNum ) {
268+ blockWaitToProcess .remove (msg );
269+ return ;
270+ }
265271 final boolean [] isFound = {false };
266272 tronNetDelegate .getActivePeer ().stream ()
267273 .filter (peer -> msg .getBlockId ().equals (peer .getSyncBlockToFetch ().peek ()))
0 commit comments