check if block is known before re-importing (#161)

This commit is contained in:
Robert Habermeier
2018-05-15 10:26:55 +02:00
committed by Gav Wood
parent 8bfded8d72
commit 413ebf3f19
2 changed files with 12 additions and 1 deletions
-1
View File
@@ -289,7 +289,6 @@ impl<B, E> Client<B, E> where
body: Option<block::Body>,
) -> error::Result<ImportResult> {
// TODO: import lock
// TODO: validate block
// TODO: import justification.
let (header, justification) = header.into_inner();
match self.backend.blockchain().status(BlockId::Hash(header.parent_hash))? {
+12
View File
@@ -230,6 +230,18 @@ impl ChainSync {
let hash = header_hash(&header);
let parent = header.parent_hash;
let is_best = best_seen.as_ref().map_or(false, |n| number >= *n);
// check whether the block is known before importing.
match protocol.chain().block_status(&BlockId::Hash(hash)) {
Ok(BlockStatus::InChain) => continue,
Ok(_) => {},
Err(e) => {
debug!(target: "sync", "Error importing block {}: {:?}: {:?}", number, hash, e);
self.restart(io, protocol);
return;
}
}
let result = protocol.chain().import(
is_best,
header,