Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ethcore/light/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl<T: ChainDataFetcher> Client<T> {

/// Import a header to the queue for additional verification.
pub fn import_header(&self, header: Header) -> EthcoreResult<H256> {
self.queue.import(header).map_err(Into::into)
self.queue.import(header).map_err(|(_, e)| e)
}

/// Inquire about the status of a given header.
Expand Down
7 changes: 3 additions & 4 deletions ethcore/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1405,15 +1405,14 @@ impl ImportBlock for Client {
bail!(EthcoreErrorKind::Block(BlockError::UnknownParent(unverified.parent_hash())));
}

let raw = unverified.bytes.clone();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant block 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), _)))=> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: space before =>

self.importer.bad_blocks.report(block.bytes, format!("{:?}", err));
bail!(EthcoreErrorKind::Block(err))
},
Err(e) => Err(e),
Err((_, e)) => Err(e),
}
}
}
Expand Down
15 changes: 9 additions & 6 deletions ethcore/src/verification/queue/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self::Unverified, Error>;
fn create(input: Self::Input, engine: &EthEngine, check_seal: bool) -> Result<Self::Unverified, (Self::Input, Error)>;

/// Attempt to verify the `Unverified` item using the given engine.
fn verify(unverified: Self::Unverified, engine: &EthEngine, check_seal: bool) -> Result<Self::Verified, Error>;
Expand Down Expand Up @@ -86,16 +86,16 @@ pub mod blocks {
type Unverified = Unverified;
type Verified = PreverifiedBlock;

fn create(input: Self::Input, engine: &EthEngine, check_seal: bool) -> Result<Self::Unverified, Error> {
fn create(input: Self::Input, engine: &EthEngine, check_seal: bool) -> Result<Self::Unverified, (Self::Input, Error)> {
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))
}
}
}
Expand Down Expand Up @@ -209,8 +209,11 @@ pub mod headers {
type Unverified = Header;
type Verified = Header;

fn create(input: Self::Input, engine: &EthEngine, _check_seal: bool) -> Result<Self::Unverified, Error> {
verify_header_params(&input, engine, true).map(|_| input)
fn create(input: Self::Input, engine: &EthEngine, _check_seal: bool) -> Result<Self::Unverified, (Self::Input, Error)> {
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<Self::Verified, Error> {
Expand Down
16 changes: 8 additions & 8 deletions ethcore/src/verification/queue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -469,21 +469,21 @@ impl<K: Kind> VerificationQueue<K> {
}

/// Add a block to the queue.
pub fn import(&self, input: K::Input) -> EthcoreResult<H256> {
pub fn import(&self, input: K::Input) -> Result<H256, (K::Input, Error)> {
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()));
}
}

Expand All @@ -500,15 +500,15 @@ impl<K: Kind> VerificationQueue<K> {
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(_)), _) => {},
_ => {
self.verification.bad.lock().insert(hash);
}
}
Err(err)
Err((input, err))
}
}
}
Expand Down Expand Up @@ -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"); }
Expand Down