[ethcore] remove error_chain (#10616)

* Derive Display for BlockError

* Convert error_chain errors

* Convert ethcore usages of errors

* Fix remaining compile errors in ethcore

* Fix other crates

* Fix tests compilation

* Implement error for Snapshot error

* Remove redundant into
This commit is contained in:
Andrew Jones
2019-05-06 14:06:20 +01:00
committed by Andronik Ordian
parent b30b54e446
commit 98b89c8e4f
23 changed files with 265 additions and 241 deletions

View File

@@ -69,7 +69,7 @@ pub mod blocks {
use super::{Kind, BlockLike};
use engines::EthEngine;
use error::{Error, ErrorKind, BlockError};
use error::{Error, BlockError};
use types::header::Header;
use verification::{PreverifiedBlock, verify_block_basic, verify_block_unordered};
use types::transaction::UnverifiedTransaction;
@@ -89,7 +89,7 @@ pub mod blocks {
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)), _)) => {
Err(Error::Block(BlockError::TemporarilyInvalid(oob))) => {
debug!(target: "client", "Block received too early {}: {:?}", input.hash(), oob);
Err((input, BlockError::TemporarilyInvalid(oob).into()))
},

View File

@@ -26,7 +26,7 @@ use heapsize::HeapSizeOf;
use ethereum_types::{H256, U256};
use parking_lot::{Condvar, Mutex, RwLock};
use io::*;
use error::{BlockError, ImportErrorKind, ErrorKind, Error};
use error::{BlockError, ImportError, Error};
use engines::EthEngine;
use client::ClientIoMessage;
use len_caching_lock::LenCachingMutex;
@@ -474,17 +474,17 @@ impl<K: Kind> VerificationQueue<K> {
let hash = input.hash();
{
if self.processing.read().contains_key(&hash) {
bail!((input, ErrorKind::Import(ImportErrorKind::AlreadyQueued).into()));
return Err((input, Error::Import(ImportError::AlreadyQueued).into()));
}
let mut bad = self.verification.bad.lock();
if bad.contains(&hash) {
bail!((input, ErrorKind::Import(ImportErrorKind::KnownBad).into()));
return Err((input, Error::Import(ImportError::KnownBad).into()));
}
if bad.contains(&input.parent_hash()) {
bad.insert(hash);
bail!((input, ErrorKind::Import(ImportErrorKind::KnownBad).into()));
return Err((input, Error::Import(ImportError::KnownBad).into()));
}
}
@@ -504,7 +504,7 @@ impl<K: Kind> VerificationQueue<K> {
Err((input, err)) => {
match err {
// Don't mark future blocks as bad.
Error(ErrorKind::Block(BlockError::TemporarilyInvalid(_)), _) => {},
Error::Block(BlockError::TemporarilyInvalid(_)) => {},
_ => {
self.verification.bad.lock().insert(hash);
}
@@ -797,7 +797,7 @@ mod tests {
match duplicate_import {
Err((_, e)) => {
match e {
Error(ErrorKind::Import(ImportErrorKind::AlreadyQueued), _) => {},
Error::Import(ImportError::AlreadyQueued) => {},
_ => { panic!("must return AlreadyQueued error"); }
}
}

View File

@@ -314,11 +314,11 @@ pub fn verify_header_params(header: &Header, engine: &EthEngine, is_full: bool,
.ok_or(BlockError::TimestampOverflow)?;
if timestamp > invalid_threshold {
return Err(From::from(BlockError::InvalidTimestamp(OutOfBounds { max: Some(max_time), min: None, found: timestamp })))
return Err(From::from(BlockError::InvalidTimestamp(OutOfBounds { max: Some(max_time), min: None, found: timestamp }.into())))
}
if timestamp > max_time {
return Err(From::from(BlockError::TemporarilyInvalid(OutOfBounds { max: Some(max_time), min: None, found: timestamp })))
return Err(From::from(BlockError::TemporarilyInvalid(OutOfBounds { max: Some(max_time), min: None, found: timestamp }.into())))
}
}
@@ -338,7 +338,7 @@ fn verify_parent(header: &Header, parent: &Header, engine: &EthEngine) -> Result
.ok_or(BlockError::TimestampOverflow)?;
let found = now.checked_add(Duration::from_secs(header.timestamp()))
.ok_or(BlockError::TimestampOverflow)?;
return Err(From::from(BlockError::InvalidTimestamp(OutOfBounds { max: None, min: Some(min), found })))
return Err(From::from(BlockError::InvalidTimestamp(OutOfBounds { max: None, min: Some(min), found }.into())))
}
if header.number() != parent.number() + 1 {
return Err(From::from(BlockError::InvalidNumber(Mismatch { expected: parent.number() + 1, found: header.number() })));
@@ -364,17 +364,17 @@ fn verify_block_integrity(block: &Unverified) -> Result<(), Error> {
let tx = block_rlp.at(1)?;
let expected_root = ordered_trie_root(tx.iter().map(|r| r.as_raw()));
if &expected_root != block.header.transactions_root() {
bail!(BlockError::InvalidTransactionsRoot(Mismatch {
return Err(BlockError::InvalidTransactionsRoot(Mismatch {
expected: expected_root,
found: *block.header.transactions_root(),
}));
}).into());
}
let expected_uncles = keccak(block_rlp.at(2)?.as_raw());
if &expected_uncles != block.header.uncles_hash(){
bail!(BlockError::InvalidUnclesHash(Mismatch {
return Err(BlockError::InvalidUnclesHash(Mismatch {
expected: expected_uncles,
found: *block.header.uncles_hash(),
}));
}).into());
}
Ok(())
}
@@ -391,7 +391,6 @@ mod tests {
use hash::keccak;
use engines::EthEngine;
use error::BlockError::*;
use error::ErrorKind;
use ethkey::{Random, Generator};
use spec::{CommonParams, Spec};
use test_helpers::{create_test_block_with_data, create_test_block};
@@ -406,7 +405,7 @@ mod tests {
fn check_fail(result: Result<(), Error>, e: BlockError) {
match result {
Err(Error(ErrorKind::Block(ref error), _)) if *error == e => (),
Err(Error::Block(ref error)) if *error == e => (),
Err(other) => panic!("Block verification failed.\nExpected: {:?}\nGot: {:?}", e, other),
Ok(_) => panic!("Block verification failed.\nExpected: {:?}\nGot: Ok", e),
}
@@ -415,8 +414,8 @@ mod tests {
fn check_fail_timestamp(result: Result<(), Error>, temp: bool) {
let name = if temp { "TemporarilyInvalid" } else { "InvalidTimestamp" };
match result {
Err(Error(ErrorKind::Block(BlockError::InvalidTimestamp(_)), _)) if !temp => (),
Err(Error(ErrorKind::Block(BlockError::TemporarilyInvalid(_)), _)) if temp => (),
Err(Error::Block(BlockError::InvalidTimestamp(_))) if !temp => (),
Err(Error::Block(BlockError::TemporarilyInvalid(_))) if temp => (),
Err(other) => panic!("Block verification failed.\nExpected: {}\nGot: {:?}", name, other),
Ok(_) => panic!("Block verification failed.\nExpected: {}\nGot: Ok", name),
}
@@ -690,7 +689,7 @@ mod tests {
bad_header.set_transactions_root(eip86_transactions_root.clone());
bad_header.set_uncles_hash(good_uncles_hash.clone());
match basic_test(&create_test_block_with_data(&bad_header, &eip86_transactions, &good_uncles), engine) {
Err(Error(ErrorKind::Transaction(ref e), _)) if e == &::ethkey::Error::InvalidSignature.into() => (),
Err(Error::Transaction(ref e)) if e == &::ethkey::Error::InvalidSignature.into() => (),
e => panic!("Block verification failed.\nExpected: Transaction Error (Invalid Signature)\nGot: {:?}", e),
}
@@ -785,7 +784,7 @@ mod tests {
header.set_gas_limit(0.into());
header.set_difficulty("0000000000000000000000000000000000000000000000000000000000020000".parse::<U256>().unwrap());
match family_test(&create_test_block(&header), engine, &bc) {
Err(Error(ErrorKind::Block(InvalidGasLimit(_)), _)) => {},
Err(Error::Block(InvalidGasLimit(_))) => {},
Err(_) => { panic!("should be invalid difficulty fail"); },
_ => { panic!("Should be error, got Ok"); },
}