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

Make sure parent block is not in importing queue when importing ancient blocks #10138

Merged
merged 9 commits into from
Jan 9, 2019
12 changes: 12 additions & 0 deletions ethcore/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ use state::{self, State};
use state_db::StateDB;
use trace::{self, TraceDB, ImportRequest as TraceImportRequest, LocalizedTrace, Database as TraceDatabase};
use transaction_ext::Transaction;
use verification::queue::Status as QueueStatus;
use verification::queue::kind::BlockLike;
use verification::queue::kind::blocks::Unverified;
use verification::{PreverifiedBlock, Verifier, BlockQueue};
Expand Down Expand Up @@ -2191,6 +2192,13 @@ impl IoClient for Client {
let first = queued.write().1.pop_front();
if let Some((unverified, receipts_bytes)) = first {
let hash = unverified.hash();
let parent_hash = unverified.parent_hash();
let status = client.importer.block_queue.status(&parent_hash);
ascjones marked this conversation as resolved.
Show resolved Hide resolved
ascjones marked this conversation as resolved.
Show resolved Hide resolved

if status == QueueStatus::Queued {
break;
}

let result = client.importer.import_old_block(
unverified,
&receipts_bytes,
Expand All @@ -2199,6 +2207,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();
ascjones marked this conversation as resolved.
Show resolved Hide resolved
}
// remove from pending
queued.write().0.remove(&hash);
Expand Down
1 change: 1 addition & 0 deletions ethcore/src/verification/queue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ impl<K: Kind> HeapSizeOf for Verifying<K> {
}

/// Status of items in the queue.
#[derive(PartialEq, Eq)]
pub enum Status {
/// Currently queued.
Queued,
Expand Down