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

Commit

Permalink
Merge pull request #1411 from ethcore/sync
Browse files Browse the repository at this point in the history
Sync: Update highest block for progress reporting
  • Loading branch information
NikVolf authored Jun 24, 2016
2 parents 416781a + e77cce6 commit 54fc5a5
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions sync/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,9 @@ impl ChainSync {
let h = header_rlp.as_raw().sha3();
trace!(target: "sync", "{} -> NewBlock ({})", peer_id, h);
let header: BlockHeader = try!(header_rlp.as_val());
if header.number() > self.highest_block.unwrap_or(0) {
self.highest_block = Some(header.number());
}
let mut unknown = false;
{
let peer = self.peers.get_mut(&peer_id).unwrap();
Expand Down Expand Up @@ -587,6 +590,10 @@ impl ChainSync {
fn on_peer_new_hashes(&mut self, io: &mut SyncIo, peer_id: PeerId, r: &UntrustedRlp) -> Result<(), PacketDecodeError> {
if self.state != SyncState::Idle {
trace!(target: "sync", "Ignoring new hashes since we're already downloading.");
let max = r.iter().take(MAX_NEW_HASHES).map(|item| item.val_at::<BlockNumber>(1).unwrap_or(0)).fold(0u64, max);
if max > self.highest_block.unwrap_or(0) {
self.highest_block = Some(max);
}
return Ok(());
}
trace!(target: "sync", "{} -> NewHashes ({} entries)", peer_id, r.item_count());
Expand All @@ -596,6 +603,9 @@ impl ChainSync {
for (rh, rd) in hashes {
let h = try!(rh);
let d = try!(rd);
if d > self.highest_block.unwrap_or(0) {
self.highest_block = Some(d);
}
if self.blocks.is_downloading(&h) {
continue;
}
Expand Down

0 comments on commit 54fc5a5

Please sign in to comment.