handle queue import errors a bit more gracefully (#8385)

This commit is contained in:
Robert Habermeier 2018-04-13 14:06:22 +02:00 committed by GitHub
parent bc2f5586ee
commit 869fa6fda8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -427,6 +427,8 @@ impl<L: AsLightClient> LightSync<L> {
// handles request dispatch, block import, state machine transitions, and timeouts. // handles request dispatch, block import, state machine transitions, and timeouts.
fn maintain_sync(&self, ctx: &BasicContext) { fn maintain_sync(&self, ctx: &BasicContext) {
use ethcore::error::{BlockImportError, ImportError};
const DRAIN_AMOUNT: usize = 128; const DRAIN_AMOUNT: usize = 128;
let client = self.client.as_light_client(); let client = self.client.as_light_client();
@ -453,7 +455,15 @@ impl<L: AsLightClient> LightSync<L> {
trace!(target: "sync", "Drained {} headers to import", sink.len()); trace!(target: "sync", "Drained {} headers to import", sink.len());
for header in sink.drain(..) { for header in sink.drain(..) {
if let Err(e) = client.queue_header(header) { match client.queue_header(header) {
Ok(_) => {}
Err(BlockImportError::Import(ImportError::AlreadyInChain)) => {
trace!(target: "sync", "Block already in chain. Continuing.");
},
Err(BlockImportError::Import(ImportError::AlreadyQueued)) => {
trace!(target: "sync", "Block already queued. Continuing.");
},
Err(e) => {
debug!(target: "sync", "Found bad header ({:?}). Reset to search state.", e); debug!(target: "sync", "Found bad header ({:?}). Reset to search state.", e);
self.begin_search(&mut state); self.begin_search(&mut state);
@ -462,6 +472,7 @@ impl<L: AsLightClient> LightSync<L> {
} }
} }
} }
}
// handle state transitions. // handle state transitions.
{ {