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,10 +251,12 @@ private synchronized void handleSyncBlock() {
250251 }
251252
252253 final boolean [] isProcessed = {true };
254+ final long [] solidNum = {0 };
253255
254256 while (isProcessed [0 ]) {
255257
256258 isProcessed [0 ] = false ;
259+ solidNum [0 ] = tronNetDelegate .getSolidBlockId ().getNum ();
257260
258261 blockWaitToProcess .forEach ((msg , peerConnection ) -> {
259262 synchronized (tronNetDelegate .getBlockLock ()) {
@@ -262,6 +265,10 @@ private synchronized void handleSyncBlock() {
262265 invalid (msg .getBlockId (), peerConnection );
263266 return ;
264267 }
268+ if (msg .getBlockId ().getNum () <= solidNum [0 ]) {
269+ blockWaitToProcess .remove (msg );
270+ return ;
271+ }
265272 final boolean [] isFound = {false };
266273 tronNetDelegate .getActivePeer ().stream ()
267274 .filter (peer -> msg .getBlockId ().equals (peer .getSyncBlockToFetch ().peek ()))
0 commit comments