removed redundant clone before each block import (#9683)
* removed redundant clone before each block import * Fix a trival typo
This commit is contained in:
parent
911fc74346
commit
5a2f3e700b
@ -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.
|
||||
|
@ -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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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>;
|
||||
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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> {
|
||||
|
@ -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<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()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -500,7 +500,7 @@ 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(_)), _) => {},
|
||||
@ -508,7 +508,7 @@ impl<K: Kind> VerificationQueue<K> {
|
||||
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"); }
|
||||
|
Loading…
Reference in New Issue
Block a user