2020-09-22 14:53:52 +02:00
|
|
|
// Copyright 2015-2020 Parity Technologies (UK) Ltd.
|
|
|
|
// This file is part of OpenEthereum.
|
2016-02-05 13:40:41 +01:00
|
|
|
|
2020-09-22 14:53:52 +02:00
|
|
|
// OpenEthereum is free software: you can redistribute it and/or modify
|
2016-02-05 13:40:41 +01:00
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
2020-09-22 14:53:52 +02:00
|
|
|
// OpenEthereum is distributed in the hope that it will be useful,
|
2016-02-05 13:40:41 +01:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
2020-09-22 14:53:52 +02:00
|
|
|
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
|
2016-02-05 13:40:41 +01:00
|
|
|
|
2016-01-10 14:05:39 +01:00
|
|
|
//! General error types for use in ethcore.
|
|
|
|
|
2019-03-02 13:18:18 +01:00
|
|
|
// Silence: `use of deprecated item 'std::error::Error::cause': replaced by Error::source, which can support downcasting`
|
2020-09-22 14:53:52 +02:00
|
|
|
// https://github.com/openethereum/openethereum/issues/10302
|
2019-03-02 13:18:18 +01:00
|
|
|
#![allow(deprecated)]
|
|
|
|
|
2020-08-05 06:08:03 +02:00
|
|
|
use std::{error, fmt, time::SystemTime};
|
2019-01-04 14:05:46 +01:00
|
|
|
|
2020-08-05 06:08:03 +02:00
|
|
|
use ethereum_types::{Address, Bloom, H256, U256};
|
2019-01-04 14:05:46 +01:00
|
|
|
use ethkey::Error as EthkeyError;
|
2018-07-02 18:50:05 +02:00
|
|
|
use ethtrie::TrieError;
|
2019-01-04 14:05:46 +01:00
|
|
|
use rlp;
|
|
|
|
use snappy::InvalidInput;
|
2016-08-05 17:00:46 +02:00
|
|
|
use snapshot::Error as SnapshotError;
|
2020-08-05 06:08:03 +02:00
|
|
|
use types::{transaction::Error as TransactionError, BlockNumber};
|
2019-01-04 14:05:46 +01:00
|
|
|
use unexpected::{Mismatch, OutOfBounds};
|
|
|
|
|
|
|
|
use engines::EngineError;
|
2016-08-05 17:00:46 +02:00
|
|
|
|
2020-08-05 06:08:03 +02:00
|
|
|
pub use executed::{CallError, ExecutionError};
|
2016-01-11 17:37:22 +01:00
|
|
|
|
2019-03-06 15:30:35 +01:00
|
|
|
#[derive(Debug, PartialEq, Clone, Eq)]
|
2016-02-03 12:18:12 +01:00
|
|
|
/// Errors concerning block processing.
|
2016-01-10 14:05:39 +01:00
|
|
|
pub enum BlockError {
|
2020-08-05 06:08:03 +02:00
|
|
|
/// Block has too many uncles.
|
|
|
|
TooManyUncles(OutOfBounds<usize>),
|
|
|
|
/// Extra data is of an invalid length.
|
|
|
|
ExtraDataOutOfBounds(OutOfBounds<usize>),
|
|
|
|
/// Seal is incorrect format.
|
|
|
|
InvalidSealArity(Mismatch<usize>),
|
|
|
|
/// Block has too much gas used.
|
|
|
|
TooMuchGasUsed(OutOfBounds<U256>),
|
|
|
|
/// Uncles hash in header is invalid.
|
|
|
|
InvalidUnclesHash(Mismatch<H256>),
|
|
|
|
/// An uncle is from a generation too old.
|
|
|
|
UncleTooOld(OutOfBounds<BlockNumber>),
|
|
|
|
/// An uncle is from the same generation as the block.
|
|
|
|
UncleIsBrother(OutOfBounds<BlockNumber>),
|
|
|
|
/// An uncle is already in the chain.
|
|
|
|
UncleInChain(H256),
|
|
|
|
/// An uncle is included twice.
|
|
|
|
DuplicateUncle(H256),
|
|
|
|
/// An uncle has a parent not in the chain.
|
|
|
|
UncleParentNotInChain(H256),
|
|
|
|
/// State root header field is invalid.
|
|
|
|
InvalidStateRoot(Mismatch<H256>),
|
|
|
|
/// Gas used header field is invalid.
|
|
|
|
InvalidGasUsed(Mismatch<U256>),
|
|
|
|
/// Transactions root header field is invalid.
|
|
|
|
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.
|
|
|
|
DifficultyOutOfBounds(OutOfBounds<U256>),
|
|
|
|
/// Difficulty header field is invalid; this is a strong error used after getting a definitive
|
|
|
|
/// value for difficulty (which is provided).
|
|
|
|
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.
|
|
|
|
MismatchedH256SealElement(Mismatch<H256>),
|
|
|
|
/// Proof-of-work aspect of seal, which we assume is a 256-bit value, is invalid.
|
|
|
|
InvalidProofOfWork(OutOfBounds<U256>),
|
|
|
|
/// Some low-level aspect of the seal is incorrect.
|
|
|
|
InvalidSeal,
|
|
|
|
/// Gas limit header field is invalid.
|
|
|
|
InvalidGasLimit(OutOfBounds<U256>),
|
|
|
|
/// Receipts trie root header field is invalid.
|
|
|
|
InvalidReceiptsRoot(Mismatch<H256>),
|
|
|
|
/// Timestamp header field is invalid.
|
|
|
|
InvalidTimestamp(OutOfBounds<SystemTime>),
|
|
|
|
/// Timestamp header field is too far in future.
|
|
|
|
TemporarilyInvalid(OutOfBounds<SystemTime>),
|
|
|
|
/// Log bloom header field is invalid.
|
|
|
|
InvalidLogBloom(Box<Mismatch<Bloom>>),
|
|
|
|
/// Number field of header is invalid.
|
|
|
|
InvalidNumber(Mismatch<BlockNumber>),
|
|
|
|
/// Block number isn't sensible.
|
|
|
|
RidiculousNumber(OutOfBounds<BlockNumber>),
|
|
|
|
/// Timestamp header overflowed
|
|
|
|
TimestampOverflow,
|
|
|
|
/// Too many transactions from a particular address.
|
|
|
|
TooManyTransactions(Address),
|
|
|
|
/// Parent given is unknown.
|
|
|
|
UnknownParent(H256),
|
|
|
|
/// Uncle parent given is unknown.
|
|
|
|
UnknownUncleParent(H256),
|
|
|
|
/// No transition to epoch number.
|
|
|
|
UnknownEpochTransition(u64),
|
2016-01-10 14:05:39 +01:00
|
|
|
}
|
|
|
|
|
2016-05-21 00:13:16 +02:00
|
|
|
impl fmt::Display for BlockError {
|
2020-08-05 06:08:03 +02:00
|
|
|
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))
|
|
|
|
}
|
2016-05-21 00:13:16 +02:00
|
|
|
}
|
|
|
|
|
2018-04-19 11:52:54 +02:00
|
|
|
impl error::Error for BlockError {
|
2020-08-05 06:08:03 +02:00
|
|
|
fn description(&self) -> &str {
|
|
|
|
"Block error"
|
|
|
|
}
|
2016-01-10 23:37:09 +01:00
|
|
|
}
|
|
|
|
|
2018-08-24 10:42:24 +02:00
|
|
|
error_chain! {
|
2020-08-05 06:08:03 +02:00
|
|
|
types {
|
|
|
|
QueueError, QueueErrorKind, QueueErrorResultExt, QueueErrorResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
errors {
|
|
|
|
#[doc = "Queue is full"]
|
|
|
|
Full(limit: usize) {
|
|
|
|
description("Queue is full")
|
|
|
|
display("The queue is full ({})", limit)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreign_links {
|
|
|
|
Channel(::io::IoError) #[doc = "Io channel error"];
|
|
|
|
}
|
2018-08-24 10:42:24 +02:00
|
|
|
}
|
|
|
|
|
2018-04-19 11:52:54 +02:00
|
|
|
error_chain! {
|
2020-08-05 06:08:03 +02:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|
2016-05-21 00:13:16 +02:00
|
|
|
}
|
2018-04-19 11:52:54 +02:00
|
|
|
|
2017-07-12 13:09:17 +02:00
|
|
|
/// Api-level error for transaction import
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub enum TransactionImportError {
|
2020-08-05 06:08:03 +02:00
|
|
|
/// Transaction error
|
|
|
|
Transaction(TransactionError),
|
|
|
|
/// Other error
|
|
|
|
Other(String),
|
2017-07-12 13:09:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl From<Error> for TransactionImportError {
|
2020-08-05 06:08:03 +02:00
|
|
|
fn from(e: Error) -> Self {
|
|
|
|
match e {
|
|
|
|
Error(ErrorKind::Transaction(transaction_error), _) => {
|
|
|
|
TransactionImportError::Transaction(transaction_error)
|
|
|
|
}
|
|
|
|
_ => TransactionImportError::Other(format!("other block import error: {:?}", e)),
|
|
|
|
}
|
|
|
|
}
|
2017-07-12 13:09:17 +02:00
|
|
|
}
|
2016-05-21 00:13:16 +02:00
|
|
|
|
2018-04-19 11:52:54 +02:00
|
|
|
error_chain! {
|
2020-08-05 06:08:03 +02:00
|
|
|
types {
|
|
|
|
Error, ErrorKind, ErrorResultExt, EthcoreResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
links {
|
|
|
|
Import(ImportError, ImportErrorKind) #[doc = "Error concerning block import." ];
|
|
|
|
Queue(QueueError, QueueErrorKind) #[doc = "Io channel queue error"];
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
2016-01-11 17:37:22 +01:00
|
|
|
}
|
|
|
|
|
2016-08-05 17:00:46 +02:00
|
|
|
impl From<SnapshotError> for Error {
|
2020-08-05 06:08:03 +02:00
|
|
|
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(),
|
|
|
|
}
|
|
|
|
}
|
2016-08-05 17:00:46 +02:00
|
|
|
}
|
|
|
|
|
2020-08-05 06:08:03 +02:00
|
|
|
impl<E> From<Box<E>> for Error
|
|
|
|
where
|
|
|
|
Error: From<E>,
|
|
|
|
{
|
|
|
|
fn from(err: Box<E>) -> Error {
|
|
|
|
Error::from(*err)
|
|
|
|
}
|
2016-08-03 18:35:48 +02:00
|
|
|
}
|