Make GetBlockHashesConsensusAndCleanUp a SyncConfig method

This is possible because we have eliminated peer count variables in
StateSync.
pull/686/head
Eugene Kim 6 years ago
parent d9eb985c36
commit 4011ede7ea
  1. 14
      api/service/syncing/syncing.go

@ -239,15 +239,15 @@ func (syncConfig *SyncConfig) CleanUpPeers(maxFirstID int) {
} }
// GetBlockHashesConsensusAndCleanUp chesk if all consensus hashes are equal. // GetBlockHashesConsensusAndCleanUp chesk if all consensus hashes are equal.
func (ss *StateSync) GetBlockHashesConsensusAndCleanUp() bool { func (sc *SyncConfig) GetBlockHashesConsensusAndCleanUp() bool {
// Sort all peers by the blockHashes. // Sort all peers by the blockHashes.
sort.Slice(ss.syncConfig.peers, func(i, j int) bool { sort.Slice(sc.peers, func(i, j int) bool {
return CompareSyncPeerConfigByblockHashes(ss.syncConfig.peers[i], ss.syncConfig.peers[j]) == -1 return CompareSyncPeerConfigByblockHashes(sc.peers[i], sc.peers[j]) == -1
}) })
maxFirstID, maxCount := ss.syncConfig.GetHowManyMaxConsensus() maxFirstID, maxCount := sc.GetHowManyMaxConsensus()
utils.GetLogInstance().Info("[SYNC] block consensus hashes", "maxFirstID", maxFirstID, "maxCount", maxCount) utils.GetLogInstance().Info("[SYNC] block consensus hashes", "maxFirstID", maxFirstID, "maxCount", maxCount)
if float64(maxCount) >= ConsensusRatio*float64(len(ss.syncConfig.peers)) { if float64(maxCount) >= ConsensusRatio*float64(len(sc.peers)) {
ss.syncConfig.CleanUpPeers(maxFirstID) sc.CleanUpPeers(maxFirstID)
return true return true
} }
return false return false
@ -270,7 +270,7 @@ func (ss *StateSync) GetConsensusHashes(startHash []byte) bool {
}(ss.syncConfig.peers[id]) }(ss.syncConfig.peers[id])
} }
wg.Wait() wg.Wait()
if ss.GetBlockHashesConsensusAndCleanUp() { if ss.syncConfig.GetBlockHashesConsensusAndCleanUp() {
break break
} }
if count > TimesToFail { if count > TimesToFail {

Loading…
Cancel
Save