add more tests when bad node participarting in syncing

pull/110/head
Minh Doan 6 years ago
parent fa3729ffb5
commit 7870edae6f
  1. 19
      syncing/syncing.go

@ -171,6 +171,14 @@ func (syncConfig *SyncConfig) GetHowManyMaxConsensus() (int, int) {
return maxFirstID, maxCount
}
// InitForTesting used for testing.
func (syncConfig *SyncConfig) InitForTesting(client *downloader.Client, blockHashes [][]byte) {
for i := range syncConfig.peers {
syncConfig.peers[i].blockHashes = blockHashes
syncConfig.peers[i].client = client
}
}
// CleanUpPeers cleans up all peers whose blockHashes are not equal to consensus block hashes.
func (syncConfig *SyncConfig) CleanUpPeers(maxFirstID int) {
fixedPeer := syncConfig.peers[maxFirstID]
@ -187,12 +195,16 @@ func (syncConfig *SyncConfig) CleanUpPeers(maxFirstID int) {
}
}
// getBlockHashesConsensusAndCleanUp chesk if all consensus hashes are equal.
func (ss *StateSync) getBlockHashesConsensusAndCleanUp() bool {
// GetBlockHashesConsensusAndCleanUp chesk if all consensus hashes are equal.
func (ss *StateSync) GetBlockHashesConsensusAndCleanUp() bool {
// Sort all peers by the blockHashes.
sort.Slice(ss.syncConfig.peers, func(i, j int) bool {
return CompareSyncPeerConfigByblockHashes(ss.syncConfig.peers[i], ss.syncConfig.peers[j]) == -1
})
<<<<<<< HEAD
=======
>>>>>>> add more tests when bad node participarting in syncing
maxFirstID, maxCount := ss.syncConfig.GetHowManyMaxConsensus()
if float64(maxCount) >= ConsensusRatio*float64(ss.activePeerNumber) {
ss.syncConfig.CleanUpPeers(maxFirstID)
@ -202,6 +214,7 @@ func (ss *StateSync) getBlockHashesConsensusAndCleanUp() bool {
return false
}
<<<<<<< HEAD
// InitForTesting used for testing.
func (syncConfig *SyncConfig) InitForTesting(client *downloader.Client, blockHashes [][]byte) {
for i := range syncConfig.peers {
@ -226,6 +239,8 @@ func (ss *StateSync) GetBlockHashesConsensusAndCleanUp() bool {
return false
}
=======
>>>>>>> add more tests when bad node participarting in syncing
// GetConsensusHashes gets all hashes needed to download.
func (ss *StateSync) GetConsensusHashes() {
for {

Loading…
Cancel
Save