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

Commit

Permalink
Allow old blocks from peers with lower difficulty (#9226)
Browse files Browse the repository at this point in the history
Previously we only allow downloading of old blocks if the peer
difficulty was greater than our syncing difficulty. This change allows
downloading of blocks from peers where the difficulty is greater then
the last downloaded old block.
  • Loading branch information
ascjones authored and 5chdn committed Aug 23, 2018
1 parent 87aa22f commit 417d907
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions ethcore/sync/src/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,14 +761,24 @@ impl ChainSync {
}
}

// Only ask for old blocks if the peer has a higher difficulty
if force || higher_difficulty {
// Only ask for old blocks if the peer has a higher difficulty than the last imported old block
let last_imported_old_block_difficulty = self.old_blocks.as_mut().and_then(|d| {
io.chain().block_total_difficulty(BlockId::Number(d.last_imported_block_number()))
});

if force || last_imported_old_block_difficulty.map_or(true, |ld| peer_difficulty.map_or(true, |pd| pd > ld)) {
if let Some(request) = self.old_blocks.as_mut().and_then(|d| d.request_blocks(io, num_active_peers)) {
SyncRequester::request_blocks(self, io, peer_id, request, BlockSet::OldBlocks);
return;
}
} else {
trace!(target: "sync", "peer {} is not suitable for asking old blocks", peer_id);
trace!(
target: "sync",
"peer {:?} is not suitable for requesting old blocks, last_imported_old_block_difficulty={:?}, peer_difficulty={:?}",
peer_id,
last_imported_old_block_difficulty,
peer_difficulty
);
self.deactivate_peer(io, peer_id);
}
},
Expand Down

0 comments on commit 417d907

Please sign in to comment.