diff --git a/ethcore/light/src/client/mod.rs b/ethcore/light/src/client/mod.rs index e97d92589..0ea8983b9 100644 --- a/ethcore/light/src/client/mod.rs +++ b/ethcore/light/src/client/mod.rs @@ -207,7 +207,7 @@ impl Client { /// Import a header to the queue for additional verification. pub fn import_header(&self, header: Header) -> EthcoreResult { - self.queue.import(header).map_err(Into::into) + self.queue.import(header).map_err(|(_, e)| e) } /// Inquire about the status of a given header. diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 0d3fb0781..a5a5a149e 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -1405,15 +1405,14 @@ impl ImportBlock for Client { bail!(EthcoreErrorKind::Block(BlockError::UnknownParent(unverified.parent_hash()))); } - let raw = unverified.bytes.clone(); match self.importer.block_queue.import(unverified) { Ok(res) => Ok(res), // we only care about block errors (not import errors) - Err(EthcoreError(EthcoreErrorKind::Block(err), _))=> { - self.importer.bad_blocks.report(raw, format!("{:?}", err)); + Err((block, EthcoreError(EthcoreErrorKind::Block(err), _))) => { + self.importer.bad_blocks.report(block.bytes, format!("{:?}", err)); bail!(EthcoreErrorKind::Block(err)) }, - Err(e) => Err(e), + Err((_, e)) => Err(e), } } } diff --git a/ethcore/src/verification/queue/kind.rs b/ethcore/src/verification/queue/kind.rs index c356d66ff..7d98aa943 100644 --- a/ethcore/src/verification/queue/kind.rs +++ b/ethcore/src/verification/queue/kind.rs @@ -58,7 +58,7 @@ pub trait Kind: 'static + Sized + Send + Sync { type Verified: Sized + Send + BlockLike + HeapSizeOf; /// Attempt to create the `Unverified` item from the input. - fn create(input: Self::Input, engine: &EthEngine, check_seal: bool) -> Result; + fn create(input: Self::Input, engine: &EthEngine, check_seal: bool) -> Result; /// Attempt to verify the `Unverified` item using the given engine. fn verify(unverified: Self::Unverified, engine: &EthEngine, check_seal: bool) -> Result; @@ -86,16 +86,16 @@ pub mod blocks { type Unverified = Unverified; type Verified = PreverifiedBlock; - fn create(input: Self::Input, engine: &EthEngine, check_seal: bool) -> Result { + fn create(input: Self::Input, engine: &EthEngine, check_seal: bool) -> Result { match verify_block_basic(&input, engine, check_seal) { Ok(()) => Ok(input), Err(Error(ErrorKind::Block(BlockError::TemporarilyInvalid(oob)), _)) => { debug!(target: "client", "Block received too early {}: {:?}", input.hash(), oob); - Err(BlockError::TemporarilyInvalid(oob).into()) + Err((input, BlockError::TemporarilyInvalid(oob).into())) }, Err(e) => { warn!(target: "client", "Stage 1 block verification failed for {}: {:?}", input.hash(), e); - Err(e) + Err((input, e)) } } } @@ -209,8 +209,11 @@ pub mod headers { type Unverified = Header; type Verified = Header; - fn create(input: Self::Input, engine: &EthEngine, _check_seal: bool) -> Result { - verify_header_params(&input, engine, true).map(|_| input) + fn create(input: Self::Input, engine: &EthEngine, _check_seal: bool) -> Result { + match verify_header_params(&input, engine, true) { + Ok(_) => Ok(input), + Err(err) => Err((input, err)) + } } fn verify(unverified: Self::Unverified, engine: &EthEngine, check_seal: bool) -> Result { diff --git a/ethcore/src/verification/queue/mod.rs b/ethcore/src/verification/queue/mod.rs index 2d5f50c5d..9b1597439 100644 --- a/ethcore/src/verification/queue/mod.rs +++ b/ethcore/src/verification/queue/mod.rs @@ -26,7 +26,7 @@ use heapsize::HeapSizeOf; use ethereum_types::{H256, U256}; use parking_lot::{Condvar, Mutex, RwLock}; use io::*; -use error::*; +use error::{BlockError, ImportErrorKind, ErrorKind, Error}; use engines::EthEngine; use client::ClientIoMessage; @@ -469,21 +469,21 @@ impl VerificationQueue { } /// Add a block to the queue. - pub fn import(&self, input: K::Input) -> EthcoreResult { + pub fn import(&self, input: K::Input) -> Result { let hash = input.hash(); { if self.processing.read().contains_key(&hash) { - bail!(ErrorKind::Import(ImportErrorKind::AlreadyQueued)); + bail!((input, ErrorKind::Import(ImportErrorKind::AlreadyQueued).into())); } let mut bad = self.verification.bad.lock(); if bad.contains(&hash) { - bail!(ErrorKind::Import(ImportErrorKind::KnownBad)); + bail!((input, ErrorKind::Import(ImportErrorKind::KnownBad).into())); } if bad.contains(&input.parent_hash()) { bad.insert(hash); - bail!(ErrorKind::Import(ImportErrorKind::KnownBad)); + bail!((input, ErrorKind::Import(ImportErrorKind::KnownBad).into())); } } @@ -500,7 +500,7 @@ impl VerificationQueue { self.more_to_verify.notify_all(); Ok(hash) }, - Err(err) => { + Err((input, err)) => { match err { // Don't mark future blocks as bad. Error(ErrorKind::Block(BlockError::TemporarilyInvalid(_)), _) => {}, @@ -508,7 +508,7 @@ impl VerificationQueue { self.verification.bad.lock().insert(hash); } } - Err(err) + Err((input, err)) } } } @@ -784,7 +784,7 @@ mod tests { let duplicate_import = queue.import(new_unverified(get_good_dummy_block())); match duplicate_import { - Err(e) => { + Err((_, e)) => { match e { Error(ErrorKind::Import(ImportErrorKind::AlreadyQueued), _) => {}, _ => { panic!("must return AlreadyQueued error"); }