[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:
parent
b30b54e446
commit
98b89c8e4f
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -710,8 +710,8 @@ dependencies = [
|
||||
"common-types 0.1.0",
|
||||
"criterion 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"crossbeam 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"derive_more 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ethabi 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ethabi-contract 6.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ethabi-derive 6.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -13,8 +13,8 @@ bn = { git = "https://github.com/paritytech/bn", default-features = false }
|
||||
byteorder = "1.0"
|
||||
common-types = { path = "types" }
|
||||
crossbeam = "0.4"
|
||||
derive_more = "0.14.0"
|
||||
env_logger = { version = "0.5", optional = true }
|
||||
error-chain = { version = "0.12", default-features = false }
|
||||
ethabi = "6.0"
|
||||
ethabi-contract = "6.0"
|
||||
ethabi-derive = "6.0"
|
||||
|
@ -35,7 +35,7 @@ use common_types::encoded;
|
||||
use common_types::header::Header;
|
||||
use common_types::ids::BlockId;
|
||||
use ethcore::engines::epoch::{Transition as EpochTransition, PendingTransition as PendingEpochTransition};
|
||||
use ethcore::error::{Error, EthcoreResult, ErrorKind as EthcoreErrorKind, BlockError};
|
||||
use ethcore::error::{Error, EthcoreResult, BlockError};
|
||||
use ethcore::spec::{Spec, SpecHardcodedSync};
|
||||
use ethereum_types::{H256, H264, U256};
|
||||
use heapsize::HeapSizeOf;
|
||||
@ -403,7 +403,7 @@ impl HeaderChain {
|
||||
.and_then(|entry| entry.candidates.iter().find(|c| c.hash == parent_hash))
|
||||
.map(|c| c.total_difficulty)
|
||||
.ok_or_else(|| BlockError::UnknownParent(parent_hash))
|
||||
.map_err(EthcoreErrorKind::Block)?
|
||||
.map_err(Error::Block)?
|
||||
};
|
||||
|
||||
parent_td + *header.difficulty()
|
||||
|
@ -63,8 +63,8 @@ use client::bad_blocks;
|
||||
use engines::{MAX_UNCLE_AGE, EthEngine, EpochTransition, ForkChoice, EngineError};
|
||||
use engines::epoch::PendingTransition;
|
||||
use error::{
|
||||
ImportErrorKind, ExecutionError, CallError, BlockError,
|
||||
QueueError, QueueErrorKind, Error as EthcoreError, EthcoreResult, ErrorKind as EthcoreErrorKind
|
||||
ImportError, ExecutionError, CallError, BlockError,
|
||||
QueueError, Error as EthcoreError, EthcoreResult,
|
||||
};
|
||||
use executive::{Executive, Executed, TransactOptions, contract_address};
|
||||
use factory::{Factories, VmFactory};
|
||||
@ -357,7 +357,7 @@ impl Importer {
|
||||
let best_block_number = client.chain.read().best_block_number();
|
||||
if client.pruning_info().earliest_state > header.number() {
|
||||
warn!(target: "client", "Block import failed for #{} ({})\nBlock is ancient (current best block: #{}).", header.number(), header.hash(), best_block_number);
|
||||
bail!("Block is ancient");
|
||||
return Err("Block is ancient".into());
|
||||
}
|
||||
|
||||
// Check if parent is in chain
|
||||
@ -365,7 +365,7 @@ impl Importer {
|
||||
Some(h) => h,
|
||||
None => {
|
||||
warn!(target: "client", "Block import failed for #{} ({}): Parent not found ({}) ", header.number(), header.hash(), header.parent_hash());
|
||||
bail!("Parent not found");
|
||||
return Err("Parent not found".into());
|
||||
}
|
||||
};
|
||||
|
||||
@ -384,13 +384,13 @@ impl Importer {
|
||||
|
||||
if let Err(e) = verify_family_result {
|
||||
warn!(target: "client", "Stage 3 block verification failed for #{} ({})\nError: {:?}", header.number(), header.hash(), e);
|
||||
bail!(e);
|
||||
return Err(e.into());
|
||||
};
|
||||
|
||||
let verify_external_result = self.verifier.verify_block_external(&header, engine);
|
||||
if let Err(e) = verify_external_result {
|
||||
warn!(target: "client", "Stage 4 block verification failed for #{} ({})\nError: {:?}", header.number(), header.hash(), e);
|
||||
bail!(e);
|
||||
return Err(e.into());
|
||||
};
|
||||
|
||||
// Enact Verified Block
|
||||
@ -415,7 +415,7 @@ impl Importer {
|
||||
Ok(b) => b,
|
||||
Err(e) => {
|
||||
warn!(target: "client", "Block import failed for #{} ({})\nError: {:?}", header.number(), header.hash(), e);
|
||||
bail!(e);
|
||||
return Err(e.into());
|
||||
}
|
||||
};
|
||||
|
||||
@ -431,7 +431,7 @@ impl Importer {
|
||||
// Final Verification
|
||||
if let Err(e) = self.verifier.verify_block_final(&header, &locked_block.header) {
|
||||
warn!(target: "client", "Stage 5 block verification failed for #{} ({})\nError: {:?}", header.number(), header.hash(), e);
|
||||
bail!(e);
|
||||
return Err(e.into());
|
||||
}
|
||||
|
||||
let pending = self.check_epoch_end_signal(
|
||||
@ -1453,12 +1453,12 @@ impl CallContract for Client {
|
||||
impl ImportBlock for Client {
|
||||
fn import_block(&self, unverified: Unverified) -> EthcoreResult<H256> {
|
||||
if self.chain.read().is_known(&unverified.hash()) {
|
||||
bail!(EthcoreErrorKind::Import(ImportErrorKind::AlreadyInChain));
|
||||
return Err(EthcoreError::Import(ImportError::AlreadyInChain));
|
||||
}
|
||||
|
||||
let status = self.block_status(BlockId::Hash(unverified.parent_hash()));
|
||||
if status == BlockStatus::Unknown {
|
||||
bail!(EthcoreErrorKind::Block(BlockError::UnknownParent(unverified.parent_hash())));
|
||||
return Err(EthcoreError::Block(BlockError::UnknownParent(unverified.parent_hash())));
|
||||
}
|
||||
|
||||
let raw = if self.importer.block_queue.is_empty() {
|
||||
@ -1477,9 +1477,9 @@ impl ImportBlock for Client {
|
||||
Ok(hash)
|
||||
},
|
||||
// we only care about block errors (not import errors)
|
||||
Err((block, EthcoreError(EthcoreErrorKind::Block(err), _))) => {
|
||||
Err((block, EthcoreError::Block(err))) => {
|
||||
self.importer.bad_blocks.report(block.bytes, format!("{:?}", err));
|
||||
bail!(EthcoreErrorKind::Block(err))
|
||||
return Err(EthcoreError::Block(err))
|
||||
},
|
||||
Err((_, e)) => Err(e),
|
||||
}
|
||||
@ -2214,14 +2214,14 @@ impl IoClient for Client {
|
||||
{
|
||||
// check block order
|
||||
if self.chain.read().is_known(&hash) {
|
||||
bail!(EthcoreErrorKind::Import(ImportErrorKind::AlreadyInChain));
|
||||
return Err(EthcoreError::Import(ImportError::AlreadyInChain));
|
||||
}
|
||||
let parent_hash = unverified.parent_hash();
|
||||
// NOTE To prevent race condition with import, make sure to check queued blocks first
|
||||
// (and attempt to acquire lock)
|
||||
let is_parent_pending = self.queued_ancient_blocks.read().0.contains(&parent_hash);
|
||||
if !is_parent_pending && !self.chain.read().is_known(&parent_hash) {
|
||||
bail!(EthcoreErrorKind::Block(BlockError::UnknownParent(parent_hash)));
|
||||
return Err(EthcoreError::Block(BlockError::UnknownParent(parent_hash)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -2752,7 +2752,9 @@ impl IoChannelQueue {
|
||||
F: Fn(&Client) + Send + Sync + 'static,
|
||||
{
|
||||
let queue_size = self.currently_queued.load(AtomicOrdering::Relaxed);
|
||||
ensure!(queue_size < self.limit, QueueErrorKind::Full(self.limit));
|
||||
if queue_size >= self.limit {
|
||||
return Err(QueueError::Full(self.limit))
|
||||
};
|
||||
|
||||
let currently_queued = self.currently_queued.clone();
|
||||
let result = channel.send(ClientIoMessage::execute(move |client| {
|
||||
@ -2765,7 +2767,7 @@ impl IoChannelQueue {
|
||||
self.currently_queued.fetch_add(count, AtomicOrdering::SeqCst);
|
||||
Ok(())
|
||||
},
|
||||
Err(e) => bail!(QueueErrorKind::Channel(e)),
|
||||
Err(e) => return Err(QueueError::Channel(e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ use client::EngineClient;
|
||||
use engines::{Engine, Seal, EngineError, ConstructedVerifier};
|
||||
use engines::block_reward;
|
||||
use engines::block_reward::{BlockRewardContract, RewardKind};
|
||||
use error::{Error, ErrorKind, BlockError};
|
||||
use error::{Error, BlockError};
|
||||
use ethjson;
|
||||
use machine::{AuxiliaryData, Call, EthereumMachine};
|
||||
use hash::keccak;
|
||||
@ -585,7 +585,7 @@ fn verify_timestamp(step: &Step, header_step: u64) -> Result<(), BlockError> {
|
||||
|
||||
let new_oob = OutOfBounds { min, max, found };
|
||||
|
||||
Err(BlockError::TemporarilyInvalid(new_oob).into())
|
||||
Err(BlockError::TemporarilyInvalid(new_oob.into()))
|
||||
},
|
||||
Ok(_) => Ok(()),
|
||||
}
|
||||
@ -1342,7 +1342,7 @@ impl Engine<EthereumMachine> for AuthorityRound {
|
||||
// contract itself.
|
||||
let res = verify_external(header, &*validators, self.empty_steps_transition);
|
||||
match res {
|
||||
Err(Error(ErrorKind::Engine(EngineError::NotProposer(_)), _)) => {
|
||||
Err(Error::Engine(EngineError::NotProposer(_))) => {
|
||||
self.validators.report_benign(header.author(), set_number, header.number());
|
||||
},
|
||||
Ok(_) => {
|
||||
@ -1570,7 +1570,7 @@ mod tests {
|
||||
use types::transaction::{Action, Transaction};
|
||||
use engines::{Seal, Engine, EngineError, EthEngine};
|
||||
use engines::validator_set::{TestSet, SimpleList};
|
||||
use error::{Error, ErrorKind};
|
||||
use error::Error;
|
||||
use super::{AuthorityRoundParams, AuthorityRound, EmptyStep, SealedEmptyStep, calculate_score};
|
||||
|
||||
fn aura<F>(f: F) -> Arc<AuthorityRound> where
|
||||
@ -1883,7 +1883,7 @@ mod tests {
|
||||
|
||||
fn assert_insufficient_proof<T: ::std::fmt::Debug>(result: Result<T, Error>, contains: &str) {
|
||||
match result {
|
||||
Err(Error(ErrorKind::Engine(EngineError::InsufficientProof(ref s)), _)) =>{
|
||||
Err(Error::Engine(EngineError::InsufficientProof(ref s))) =>{
|
||||
assert!(s.contains(contains), "Expected {:?} to contain {:?}", s, contains);
|
||||
},
|
||||
e => assert!(false, "Unexpected result: {:?}", e),
|
||||
|
@ -551,7 +551,7 @@ impl Engine<EthereumMachine> for Clique {
|
||||
min: None,
|
||||
max: Some(limit),
|
||||
found,
|
||||
}))?
|
||||
}.into()))?
|
||||
}
|
||||
}
|
||||
|
||||
@ -664,7 +664,7 @@ impl Engine<EthereumMachine> for Clique {
|
||||
min: None,
|
||||
max,
|
||||
found,
|
||||
}))?
|
||||
}.into()))?
|
||||
}
|
||||
|
||||
// Retrieve the parent state
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
use block::*;
|
||||
use engines::Engine;
|
||||
use error::{Error, ErrorKind};
|
||||
use error::Error;
|
||||
use ethereum_types::{Address, H256};
|
||||
use ethkey::{Secret, KeyPair};
|
||||
use state_db::StateDB;
|
||||
@ -715,8 +715,8 @@ fn unauthorized_signer_should_not_be_able_to_sign_block() {
|
||||
let tester = CliqueTester::with(3, 1, vec!['A']);
|
||||
let err = tester.new_block_and_import(CliqueBlockType::Empty, &tester.genesis, None, 'B').unwrap_err();
|
||||
|
||||
match err.kind() {
|
||||
ErrorKind::Engine(EngineError::NotAuthorized(_)) => (),
|
||||
match err {
|
||||
Error::Engine(EngineError::NotAuthorized(_)) => (),
|
||||
_ => assert!(true == false, "Wrong error kind"),
|
||||
}
|
||||
}
|
||||
@ -727,8 +727,8 @@ fn signer_should_not_be_able_to_sign_two_consequtive_blocks() {
|
||||
let b = tester.new_block_and_import(CliqueBlockType::Empty, &tester.genesis, None, 'A').unwrap();
|
||||
let err = tester.new_block_and_import(CliqueBlockType::Empty, &b, None, 'A').unwrap_err();
|
||||
|
||||
match err.kind() {
|
||||
ErrorKind::Engine(EngineError::CliqueTooRecentlySigned(_)) => (),
|
||||
match err {
|
||||
Error::Engine(EngineError::CliqueTooRecentlySigned(_)) => (),
|
||||
_ => assert!(true == false, "Wrong error kind"),
|
||||
}
|
||||
}
|
||||
@ -744,8 +744,8 @@ fn recent_signers_should_not_reset_on_checkpoint() {
|
||||
|
||||
let err = tester.new_block_and_import(CliqueBlockType::Empty, &block, None, 'A').unwrap_err();
|
||||
|
||||
match err.kind() {
|
||||
ErrorKind::Engine(EngineError::CliqueTooRecentlySigned(_)) => (),
|
||||
match err {
|
||||
Error::Engine(EngineError::CliqueTooRecentlySigned(_)) => (),
|
||||
_ => assert!(true == false, "Wrong error kind"),
|
||||
}
|
||||
}
|
||||
|
@ -16,13 +16,10 @@
|
||||
|
||||
//! General error types for use in ethcore.
|
||||
|
||||
// Silence: `use of deprecated item 'std::error::Error::cause': replaced by Error::source, which can support downcasting`
|
||||
// https://github.com/paritytech/parity-ethereum/issues/10302
|
||||
#![allow(deprecated)]
|
||||
|
||||
use std::{fmt, error};
|
||||
use std::time::SystemTime;
|
||||
|
||||
use derive_more::{Display, From};
|
||||
use ethereum_types::{H256, U256, Address, Bloom};
|
||||
use ethkey::Error as EthkeyError;
|
||||
use ethtrie::TrieError;
|
||||
@ -37,118 +34,113 @@ use engines::EngineError;
|
||||
|
||||
pub use executed::{ExecutionError, CallError};
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Eq)]
|
||||
/// Errors concerning block processing.
|
||||
#[derive(Debug, Display, PartialEq, Clone, Eq)]
|
||||
pub enum BlockError {
|
||||
/// Block has too many uncles.
|
||||
#[display(fmt = "Block has too many uncles. {}", _0)]
|
||||
TooManyUncles(OutOfBounds<usize>),
|
||||
/// Extra data is of an invalid length.
|
||||
#[display(fmt = "Extra block data too long. {}", _0)]
|
||||
ExtraDataOutOfBounds(OutOfBounds<usize>),
|
||||
/// Seal is incorrect format.
|
||||
#[display(fmt = "Block seal in incorrect format: {}", _0)]
|
||||
InvalidSealArity(Mismatch<usize>),
|
||||
/// Block has too much gas used.
|
||||
#[display(fmt = "Block has too much gas used. {}", _0)]
|
||||
TooMuchGasUsed(OutOfBounds<U256>),
|
||||
/// Uncles hash in header is invalid.
|
||||
#[display(fmt = "Block has invalid uncles hash: {}", _0)]
|
||||
InvalidUnclesHash(Mismatch<H256>),
|
||||
/// An uncle is from a generation too old.
|
||||
#[display(fmt = "Uncle block is too old. {}", _0)]
|
||||
UncleTooOld(OutOfBounds<BlockNumber>),
|
||||
/// An uncle is from the same generation as the block.
|
||||
#[display(fmt = "Uncle from same generation as block. {}", _0)]
|
||||
UncleIsBrother(OutOfBounds<BlockNumber>),
|
||||
/// An uncle is already in the chain.
|
||||
#[display(fmt = "Uncle {} already in chain", _0)]
|
||||
UncleInChain(H256),
|
||||
/// An uncle is included twice.
|
||||
#[display(fmt = "Uncle {} already in the header", _0)]
|
||||
DuplicateUncle(H256),
|
||||
/// An uncle has a parent not in the chain.
|
||||
#[display(fmt = "Uncle {} has a parent not in the chain", _0)]
|
||||
UncleParentNotInChain(H256),
|
||||
/// State root header field is invalid.
|
||||
#[display(fmt = "Invalid state root in header: {}", _0)]
|
||||
InvalidStateRoot(Mismatch<H256>),
|
||||
/// Gas used header field is invalid.
|
||||
#[display(fmt = "Invalid gas used in header: {}", _0)]
|
||||
InvalidGasUsed(Mismatch<U256>),
|
||||
/// Transactions root header field is invalid.
|
||||
#[display(fmt = "Invalid transactions root in header: {}", _0)]
|
||||
InvalidTransactionsRoot(Mismatch<H256>),
|
||||
/// Difficulty is out of range; this can be used as an looser error prior to getting a definitive
|
||||
/// value for difficulty. This error needs only provide bounds of which it is out.
|
||||
#[display(fmt = "Difficulty out of bounds: {}", _0)]
|
||||
DifficultyOutOfBounds(OutOfBounds<U256>),
|
||||
/// Difficulty header field is invalid; this is a strong error used after getting a definitive
|
||||
/// value for difficulty (which is provided).
|
||||
#[display(fmt = "Invalid block difficulty: {}", _0)]
|
||||
InvalidDifficulty(Mismatch<U256>),
|
||||
/// Seal element of type H256 (max_hash for Ethash, but could be something else for
|
||||
/// other seal engines) is out of bounds.
|
||||
#[display(fmt = "Seal element out of bounds: {}", _0)]
|
||||
MismatchedH256SealElement(Mismatch<H256>),
|
||||
/// Proof-of-work aspect of seal, which we assume is a 256-bit value, is invalid.
|
||||
#[display(fmt = "Block has invalid PoW: {}", _0)]
|
||||
InvalidProofOfWork(OutOfBounds<U256>),
|
||||
/// Some low-level aspect of the seal is incorrect.
|
||||
#[display(fmt = "Block has invalid seal.")]
|
||||
InvalidSeal,
|
||||
/// Gas limit header field is invalid.
|
||||
#[display(fmt = "Invalid gas limit: {}", _0)]
|
||||
InvalidGasLimit(OutOfBounds<U256>),
|
||||
/// Receipts trie root header field is invalid.
|
||||
#[display(fmt = "Invalid receipts trie root in header: {}", _0)]
|
||||
InvalidReceiptsRoot(Mismatch<H256>),
|
||||
/// Timestamp header field is invalid.
|
||||
InvalidTimestamp(OutOfBounds<SystemTime>),
|
||||
#[display(fmt = "Invalid timestamp in header: {}", _0)]
|
||||
InvalidTimestamp(OutOfBoundsTime),
|
||||
/// Timestamp header field is too far in future.
|
||||
TemporarilyInvalid(OutOfBounds<SystemTime>),
|
||||
#[display(fmt = "Future timestamp in header: {}", _0)]
|
||||
TemporarilyInvalid(OutOfBoundsTime),
|
||||
/// Log bloom header field is invalid.
|
||||
#[display(fmt = "Invalid log bloom in header: {}", _0)]
|
||||
InvalidLogBloom(Box<Mismatch<Bloom>>),
|
||||
/// Number field of header is invalid.
|
||||
#[display(fmt = "Invalid number in header: {}", _0)]
|
||||
InvalidNumber(Mismatch<BlockNumber>),
|
||||
/// Block number isn't sensible.
|
||||
#[display(fmt = "Implausible block number. {}", _0)]
|
||||
RidiculousNumber(OutOfBounds<BlockNumber>),
|
||||
/// Timestamp header overflowed
|
||||
#[display(fmt = "Timestamp overflow")]
|
||||
TimestampOverflow,
|
||||
/// Too many transactions from a particular address.
|
||||
#[display(fmt = "Too many transactions from: {}", _0)]
|
||||
TooManyTransactions(Address),
|
||||
/// Parent given is unknown.
|
||||
#[display(fmt = "Unknown parent: {}", _0)]
|
||||
UnknownParent(H256),
|
||||
/// Uncle parent given is unknown.
|
||||
#[display(fmt = "Unknown uncle parent: {}", _0)]
|
||||
UnknownUncleParent(H256),
|
||||
/// No transition to epoch number.
|
||||
#[display(fmt = "Unknown transition to epoch number: {}", _0)]
|
||||
UnknownEpochTransition(u64),
|
||||
}
|
||||
|
||||
impl fmt::Display for BlockError {
|
||||
/// Newtype for Display impl to show seconds
|
||||
#[derive(Debug, Clone, From, PartialEq, Eq)]
|
||||
pub struct OutOfBoundsTime(OutOfBounds<SystemTime>);
|
||||
|
||||
impl fmt::Display for OutOfBoundsTime {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
use self::BlockError::*;
|
||||
|
||||
let msg = match *self {
|
||||
TooManyUncles(ref oob) => format!("Block has too many uncles. {}", oob),
|
||||
ExtraDataOutOfBounds(ref oob) => format!("Extra block data too long. {}", oob),
|
||||
InvalidSealArity(ref mis) => format!("Block seal in incorrect format: {}", mis),
|
||||
TooMuchGasUsed(ref oob) => format!("Block has too much gas used. {}", oob),
|
||||
InvalidUnclesHash(ref mis) => format!("Block has invalid uncles hash: {}", mis),
|
||||
UncleTooOld(ref oob) => format!("Uncle block is too old. {}", oob),
|
||||
UncleIsBrother(ref oob) => format!("Uncle from same generation as block. {}", oob),
|
||||
UncleInChain(ref hash) => format!("Uncle {} already in chain", hash),
|
||||
DuplicateUncle(ref hash) => format!("Uncle {} already in the header", hash),
|
||||
UncleParentNotInChain(ref hash) => format!("Uncle {} has a parent not in the chain", hash),
|
||||
InvalidStateRoot(ref mis) => format!("Invalid state root in header: {}", mis),
|
||||
InvalidGasUsed(ref mis) => format!("Invalid gas used in header: {}", mis),
|
||||
InvalidTransactionsRoot(ref mis) => format!("Invalid transactions root in header: {}", mis),
|
||||
DifficultyOutOfBounds(ref oob) => format!("Invalid block difficulty: {}", oob),
|
||||
InvalidDifficulty(ref mis) => format!("Invalid block difficulty: {}", mis),
|
||||
MismatchedH256SealElement(ref mis) => format!("Seal element out of bounds: {}", mis),
|
||||
InvalidProofOfWork(ref oob) => format!("Block has invalid PoW: {}", oob),
|
||||
InvalidSeal => "Block has invalid seal.".into(),
|
||||
InvalidGasLimit(ref oob) => format!("Invalid gas limit: {}", oob),
|
||||
InvalidReceiptsRoot(ref mis) => format!("Invalid receipts trie root in header: {}", mis),
|
||||
InvalidTimestamp(ref oob) => {
|
||||
let oob = oob.map(|st| st.elapsed().unwrap_or_default().as_secs());
|
||||
format!("Invalid timestamp in header: {}", oob)
|
||||
},
|
||||
TemporarilyInvalid(ref oob) => {
|
||||
let oob = oob.map(|st| st.elapsed().unwrap_or_default().as_secs());
|
||||
format!("Future timestamp in header: {}", oob)
|
||||
},
|
||||
InvalidLogBloom(ref oob) => format!("Invalid log bloom in header: {}", oob),
|
||||
InvalidNumber(ref mis) => format!("Invalid number in header: {}", mis),
|
||||
RidiculousNumber(ref oob) => format!("Implausible block number. {}", oob),
|
||||
UnknownParent(ref hash) => format!("Unknown parent: {}", hash),
|
||||
UnknownUncleParent(ref hash) => format!("Unknown uncle parent: {}", hash),
|
||||
UnknownEpochTransition(ref num) => format!("Unknown transition to epoch number: {}", num),
|
||||
TimestampOverflow => format!("Timestamp overflow"),
|
||||
TooManyTransactions(ref address) => format!("Too many transactions from: {}", address),
|
||||
};
|
||||
|
||||
f.write_fmt(format_args!("Block error ({})", msg))
|
||||
let seconds = self.0
|
||||
.map(|st| st.elapsed().unwrap_or_default().as_secs());
|
||||
f.write_fmt(format_args!("{}", seconds))
|
||||
}
|
||||
}
|
||||
|
||||
@ -158,50 +150,42 @@ impl error::Error for BlockError {
|
||||
}
|
||||
}
|
||||
|
||||
error_chain! {
|
||||
types {
|
||||
QueueError, QueueErrorKind, QueueErrorResultExt, QueueErrorResult;
|
||||
}
|
||||
/// Queue error
|
||||
#[derive(Debug, Display, From)]
|
||||
pub enum QueueError {
|
||||
/// Queue is full
|
||||
#[display(fmt = "Queue is full ({})", _0)]
|
||||
Full(usize),
|
||||
/// Io channel error
|
||||
#[display(fmt = "Io channel error: {}", _0)]
|
||||
Channel(::io::IoError)
|
||||
}
|
||||
|
||||
errors {
|
||||
#[doc = "Queue is full"]
|
||||
Full(limit: usize) {
|
||||
description("Queue is full")
|
||||
display("The queue is full ({})", limit)
|
||||
impl error::Error for QueueError {
|
||||
fn source(&self) -> Option<&(error::Error + 'static)> {
|
||||
match self {
|
||||
QueueError::Channel(e) => Some(e),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
foreign_links {
|
||||
Channel(::io::IoError) #[doc = "Io channel error"];
|
||||
}
|
||||
}
|
||||
|
||||
error_chain! {
|
||||
types {
|
||||
ImportError, ImportErrorKind, ImportErrorResultExt, ImportErrorResult;
|
||||
}
|
||||
|
||||
errors {
|
||||
#[doc = "Already in the block chain."]
|
||||
AlreadyInChain {
|
||||
description("Block already in chain")
|
||||
display("Block already in chain")
|
||||
}
|
||||
|
||||
#[doc = "Already in the block queue"]
|
||||
AlreadyQueued {
|
||||
description("block already in the block queue")
|
||||
display("block already in the block queue")
|
||||
}
|
||||
|
||||
#[doc = "Already marked as bad from a previous import (could mean parent is bad)."]
|
||||
KnownBad {
|
||||
description("block known to be bad")
|
||||
display("block known to be bad")
|
||||
}
|
||||
}
|
||||
/// Block import Error
|
||||
#[derive(Debug, Display)]
|
||||
pub enum ImportError {
|
||||
/// Already in the block chain.
|
||||
#[display(fmt = "Block already in chain")]
|
||||
AlreadyInChain,
|
||||
/// Already in the block queue
|
||||
#[display(fmt = "block already in the block queue")]
|
||||
AlreadyQueued,
|
||||
/// Already marked as bad from a previous import (could mean parent is bad)
|
||||
#[display(fmt = "block known to be bad")]
|
||||
KnownBad,
|
||||
}
|
||||
|
||||
impl error::Error for ImportError {}
|
||||
|
||||
/// Api-level error for transaction import
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum TransactionImportError {
|
||||
@ -214,70 +198,99 @@ pub enum TransactionImportError {
|
||||
impl From<Error> for TransactionImportError {
|
||||
fn from(e: Error) -> Self {
|
||||
match e {
|
||||
Error(ErrorKind::Transaction(transaction_error), _) => TransactionImportError::Transaction(transaction_error),
|
||||
Error::Transaction(transaction_error) => TransactionImportError::Transaction(transaction_error),
|
||||
_ => TransactionImportError::Other(format!("other block import error: {:?}", e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
error_chain! {
|
||||
types {
|
||||
Error, ErrorKind, ErrorResultExt, EthcoreResult;
|
||||
}
|
||||
/// Ethcore Result
|
||||
pub type EthcoreResult<T> = Result<T, Error>;
|
||||
|
||||
links {
|
||||
Import(ImportError, ImportErrorKind) #[doc = "Error concerning block import." ];
|
||||
Queue(QueueError, QueueErrorKind) #[doc = "Io channel queue error"];
|
||||
}
|
||||
/// Ethcore Error
|
||||
#[derive(Debug, Display, From)]
|
||||
pub enum Error {
|
||||
/// Error concerning block import.
|
||||
#[display(fmt = "Import error: {}", _0)]
|
||||
Import(ImportError),
|
||||
/// Io channel queue error
|
||||
#[display(fmt = "Queue error: {}", _0)]
|
||||
Queue(QueueError),
|
||||
/// Io create error
|
||||
#[display(fmt = "Io error: {}", _0)]
|
||||
Io(::io::IoError),
|
||||
/// Error concerning the Rust standard library's IO subsystem.
|
||||
#[display(fmt = "Std Io error: {}", _0)]
|
||||
StdIo(::std::io::Error),
|
||||
/// Error concerning TrieDBs.
|
||||
#[display(fmt = "Trie error: {}", _0)]
|
||||
Trie(TrieError),
|
||||
/// Error concerning EVM code execution.
|
||||
#[display(fmt = "Execution error: {}", _0)]
|
||||
Execution(ExecutionError),
|
||||
/// Error concerning block processing.
|
||||
#[display(fmt = "Block error: {}", _0)]
|
||||
Block(BlockError),
|
||||
/// Error concerning transaction processing.
|
||||
#[display(fmt = "Transaction error: {}", _0)]
|
||||
Transaction(TransactionError),
|
||||
/// Snappy error
|
||||
#[display(fmt = "Snappy error: {}", _0)]
|
||||
Snappy(InvalidInput),
|
||||
/// Consensus vote error.
|
||||
#[display(fmt = "Engine error: {}", _0)]
|
||||
Engine(EngineError),
|
||||
/// Ethkey error."
|
||||
#[display(fmt = "Ethkey error: {}", _0)]
|
||||
Ethkey(EthkeyError),
|
||||
/// RLP decoding errors
|
||||
#[display(fmt = "Decoder error: {}", _0)]
|
||||
Decoder(rlp::DecoderError),
|
||||
/// Snapshot error.
|
||||
#[display(fmt = "Snapshot error {}", _0)]
|
||||
Snapshot(SnapshotError),
|
||||
/// PoW hash is invalid or out of date.
|
||||
#[display(fmt = "PoW hash is invalid or out of date.")]
|
||||
PowHashInvalid,
|
||||
/// The value of the nonce or mishash is invalid.
|
||||
#[display(fmt = "The value of the nonce or mishash is invalid.")]
|
||||
PowInvalid,
|
||||
/// Unknown engine given
|
||||
#[display(fmt = "Unknown engine name ({})", _0)]
|
||||
UnknownEngineName(String),
|
||||
/// A convenient variant for String.
|
||||
#[display(fmt = "{}", _0)]
|
||||
Msg(String),
|
||||
}
|
||||
|
||||
foreign_links {
|
||||
Io(::io::IoError) #[doc = "Io create error"];
|
||||
StdIo(::std::io::Error) #[doc = "Error concerning the Rust standard library's IO subsystem."];
|
||||
Trie(TrieError) #[doc = "Error concerning TrieDBs."];
|
||||
Execution(ExecutionError) #[doc = "Error concerning EVM code execution."];
|
||||
Block(BlockError) #[doc = "Error concerning block processing."];
|
||||
Transaction(TransactionError) #[doc = "Error concerning transaction processing."];
|
||||
Snappy(InvalidInput) #[doc = "Snappy error."];
|
||||
Engine(EngineError) #[doc = "Consensus vote error."];
|
||||
Ethkey(EthkeyError) #[doc = "Ethkey error."];
|
||||
Decoder(rlp::DecoderError) #[doc = "RLP decoding errors"];
|
||||
}
|
||||
|
||||
errors {
|
||||
#[doc = "Snapshot error."]
|
||||
Snapshot(err: SnapshotError) {
|
||||
description("Snapshot error.")
|
||||
display("Snapshot error {}", err)
|
||||
}
|
||||
|
||||
#[doc = "PoW hash is invalid or out of date."]
|
||||
PowHashInvalid {
|
||||
description("PoW hash is invalid or out of date.")
|
||||
display("PoW hash is invalid or out of date.")
|
||||
}
|
||||
|
||||
#[doc = "The value of the nonce or mishash is invalid."]
|
||||
PowInvalid {
|
||||
description("The value of the nonce or mishash is invalid.")
|
||||
display("The value of the nonce or mishash is invalid.")
|
||||
}
|
||||
|
||||
#[doc = "Unknown engine given"]
|
||||
UnknownEngineName(name: String) {
|
||||
description("Unknown engine name")
|
||||
display("Unknown engine name ({})", name)
|
||||
impl error::Error for Error {
|
||||
fn source(&self) -> Option<&(error::Error + 'static)> {
|
||||
match self {
|
||||
Error::Io(e) => Some(e),
|
||||
Error::StdIo(e) => Some(e),
|
||||
Error::Trie(e) => Some(e),
|
||||
Error::Execution(e) => Some(e),
|
||||
Error::Block(e) => Some(e),
|
||||
Error::Transaction(e) => Some(e),
|
||||
Error::Snappy(e) => Some(e),
|
||||
Error::Engine(e) => Some(e),
|
||||
Error::Ethkey(e) => Some(e),
|
||||
Error::Decoder(e) => Some(e),
|
||||
Error::Snapshot(e) => Some(e),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SnapshotError> for Error {
|
||||
fn from(err: SnapshotError) -> Error {
|
||||
match err {
|
||||
SnapshotError::Io(err) => ErrorKind::StdIo(err).into(),
|
||||
SnapshotError::Trie(err) => ErrorKind::Trie(err).into(),
|
||||
SnapshotError::Decoder(err) => err.into(),
|
||||
other => ErrorKind::Snapshot(other).into(),
|
||||
}
|
||||
impl From<String> for Error {
|
||||
fn from(s: String) -> Self {
|
||||
Error::Msg(s)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for Error {
|
||||
fn from(s: &str) -> Self {
|
||||
Error::Msg(s.into())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -490,7 +490,7 @@ mod tests {
|
||||
use ethereum_types::{H64, H256, U256, Address};
|
||||
use block::*;
|
||||
use test_helpers::get_temp_state_db;
|
||||
use error::{BlockError, Error, ErrorKind};
|
||||
use error::{BlockError, Error};
|
||||
use types::header::Header;
|
||||
use spec::Spec;
|
||||
use engines::Engine;
|
||||
@ -641,7 +641,7 @@ mod tests {
|
||||
let verify_result = engine.verify_block_basic(&header);
|
||||
|
||||
match verify_result {
|
||||
Err(Error(ErrorKind::Block(BlockError::InvalidSealArity(_)), _)) => {},
|
||||
Err(Error::Block(BlockError::InvalidSealArity(_))) => {},
|
||||
Err(_) => { panic!("should be block seal-arity mismatch error (got {:?})", verify_result); },
|
||||
_ => { panic!("Should be error, got Ok"); },
|
||||
}
|
||||
@ -656,7 +656,7 @@ mod tests {
|
||||
let verify_result = engine.verify_block_basic(&header);
|
||||
|
||||
match verify_result {
|
||||
Err(Error(ErrorKind::Block(BlockError::DifficultyOutOfBounds(_)), _)) => {},
|
||||
Err(Error::Block(BlockError::DifficultyOutOfBounds(_))) => {},
|
||||
Err(_) => { panic!("should be block difficulty error (got {:?})", verify_result); },
|
||||
_ => { panic!("Should be error, got Ok"); },
|
||||
}
|
||||
@ -672,7 +672,7 @@ mod tests {
|
||||
let verify_result = engine.verify_block_basic(&header);
|
||||
|
||||
match verify_result {
|
||||
Err(Error(ErrorKind::Block(BlockError::InvalidProofOfWork(_)), _)) => {},
|
||||
Err(Error::Block(BlockError::InvalidProofOfWork(_))) => {},
|
||||
Err(_) => { panic!("should be invalid proof of work error (got {:?})", verify_result); },
|
||||
_ => { panic!("Should be error, got Ok"); },
|
||||
}
|
||||
@ -686,7 +686,7 @@ mod tests {
|
||||
let verify_result = engine.verify_block_unordered(&header);
|
||||
|
||||
match verify_result {
|
||||
Err(Error(ErrorKind::Block(BlockError::InvalidSealArity(_)), _)) => {},
|
||||
Err(Error::Block(BlockError::InvalidSealArity(_))) => {},
|
||||
Err(_) => { panic!("should be block seal-arity mismatch error (got {:?})", verify_result); },
|
||||
_ => { panic!("Should be error, got Ok"); },
|
||||
}
|
||||
@ -711,7 +711,7 @@ mod tests {
|
||||
let verify_result = engine.verify_block_unordered(&header);
|
||||
|
||||
match verify_result {
|
||||
Err(Error(ErrorKind::Block(BlockError::MismatchedH256SealElement(_)), _)) => {},
|
||||
Err(Error::Block(BlockError::MismatchedH256SealElement(_))) => {},
|
||||
Err(_) => { panic!("should be invalid 256-bit seal fail (got {:?})", verify_result); },
|
||||
_ => { panic!("Should be error, got Ok"); },
|
||||
}
|
||||
@ -727,7 +727,7 @@ mod tests {
|
||||
let verify_result = engine.verify_block_unordered(&header);
|
||||
|
||||
match verify_result {
|
||||
Err(Error(ErrorKind::Block(BlockError::InvalidProofOfWork(_)), _)) => {},
|
||||
Err(Error::Block(BlockError::InvalidProofOfWork(_))) => {},
|
||||
Err(_) => { panic!("should be invalid proof-of-work fail (got {:?})", verify_result); },
|
||||
_ => { panic!("Should be error, got Ok"); },
|
||||
}
|
||||
@ -742,7 +742,7 @@ mod tests {
|
||||
let verify_result = engine.verify_block_family(&header, &parent_header);
|
||||
|
||||
match verify_result {
|
||||
Err(Error(ErrorKind::Block(BlockError::RidiculousNumber(_)), _)) => {},
|
||||
Err(Error::Block(BlockError::RidiculousNumber(_))) => {},
|
||||
Err(_) => { panic!("should be invalid block number fail (got {:?})", verify_result); },
|
||||
_ => { panic!("Should be error, got Ok"); },
|
||||
}
|
||||
@ -759,7 +759,7 @@ mod tests {
|
||||
let verify_result = engine.verify_block_family(&header, &parent_header);
|
||||
|
||||
match verify_result {
|
||||
Err(Error(ErrorKind::Block(BlockError::InvalidDifficulty(_)), _)) => {},
|
||||
Err(Error::Block(BlockError::InvalidDifficulty(_))) => {},
|
||||
Err(_) => { panic!("should be invalid difficulty fail (got {:?})", verify_result); },
|
||||
_ => { panic!("Should be error, got Ok"); },
|
||||
}
|
||||
|
@ -126,8 +126,7 @@ extern crate rlp_compress;
|
||||
extern crate ethabi_derive;
|
||||
#[macro_use]
|
||||
extern crate ethabi_contract;
|
||||
#[macro_use]
|
||||
extern crate error_chain;
|
||||
extern crate derive_more;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
#[macro_use]
|
||||
|
@ -54,7 +54,7 @@ use client::{
|
||||
};
|
||||
use client::{BlockId, ClientIoMessage};
|
||||
use engines::{EthEngine, Seal, EngineSigner};
|
||||
use error::{Error, ErrorKind};
|
||||
use error::Error;
|
||||
use executed::ExecutionError;
|
||||
use executive::contract_address;
|
||||
use spec::Spec;
|
||||
@ -521,7 +521,7 @@ impl Miner {
|
||||
|
||||
debug!(target: "miner", "Adding tx {:?} took {} ms", hash, took_ms(&took));
|
||||
match result {
|
||||
Err(Error(ErrorKind::Execution(ExecutionError::BlockGasLimitReached { gas_limit, gas_used, gas }), _)) => {
|
||||
Err(Error::Execution(ExecutionError::BlockGasLimitReached { gas_limit, gas_used, gas })) => {
|
||||
debug!(target: "miner", "Skipping adding transaction to block because of gas limit: {:?} (limit: {:?}, used: {:?}, gas: {:?})", hash, gas_limit, gas_used, gas);
|
||||
|
||||
// Penalize transaction if it's above current gas limit
|
||||
@ -546,12 +546,12 @@ impl Miner {
|
||||
},
|
||||
// Invalid nonce error can happen only if previous transaction is skipped because of gas limit.
|
||||
// If there is errornous state of transaction queue it will be fixed when next block is imported.
|
||||
Err(Error(ErrorKind::Execution(ExecutionError::InvalidNonce { expected, got }), _)) => {
|
||||
Err(Error::Execution(ExecutionError::InvalidNonce { expected, got })) => {
|
||||
debug!(target: "miner", "Skipping adding transaction to block because of invalid nonce: {:?} (expected: {:?}, got: {:?})", hash, expected, got);
|
||||
},
|
||||
// already have transaction - ignore
|
||||
Err(Error(ErrorKind::Transaction(transaction::Error::AlreadyImported), _)) => {},
|
||||
Err(Error(ErrorKind::Transaction(transaction::Error::NotAllowed), _)) => {
|
||||
Err(Error::Transaction(transaction::Error::AlreadyImported)) => {},
|
||||
Err(Error::Transaction(transaction::Error::NotAllowed)) => {
|
||||
not_allowed_transactions.insert(hash);
|
||||
debug!(target: "miner", "Skipping non-allowed transaction for sender {:?}", hash);
|
||||
},
|
||||
@ -1222,11 +1222,11 @@ impl miner::MinerService for Miner {
|
||||
trace!(target: "miner", "Submitted block {}={} with seal {:?}", block_hash, b.header.bare_hash(), seal);
|
||||
b.lock().try_seal(&*self.engine, seal).or_else(|e| {
|
||||
warn!(target: "miner", "Mined solution rejected: {}", e);
|
||||
Err(ErrorKind::PowInvalid.into())
|
||||
Err(Error::PowInvalid.into())
|
||||
})
|
||||
} else {
|
||||
warn!(target: "miner", "Submitted solution rejected: Block unknown or out of date.");
|
||||
Err(ErrorKind::PowHashInvalid.into())
|
||||
Err(Error::PowHashInvalid.into())
|
||||
};
|
||||
|
||||
result.and_then(|sealed| {
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
//! Snapshot-related errors.
|
||||
|
||||
use std::error;
|
||||
use std::fmt;
|
||||
|
||||
use types::ids::BlockId;
|
||||
@ -69,6 +70,17 @@ pub enum Error {
|
||||
UnlinkedAncientBlockChain,
|
||||
}
|
||||
|
||||
impl error::Error for Error {
|
||||
fn source(&self) -> Option<&(error::Error + 'static)> {
|
||||
match self {
|
||||
Error::Trie(e) => Some(e),
|
||||
Error::Decoder(e) => Some(e),
|
||||
Error::Io(e) => Some(e),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
|
@ -30,7 +30,7 @@ use super::io::{SnapshotReader, LooseReader, SnapshotWriter, LooseWriter};
|
||||
use blockchain::{BlockChain, BlockChainDB, BlockChainDBHandler};
|
||||
use client::{BlockInfo, BlockChainClient, Client, ChainInfo, ClientIoMessage};
|
||||
use engines::EthEngine;
|
||||
use error::{Error, ErrorKind as SnapshotErrorKind};
|
||||
use error::Error;
|
||||
use snapshot::{Error as SnapshotError};
|
||||
use hash::keccak;
|
||||
use types::ids::BlockId;
|
||||
@ -697,7 +697,7 @@ impl Service {
|
||||
let mut restoration = self.restoration.lock();
|
||||
match self.feed_chunk_with_restoration(&mut restoration, hash, chunk, is_state) {
|
||||
Ok(()) |
|
||||
Err(Error(SnapshotErrorKind::Snapshot(SnapshotError::RestorationAborted), _)) => (),
|
||||
Err(Error::Snapshot(SnapshotError::RestorationAborted)) => (),
|
||||
Err(e) => {
|
||||
warn!("Encountered error during snapshot restoration: {}", e);
|
||||
*self.restoration.lock() = None;
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use tempdir::TempDir;
|
||||
use error::{Error, ErrorKind};
|
||||
use error::Error;
|
||||
|
||||
use blockchain::generator::{BlockGenerator, BlockBuilder};
|
||||
use blockchain::{BlockChain, ExtrasInsert};
|
||||
@ -143,7 +143,7 @@ fn checks_flag() {
|
||||
let mut rebuilder = SNAPSHOT_MODE.rebuilder(chain, db.clone(), &manifest).unwrap();
|
||||
|
||||
match rebuilder.feed(&chunk, engine.as_ref(), &AtomicBool::new(false)) {
|
||||
Err(Error(ErrorKind::Snapshot(SnapshotError::RestorationAborted), _)) => {}
|
||||
Err(Error::Snapshot(SnapshotError::RestorationAborted)) => {}
|
||||
_ => panic!("Wrong result on abort flag set")
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ use snapshot::{chunk_state, Error as SnapshotError, Progress, StateRebuilder, SN
|
||||
use snapshot::io::{PackedReader, PackedWriter, SnapshotReader, SnapshotWriter};
|
||||
use super::helpers::StateProducer;
|
||||
|
||||
use error::{Error, ErrorKind};
|
||||
use error::Error;
|
||||
|
||||
use rand::{XorShiftRng, SeedableRng};
|
||||
use ethereum_types::H256;
|
||||
@ -196,7 +196,7 @@ fn checks_flag() {
|
||||
let chunk = ::snappy::decompress(&raw).unwrap();
|
||||
|
||||
match rebuilder.feed(&chunk, &flag) {
|
||||
Err(Error(ErrorKind::Snapshot(SnapshotError::RestorationAborted), _)) => {},
|
||||
Err(Error::Snapshot(SnapshotError::RestorationAborted)) => {},
|
||||
_ => panic!("unexpected result when feeding with flag off"),
|
||||
}
|
||||
}
|
||||
|
@ -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()))
|
||||
},
|
||||
|
@ -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"); }
|
||||
}
|
||||
}
|
||||
|
@ -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"); },
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ use ethereum_types::H256;
|
||||
use rlp::{self, Rlp};
|
||||
use types::BlockNumber;
|
||||
use ethcore::client::{BlockStatus, BlockId};
|
||||
use ethcore::error::{ImportErrorKind, QueueErrorKind, BlockError, Error as EthcoreError, ErrorKind as EthcoreErrorKind};
|
||||
use ethcore::error::{ImportError, QueueError, BlockError, Error as EthcoreError};
|
||||
use sync_io::SyncIo;
|
||||
use blocks::{BlockCollection, SyncBody, SyncHeader};
|
||||
use chain::BlockSet;
|
||||
@ -556,11 +556,11 @@ impl BlockDownloader {
|
||||
};
|
||||
|
||||
match result {
|
||||
Err(EthcoreError(EthcoreErrorKind::Import(ImportErrorKind::AlreadyInChain), _)) => {
|
||||
Err(EthcoreError::Import(ImportError::AlreadyInChain)) => {
|
||||
trace_sync!(self, "Block already in chain {:?}", h);
|
||||
self.block_imported(&h, number, &parent);
|
||||
},
|
||||
Err(EthcoreError(EthcoreErrorKind::Import(ImportErrorKind::AlreadyQueued), _)) => {
|
||||
Err(EthcoreError::Import(ImportError::AlreadyQueued)) => {
|
||||
trace_sync!(self, "Block already queued {:?}", h);
|
||||
self.block_imported(&h, number, &parent);
|
||||
},
|
||||
@ -569,18 +569,18 @@ impl BlockDownloader {
|
||||
imported.insert(h.clone());
|
||||
self.block_imported(&h, number, &parent);
|
||||
},
|
||||
Err(EthcoreError(EthcoreErrorKind::Block(BlockError::UnknownParent(_)), _)) if allow_out_of_order => {
|
||||
Err(EthcoreError::Block(BlockError::UnknownParent(_))) if allow_out_of_order => {
|
||||
break;
|
||||
},
|
||||
Err(EthcoreError(EthcoreErrorKind::Block(BlockError::UnknownParent(_)), _)) => {
|
||||
Err(EthcoreError::Block(BlockError::UnknownParent(_))) => {
|
||||
trace_sync!(self, "Unknown new block parent, restarting sync");
|
||||
break;
|
||||
},
|
||||
Err(EthcoreError(EthcoreErrorKind::Block(BlockError::TemporarilyInvalid(_)), _)) => {
|
||||
Err(EthcoreError::Block(BlockError::TemporarilyInvalid(_))) => {
|
||||
debug_sync!(self, "Block temporarily invalid: {:?}, restarting sync", h);
|
||||
break;
|
||||
},
|
||||
Err(EthcoreError(EthcoreErrorKind::Queue(QueueErrorKind::Full(limit)), _)) => {
|
||||
Err(EthcoreError::Queue(QueueError::Full(limit))) => {
|
||||
debug_sync!(self, "Block import queue full ({}), restarting sync", limit);
|
||||
download_action = DownloadAction::Reset;
|
||||
break;
|
||||
|
@ -18,7 +18,7 @@ use api::WARP_SYNC_PROTOCOL_ID;
|
||||
use block_sync::{BlockDownloaderImportError as DownloaderImportError, DownloadAction};
|
||||
use bytes::Bytes;
|
||||
use enum_primitive::FromPrimitive;
|
||||
use ethcore::error::{Error as EthcoreError, ErrorKind as EthcoreErrorKind, ImportErrorKind, BlockError};
|
||||
use ethcore::error::{Error as EthcoreError, ImportError, BlockError};
|
||||
use ethcore::snapshot::{ManifestData, RestorationStatus};
|
||||
use ethcore::verification::queue::kind::blocks::Unverified;
|
||||
use ethereum_types::{H256, U256};
|
||||
@ -183,10 +183,10 @@ impl SyncHandler {
|
||||
return Err(DownloaderImportError::Invalid);
|
||||
}
|
||||
match io.chain().import_block(block) {
|
||||
Err(EthcoreError(EthcoreErrorKind::Import(ImportErrorKind::AlreadyInChain), _)) => {
|
||||
Err(EthcoreError::Import(ImportError::AlreadyInChain)) => {
|
||||
trace!(target: "sync", "New block already in chain {:?}", hash);
|
||||
},
|
||||
Err(EthcoreError(EthcoreErrorKind::Import(ImportErrorKind::AlreadyQueued), _)) => {
|
||||
Err(EthcoreError::Import(ImportError::AlreadyQueued)) => {
|
||||
trace!(target: "sync", "New block already queued {:?}", hash);
|
||||
},
|
||||
Ok(_) => {
|
||||
@ -195,7 +195,7 @@ impl SyncHandler {
|
||||
sync.new_blocks.mark_as_known(&hash, number);
|
||||
trace!(target: "sync", "New block queued {:?} ({})", hash, number);
|
||||
},
|
||||
Err(EthcoreError(EthcoreErrorKind::Block(BlockError::UnknownParent(p)), _)) => {
|
||||
Err(EthcoreError::Block(BlockError::UnknownParent(p))) => {
|
||||
unknown = true;
|
||||
trace!(target: "sync", "New block with unknown parent ({:?}) {:?}", p, hash);
|
||||
},
|
||||
|
@ -493,7 +493,7 @@ impl<L: AsLightClient> LightSync<L> {
|
||||
|
||||
// handles request dispatch, block import, state machine transitions, and timeouts.
|
||||
fn maintain_sync(&self, ctx: &BasicContext) {
|
||||
use ethcore::error::{Error as EthcoreError, ErrorKind as EthcoreErrorKind, ImportErrorKind};
|
||||
use ethcore::error::{Error as EthcoreError, ImportError};
|
||||
|
||||
const DRAIN_AMOUNT: usize = 128;
|
||||
|
||||
@ -524,10 +524,10 @@ impl<L: AsLightClient> LightSync<L> {
|
||||
for header in sink.drain(..) {
|
||||
match client.queue_header(header) {
|
||||
Ok(_) => {}
|
||||
Err(EthcoreError(EthcoreErrorKind::Import(ImportErrorKind::AlreadyInChain), _)) => {
|
||||
Err(EthcoreError::Import(ImportError::AlreadyInChain)) => {
|
||||
trace!(target: "sync", "Block already in chain. Continuing.");
|
||||
},
|
||||
Err(EthcoreError(EthcoreErrorKind::Import(ImportErrorKind::AlreadyQueued), _)) => {
|
||||
Err(EthcoreError::Import(ImportError::AlreadyQueued)) => {
|
||||
trace!(target: "sync", "Block already queued. Continuing.");
|
||||
},
|
||||
Err(e) => {
|
||||
|
@ -28,7 +28,7 @@ use rlp::PayloadInfo;
|
||||
use ethcore::client::{
|
||||
Mode, DatabaseCompactionProfile, VMType, Nonce, Balance, BlockChainClient, BlockId, BlockInfo, ImportBlock, BlockChainReset
|
||||
};
|
||||
use ethcore::error::{ImportErrorKind, ErrorKind as EthcoreErrorKind, Error as EthcoreError};
|
||||
use ethcore::error::{ImportError, Error as EthcoreError};
|
||||
use ethcore::miner::Miner;
|
||||
use ethcore::verification::queue::VerifierSettings;
|
||||
use ethcore::verification::queue::kind::blocks::Unverified;
|
||||
@ -272,7 +272,7 @@ fn execute_import_light(cmd: ImportBlockchain) -> Result<(), String> {
|
||||
}
|
||||
|
||||
match client.import_header(header) {
|
||||
Err(EthcoreError(EthcoreErrorKind::Import(ImportErrorKind::AlreadyInChain), _)) => {
|
||||
Err(EthcoreError::Import(ImportError::AlreadyInChain)) => {
|
||||
trace!("Skipping block already in chain.");
|
||||
}
|
||||
Err(e) => {
|
||||
@ -444,7 +444,7 @@ fn execute_import(cmd: ImportBlockchain) -> Result<(), String> {
|
||||
let block = Unverified::from_rlp(bytes).map_err(|_| "Invalid block rlp")?;
|
||||
while client.queue_info().is_full() { sleep(Duration::from_secs(1)); }
|
||||
match client.import_block(block) {
|
||||
Err(EthcoreError(EthcoreErrorKind::Import(ImportErrorKind::AlreadyInChain), _)) => {
|
||||
Err(EthcoreError::Import(ImportError::AlreadyInChain)) => {
|
||||
trace!("Skipping block already in chain.");
|
||||
}
|
||||
Err(e) => {
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
use std::fmt;
|
||||
|
||||
use ethcore::error::{Error as EthcoreError, ErrorKind, CallError};
|
||||
use ethcore::error::{Error as EthcoreError, CallError};
|
||||
use ethcore::client::BlockId;
|
||||
use jsonrpc_core::{futures, Result as RpcResult, Error, ErrorCode, Value};
|
||||
use rlp::DecoderError;
|
||||
@ -440,7 +440,7 @@ pub fn transaction_message(error: &TransactionError) -> String {
|
||||
|
||||
pub fn transaction<T: Into<EthcoreError>>(error: T) -> Error {
|
||||
let error = error.into();
|
||||
if let ErrorKind::Transaction(ref e) = *error.kind() {
|
||||
if let EthcoreError::Transaction(ref e) = error {
|
||||
Error {
|
||||
code: ErrorCode::ServerError(codes::TRANSACTION_ERROR),
|
||||
message: transaction_message(e),
|
||||
@ -456,9 +456,8 @@ pub fn transaction<T: Into<EthcoreError>>(error: T) -> Error {
|
||||
}
|
||||
|
||||
pub fn decode<T: Into<EthcoreError>>(error: T) -> Error {
|
||||
let error = error.into();
|
||||
match *error.kind() {
|
||||
ErrorKind::Decoder(ref dec_err) => rlp(dec_err.clone()),
|
||||
match error.into() {
|
||||
EthcoreError::Decoder(ref dec_err) => rlp(dec_err.clone()),
|
||||
_ => Error {
|
||||
code: ErrorCode::InternalError,
|
||||
message: "decoding error".into(),
|
||||
|
Loading…
Reference in New Issue
Block a user