Skip to content

Commit 3dc7662

Browse files
authored
Confirm the state of download finish if the whole network stuck (#770)
* confirm the state of download finish if the whole network stuck * reset the firstDownloadCounter when finding out they are not stuck * reduce the validation limit constant
1 parent d66b362 commit 3dc7662

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

core/blockchainsync/downloadBlockchain.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type (
3434
PeerExplorer strategy.PeerExplorerStrategyInterface
3535
Logger *log.Logger
3636
BlockchainStatusService service.BlockchainStatusServiceInterface
37+
firstDownloadCounter int32
3738
}
3839

3940
PeerBlockchainInfo struct {
@@ -75,10 +76,20 @@ func (bd *BlockchainDownloader) IsDownloadFinish(currentLastBlock *model.Block)
7576
return false
7677
}
7778
heightAfterDownload := afterDownloadLastBlock.Height
79+
// to avoid the network being start at the initial kick off / restart
80+
if currentHeight == heightAfterDownload {
81+
bd.firstDownloadCounter++
82+
if bd.firstDownloadCounter >= constant.MaxResolvedPeers {
83+
bd.firstDownloadCounter = 0
84+
return true
85+
}
86+
}
7887
cumulativeDifficultyAfterDownload := afterDownloadLastBlock.CumulativeDifficulty
7988
if currentHeight > 0 && currentHeight == heightAfterDownload && currentCumulativeDifficulty == cumulativeDifficultyAfterDownload {
89+
bd.firstDownloadCounter = 0
8090
return true
8191
}
92+
bd.firstDownloadCounter = 0
8293
return false
8394
}
8495

0 commit comments

Comments
 (0)