Fixed sync stalling on fork

This commit is contained in:
arkpar 2016-02-04 13:16:31 +01:00
parent 280ef77f44
commit 77449140cd

View File

@ -322,13 +322,13 @@ impl ChainSync {
//validate chain //validate chain
let base_hash = self.last_imported_hash.clone().unwrap(); let base_hash = self.last_imported_hash.clone().unwrap();
if self.have_common_block && number == self.current_base_block() + 1 && info.parent_hash != base_hash { if self.have_common_block && number == self.current_base_block() + 1 && info.parent_hash != base_hash {
// TODO: lower peer rating // Part of the forked chain. Restart to find common block again
debug!(target: "sync", "Mismatched block header {} {}", number, hash); debug!(target: "sync", "Mismatched block header {} {}, restarting sync", number, hash);
continue; self.restart(io);
return Ok(());
} }
if self.headers.find_item(&(number - 1)).map_or(false, |p| p.hash != info.parent_hash) { if self.headers.find_item(&(number - 1)).map_or(false, |p| p.hash != info.parent_hash) {
// mismatching parent id, delete the previous block and don't add this one // mismatching parent id, delete the previous block and don't add this one
// TODO: lower peer rating
debug!(target: "sync", "Mismatched block header {} {}", number, hash); debug!(target: "sync", "Mismatched block header {} {}", number, hash);
self.remove_downloaded_blocks(number - 1); self.remove_downloaded_blocks(number - 1);
continue; continue;