removed redundant clone before each block import (#9683)

* removed redundant clone before each block import

* Fix a trival typo
This commit is contained in:
Marek Kotewicz 2018-10-03 18:44:58 +01:00 committed by Wei Tang
parent 911fc74346
commit 5a2f3e700b
4 changed files with 21 additions and 19 deletions

View File

@ -207,7 +207,7 @@ impl<T: ChainDataFetcher> Client<T> {
/// Import a header to the queue for additional verification. /// Import a header to the queue for additional verification.
pub fn import_header(&self, header: Header) -> EthcoreResult<H256> { 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. /// Inquire about the status of a given header.

View File

@ -1405,15 +1405,14 @@ impl ImportBlock for Client {
bail!(EthcoreErrorKind::Block(BlockError::UnknownParent(unverified.parent_hash()))); bail!(EthcoreErrorKind::Block(BlockError::UnknownParent(unverified.parent_hash())));
} }
let raw = unverified.bytes.clone();
match self.importer.block_queue.import(unverified) { match self.importer.block_queue.import(unverified) {
Ok(res) => Ok(res), Ok(res) => Ok(res),
// we only care about block errors (not import errors) // we only care about block errors (not import errors)
Err(EthcoreError(EthcoreErrorKind::Block(err), _))=> { Err((block, EthcoreError(EthcoreErrorKind::Block(err), _))) => {
self.importer.bad_blocks.report(raw, format!("{:?}", err)); self.importer.bad_blocks.report(block.bytes, format!("{:?}", err));
bail!(EthcoreErrorKind::Block(err)) bail!(EthcoreErrorKind::Block(err))
}, },
Err(e) => Err(e), Err((_, e)) => Err(e),
} }
} }
} }

View File

@ -58,7 +58,7 @@ pub trait Kind: 'static + Sized + Send + Sync {
type Verified: Sized + Send + BlockLike + HeapSizeOf; type Verified: Sized + Send + BlockLike + HeapSizeOf;
/// Attempt to create the `Unverified` item from the input. /// 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. /// Attempt to verify the `Unverified` item using the given engine.
fn verify(unverified: Self::Unverified, engine: &EthEngine, check_seal: bool) -> Result<Self::Verified, Error>; fn verify(unverified: Self::Unverified, engine: &EthEngine, check_seal: bool) -> Result<Self::Verified, Error>;
@ -86,16 +86,16 @@ pub mod blocks {
type Unverified = Unverified; type Unverified = Unverified;
type Verified = PreverifiedBlock; 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) { match verify_block_basic(&input, engine, check_seal) {
Ok(()) => Ok(input), Ok(()) => Ok(input),
Err(Error(ErrorKind::Block(BlockError::TemporarilyInvalid(oob)), _)) => { Err(Error(ErrorKind::Block(BlockError::TemporarilyInvalid(oob)), _)) => {
debug!(target: "client", "Block received too early {}: {:?}", input.hash(), oob); debug!(target: "client", "Block received too early {}: {:?}", input.hash(), oob);
Err(BlockError::TemporarilyInvalid(oob).into()) Err((input, BlockError::TemporarilyInvalid(oob).into()))
}, },
Err(e) => { Err(e) => {
warn!(target: "client", "Stage 1 block verification failed for {}: {:?}", input.hash(), 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 Unverified = Header;
type Verified = Header; type Verified = Header;
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)> {
verify_header_params(&input, engine, true).map(|_| input) 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> { fn verify(unverified: Self::Unverified, engine: &EthEngine, check_seal: bool) -> Result<Self::Verified, Error> {

View File

@ -26,7 +26,7 @@ use heapsize::HeapSizeOf;
use ethereum_types::{H256, U256}; use ethereum_types::{H256, U256};
use parking_lot::{Condvar, Mutex, RwLock}; use parking_lot::{Condvar, Mutex, RwLock};
use io::*; use io::*;
use error::*; use error::{BlockError, ImportErrorKind, ErrorKind, Error};
use engines::EthEngine; use engines::EthEngine;
use client::ClientIoMessage; use client::ClientIoMessage;
@ -469,21 +469,21 @@ impl<K: Kind> VerificationQueue<K> {
} }
/// Add a block to the queue. /// 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(); let hash = input.hash();
{ {
if self.processing.read().contains_key(&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(); let mut bad = self.verification.bad.lock();
if bad.contains(&hash) { if bad.contains(&hash) {
bail!(ErrorKind::Import(ImportErrorKind::KnownBad)); bail!((input, ErrorKind::Import(ImportErrorKind::KnownBad).into()));
} }
if bad.contains(&input.parent_hash()) { if bad.contains(&input.parent_hash()) {
bad.insert(hash); bad.insert(hash);
bail!(ErrorKind::Import(ImportErrorKind::KnownBad)); bail!((input, ErrorKind::Import(ImportErrorKind::KnownBad).into()));
} }
} }
@ -500,7 +500,7 @@ impl<K: Kind> VerificationQueue<K> {
self.more_to_verify.notify_all(); self.more_to_verify.notify_all();
Ok(hash) Ok(hash)
}, },
Err(err) => { Err((input, err)) => {
match err { match err {
// Don't mark future blocks as bad. // Don't mark future blocks as bad.
Error(ErrorKind::Block(BlockError::TemporarilyInvalid(_)), _) => {}, Error(ErrorKind::Block(BlockError::TemporarilyInvalid(_)), _) => {},
@ -508,7 +508,7 @@ impl<K: Kind> VerificationQueue<K> {
self.verification.bad.lock().insert(hash); 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())); let duplicate_import = queue.import(new_unverified(get_good_dummy_block()));
match duplicate_import { match duplicate_import {
Err(e) => { Err((_, e)) => {
match e { match e {
Error(ErrorKind::Import(ImportErrorKind::AlreadyQueued), _) => {}, Error(ErrorKind::Import(ImportErrorKind::AlreadyQueued), _) => {},
_ => { panic!("must return AlreadyQueued error"); } _ => { panic!("must return AlreadyQueued error"); }