Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Restart sync if no more peers with snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
arkpar committed Oct 31, 2016
1 parent d086251 commit aff752b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions sync/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,10 +1047,6 @@ impl ChainSync {

/// Resume downloading
fn continue_sync(&mut self, io: &mut SyncIo) {
if (self.state == SyncState::Blocks || self.state == SyncState::NewBlocks || self.state == SyncState::Idle)
&& !self.peers.values().any(|p| p.asking != PeerAsking::Nothing && p.block_set != Some(BlockSet::OldBlocks) && p.can_sync()) {
self.complete_sync(io);
}
let mut peers: Vec<(PeerId, U256, u8)> = self.peers.iter().filter_map(|(k, p)|
if p.can_sync() { Some((*k, p.difficulty.unwrap_or_else(U256::zero), p.protocol_version)) } else { None }).collect();
thread_rng().shuffle(&mut peers); //TODO: sort by rating
Expand All @@ -1062,6 +1058,11 @@ impl ChainSync {
self.sync_peer(io, p, false);
}
}
if (self.state != SyncState::WaitingPeers && self.state != SyncState::SnapshotWaiting && self.state != SyncState::Waiting && self.state != SyncState::Idle)
&& !self.peers.values().any(|p| p.asking != PeerAsking::Nothing && p.block_set != Some(BlockSet::OldBlocks) && p.can_sync()) {

self.complete_sync(io);
}
}

/// Called after all blocks have been downloaded
Expand Down

0 comments on commit aff752b

Please sign in to comment.