From 6ff00e5d95aba4639bf9976dc9bb5f3951c98edd Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Mon, 14 May 2018 17:24:38 +0200 Subject: [PATCH] check if block is known before re-importing --- substrate/client/src/client.rs | 1 - substrate/network/src/sync.rs | 12 ++++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/substrate/client/src/client.rs b/substrate/client/src/client.rs index c0b16bf109903..967a24198d555 100644 --- a/substrate/client/src/client.rs +++ b/substrate/client/src/client.rs @@ -289,7 +289,6 @@ impl Client where body: Option, ) -> error::Result { // 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))? { diff --git a/substrate/network/src/sync.rs b/substrate/network/src/sync.rs index 395681efff136..9cef0cd021631 100644 --- a/substrate/network/src/sync.rs +++ b/substrate/network/src/sync.rs @@ -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,