fix: wait_for_min_peers shouldn't wait forever when all peers are in same work (#2340)

This commit is contained in:
Gary Yu
2019-01-12 07:38:27 +08:00
committed by GitHub
parent 1a6b46b09d
commit 7698b28e16
2 changed files with 21 additions and 5 deletions
+5 -5
View File
@@ -77,18 +77,18 @@ impl SyncRunner {
let mut n = 0;
const MIN_PEERS: usize = 3;
loop {
let wp = self.peers.more_work_peers();
let wp = self.peers.more_or_same_work_peers();
// exit loop when:
// * we have more than MIN_PEERS more_work peers
// * we have more than MIN_PEERS more_or_same_work peers
// * we are synced already, e.g. grin was quickly restarted
// * timeout
if wp.len() > MIN_PEERS
|| (wp.len() == 0
if wp > MIN_PEERS
|| (wp == 0
&& self.peers.enough_peers()
&& head.total_difficulty > Difficulty::zero())
|| n > wait_secs
{
if wp.len() > 0 || !global::is_production_mode() {
if wp > 0 || !global::is_production_mode() {
break;
}
}