Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Commit 5a2f3e7

Browse files
debrissorpaas
authored andcommitted
removed redundant clone before each block import (#9683)
* removed redundant clone before each block import * Fix a trival typo
1 parent 911fc74 commit 5a2f3e7

File tree

4 files changed

+21
-19
lines changed

4 files changed

+21
-19
lines changed

ethcore/light/src/client/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl<T: ChainDataFetcher> Client<T> {
207207

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

213213
/// Inquire about the status of a given header.

ethcore/src/client/client.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,15 +1405,14 @@ impl ImportBlock for Client {
14051405
bail!(EthcoreErrorKind::Block(BlockError::UnknownParent(unverified.parent_hash())));
14061406
}
14071407

1408-
let raw = unverified.bytes.clone();
14091408
match self.importer.block_queue.import(unverified) {
14101409
Ok(res) => Ok(res),
14111410
// we only care about block errors (not import errors)
1412-
Err(EthcoreError(EthcoreErrorKind::Block(err), _))=> {
1413-
self.importer.bad_blocks.report(raw, format!("{:?}", err));
1411+
Err((block, EthcoreError(EthcoreErrorKind::Block(err), _))) => {
1412+
self.importer.bad_blocks.report(block.bytes, format!("{:?}", err));
14141413
bail!(EthcoreErrorKind::Block(err))
14151414
},
1416-
Err(e) => Err(e),
1415+
Err((_, e)) => Err(e),
14171416
}
14181417
}
14191418
}

ethcore/src/verification/queue/kind.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub trait Kind: 'static + Sized + Send + Sync {
5858
type Verified: Sized + Send + BlockLike + HeapSizeOf;
5959

6060
/// Attempt to create the `Unverified` item from the input.
61-
fn create(input: Self::Input, engine: &EthEngine, check_seal: bool) -> Result<Self::Unverified, Error>;
61+
fn create(input: Self::Input, engine: &EthEngine, check_seal: bool) -> Result<Self::Unverified, (Self::Input, Error)>;
6262

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

89-
fn create(input: Self::Input, engine: &EthEngine, check_seal: bool) -> Result<Self::Unverified, Error> {
89+
fn create(input: Self::Input, engine: &EthEngine, check_seal: bool) -> Result<Self::Unverified, (Self::Input, Error)> {
9090
match verify_block_basic(&input, engine, check_seal) {
9191
Ok(()) => Ok(input),
9292
Err(Error(ErrorKind::Block(BlockError::TemporarilyInvalid(oob)), _)) => {
9393
debug!(target: "client", "Block received too early {}: {:?}", input.hash(), oob);
94-
Err(BlockError::TemporarilyInvalid(oob).into())
94+
Err((input, BlockError::TemporarilyInvalid(oob).into()))
9595
},
9696
Err(e) => {
9797
warn!(target: "client", "Stage 1 block verification failed for {}: {:?}", input.hash(), e);
98-
Err(e)
98+
Err((input, e))
9999
}
100100
}
101101
}
@@ -209,8 +209,11 @@ pub mod headers {
209209
type Unverified = Header;
210210
type Verified = Header;
211211

212-
fn create(input: Self::Input, engine: &EthEngine, _check_seal: bool) -> Result<Self::Unverified, Error> {
213-
verify_header_params(&input, engine, true).map(|_| input)
212+
fn create(input: Self::Input, engine: &EthEngine, _check_seal: bool) -> Result<Self::Unverified, (Self::Input, Error)> {
213+
match verify_header_params(&input, engine, true) {
214+
Ok(_) => Ok(input),
215+
Err(err) => Err((input, err))
216+
}
214217
}
215218

216219
fn verify(unverified: Self::Unverified, engine: &EthEngine, check_seal: bool) -> Result<Self::Verified, Error> {

ethcore/src/verification/queue/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use heapsize::HeapSizeOf;
2626
use ethereum_types::{H256, U256};
2727
use parking_lot::{Condvar, Mutex, RwLock};
2828
use io::*;
29-
use error::*;
29+
use error::{BlockError, ImportErrorKind, ErrorKind, Error};
3030
use engines::EthEngine;
3131
use client::ClientIoMessage;
3232

@@ -469,21 +469,21 @@ impl<K: Kind> VerificationQueue<K> {
469469
}
470470

471471
/// Add a block to the queue.
472-
pub fn import(&self, input: K::Input) -> EthcoreResult<H256> {
472+
pub fn import(&self, input: K::Input) -> Result<H256, (K::Input, Error)> {
473473
let hash = input.hash();
474474
{
475475
if self.processing.read().contains_key(&hash) {
476-
bail!(ErrorKind::Import(ImportErrorKind::AlreadyQueued));
476+
bail!((input, ErrorKind::Import(ImportErrorKind::AlreadyQueued).into()));
477477
}
478478

479479
let mut bad = self.verification.bad.lock();
480480
if bad.contains(&hash) {
481-
bail!(ErrorKind::Import(ImportErrorKind::KnownBad));
481+
bail!((input, ErrorKind::Import(ImportErrorKind::KnownBad).into()));
482482
}
483483

484484
if bad.contains(&input.parent_hash()) {
485485
bad.insert(hash);
486-
bail!(ErrorKind::Import(ImportErrorKind::KnownBad));
486+
bail!((input, ErrorKind::Import(ImportErrorKind::KnownBad).into()));
487487
}
488488
}
489489

@@ -500,15 +500,15 @@ impl<K: Kind> VerificationQueue<K> {
500500
self.more_to_verify.notify_all();
501501
Ok(hash)
502502
},
503-
Err(err) => {
503+
Err((input, err)) => {
504504
match err {
505505
// Don't mark future blocks as bad.
506506
Error(ErrorKind::Block(BlockError::TemporarilyInvalid(_)), _) => {},
507507
_ => {
508508
self.verification.bad.lock().insert(hash);
509509
}
510510
}
511-
Err(err)
511+
Err((input, err))
512512
}
513513
}
514514
}
@@ -784,7 +784,7 @@ mod tests {
784784

785785
let duplicate_import = queue.import(new_unverified(get_good_dummy_block()));
786786
match duplicate_import {
787-
Err(e) => {
787+
Err((_, e)) => {
788788
match e {
789789
Error(ErrorKind::Import(ImportErrorKind::AlreadyQueued), _) => {},
790790
_ => { panic!("must return AlreadyQueued error"); }

0 commit comments

Comments
 (0)