From 010cfb7d677b6a200b0e32ff3cbd8cc7e3aa0818 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Wed, 9 Jan 2019 14:47:14 +0100 Subject: [PATCH] Make sure parent block is not in importing queue when importing ancient blocks (#10138) * Make sure parent block is not in importing queue when importing ancient blocks * Clear queue when an ancient import fails * Lock only once in clear * Add comments why queued check is needed * Should push the value back to the queue * Directly check in chain.read() * Remove extra empty line * Revert unused verification change --- ethcore/src/client/client.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 22a38ec55..995b11520 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -2165,11 +2165,8 @@ impl IoClient for Client { // NOTE To prevent race condition with import, make sure to check queued blocks first // (and attempt to acquire lock) let is_parent_pending = self.queued_ancient_blocks.read().0.contains(&parent_hash); - if !is_parent_pending { - let status = self.block_status(BlockId::Hash(parent_hash)); - if status == BlockStatus::Unknown { - bail!(EthcoreErrorKind::Block(BlockError::UnknownParent(parent_hash))); - } + if !is_parent_pending && !self.chain.read().is_known(&parent_hash) { + bail!(EthcoreErrorKind::Block(BlockError::UnknownParent(parent_hash))); } } @@ -2199,6 +2196,10 @@ impl IoClient for Client { ); if let Err(e) = result { error!(target: "client", "Error importing ancient block: {}", e); + + let mut queued = queued.write(); + queued.0.clear(); + queued.1.clear(); } // remove from pending queued.write().0.remove(&hash);