From 7870edae6f406008594ca73cb43dd26085e1b6dd Mon Sep 17 00:00:00 2001 From: Minh Doan Date: Thu, 29 Nov 2018 14:29:04 -0800 Subject: [PATCH] add more tests when bad node participarting in syncing --- syncing/syncing.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/syncing/syncing.go b/syncing/syncing.go index 19bdc561f..759612604 100644 --- a/syncing/syncing.go +++ b/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 {