2019-01-07 11:33:07 +01:00
|
|
|
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
|
|
|
|
// This file is part of Parity Ethereum.
|
2016-08-05 17:00:46 +02:00
|
|
|
|
2019-01-07 11:33:07 +01:00
|
|
|
// Parity Ethereum is free software: you can redistribute it and/or modify
|
2016-08-05 17:00:46 +02: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.
|
|
|
|
|
2019-01-07 11:33:07 +01:00
|
|
|
// Parity Ethereum is distributed in the hope that it will be useful,
|
2016-08-05 17:00:46 +02: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
|
2019-01-07 11:33:07 +01:00
|
|
|
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
2016-08-05 17:00:46 +02:00
|
|
|
|
|
|
|
//! Snapshot-related errors.
|
|
|
|
|
|
|
|
use std::fmt;
|
|
|
|
|
2019-01-04 14:05:46 +01:00
|
|
|
use types::ids::BlockId;
|
2016-08-08 18:41:30 +02:00
|
|
|
|
2018-01-10 13:35:18 +01:00
|
|
|
use ethereum_types::H256;
|
2018-07-02 18:50:05 +02:00
|
|
|
use ethtrie::TrieError;
|
2016-09-01 14:29:59 +02:00
|
|
|
use rlp::DecoderError;
|
2016-08-05 17:00:46 +02:00
|
|
|
|
|
|
|
/// Snapshot-related errors.
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum Error {
|
|
|
|
/// Invalid starting block for snapshot.
|
2016-12-09 23:01:43 +01:00
|
|
|
InvalidStartingBlock(BlockId),
|
2016-08-05 17:00:46 +02:00
|
|
|
/// Block not found.
|
|
|
|
BlockNotFound(H256),
|
2016-08-08 18:41:30 +02:00
|
|
|
/// Incomplete chain.
|
|
|
|
IncompleteChain,
|
2016-10-28 16:10:30 +02:00
|
|
|
/// Best block has wrong state root.
|
|
|
|
WrongStateRoot(H256, H256),
|
|
|
|
/// Wrong block hash.
|
|
|
|
WrongBlockHash(u64, H256, H256),
|
|
|
|
/// Too many blocks contained within the snapshot.
|
|
|
|
TooManyBlocks(u64, u64),
|
2016-08-08 18:41:30 +02:00
|
|
|
/// Old starting block in a pruned database.
|
|
|
|
OldBlockPrunedDB,
|
2016-08-25 14:28:45 +02:00
|
|
|
/// Missing code.
|
|
|
|
MissingCode(Vec<H256>),
|
|
|
|
/// Unrecognized code encoding.
|
|
|
|
UnrecognizedCodeState(u8),
|
2016-11-13 13:52:53 +01:00
|
|
|
/// Restoration aborted.
|
|
|
|
RestorationAborted,
|
2016-08-05 17:00:46 +02:00
|
|
|
/// Trie error.
|
|
|
|
Trie(TrieError),
|
|
|
|
/// Decoder error.
|
|
|
|
Decoder(DecoderError),
|
|
|
|
/// Io error.
|
|
|
|
Io(::std::io::Error),
|
2017-03-24 14:02:04 +01:00
|
|
|
/// Snapshot version is not supported.
|
|
|
|
VersionNotSupported(u64),
|
2017-04-05 16:50:06 +02:00
|
|
|
/// Max chunk size is to small to fit basic account data.
|
|
|
|
ChunkTooSmall,
|
2018-02-22 14:52:29 +01:00
|
|
|
/// Oversized chunk
|
|
|
|
ChunkTooLarge,
|
2017-04-19 20:31:53 +02:00
|
|
|
/// Snapshots not supported by the consensus engine.
|
|
|
|
SnapshotsUnsupported,
|
2019-06-25 15:38:29 +02:00
|
|
|
/// Aborted snapshot
|
|
|
|
SnapshotAborted,
|
2017-05-17 12:41:33 +02:00
|
|
|
/// Bad epoch transition.
|
|
|
|
BadEpochProof(u64),
|
|
|
|
/// Wrong chunk format.
|
|
|
|
WrongChunkFormat(String),
|
2018-11-18 00:06:34 +01:00
|
|
|
/// Unlinked ancient block chain
|
|
|
|
UnlinkedAncientBlockChain,
|
2016-08-05 17:00:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for Error {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match *self {
|
2016-08-08 18:41:30 +02:00
|
|
|
Error::InvalidStartingBlock(ref id) => write!(f, "Invalid starting block: {:?}", id),
|
2016-08-05 17:00:46 +02:00
|
|
|
Error::BlockNotFound(ref hash) => write!(f, "Block not found in chain: {}", hash),
|
2016-10-28 16:10:30 +02:00
|
|
|
Error::IncompleteChain => write!(f, "Incomplete blockchain."),
|
|
|
|
Error::WrongStateRoot(ref expected, ref found) => write!(
|
|
|
|
f,
|
|
|
|
"Final block has wrong state root. Expected {:?}, got {:?}",
|
|
|
|
expected, found
|
|
|
|
),
|
|
|
|
Error::WrongBlockHash(ref num, ref expected, ref found) => write!(
|
|
|
|
f,
|
|
|
|
"Block {} had wrong hash. expected {:?}, got {:?}",
|
|
|
|
num, expected, found
|
|
|
|
),
|
|
|
|
Error::TooManyBlocks(ref expected, ref found) => write!(
|
|
|
|
f,
|
|
|
|
"Snapshot contained too many blocks. Expected {}, got {}",
|
|
|
|
expected, found
|
|
|
|
),
|
2016-08-08 18:41:30 +02:00
|
|
|
Error::OldBlockPrunedDB => write!(
|
|
|
|
f,
|
|
|
|
"Attempted to create a snapshot at an old block while using \
|
|
|
|
a pruned database. Please re-run with the --pruning archive flag."
|
2016-08-25 14:28:45 +02:00
|
|
|
),
|
|
|
|
Error::MissingCode(ref missing) => write!(
|
|
|
|
f,
|
|
|
|
"Incomplete snapshot: {} contract codes not found.",
|
|
|
|
missing.len()
|
|
|
|
),
|
|
|
|
Error::UnrecognizedCodeState(state) => {
|
|
|
|
write!(f, "Unrecognized code encoding ({})", state)
|
2020-08-05 06:08:03 +02:00
|
|
|
}
|
2016-11-13 13:52:53 +01:00
|
|
|
Error::RestorationAborted => write!(f, "Snapshot restoration aborted."),
|
2016-08-05 17:00:46 +02:00
|
|
|
Error::Io(ref err) => err.fmt(f),
|
|
|
|
Error::Decoder(ref err) => err.fmt(f),
|
|
|
|
Error::Trie(ref err) => err.fmt(f),
|
2017-03-24 14:02:04 +01:00
|
|
|
Error::VersionNotSupported(ref ver) => {
|
|
|
|
write!(f, "Snapshot version {} is not supprted.", ver)
|
2020-08-05 06:08:03 +02:00
|
|
|
}
|
2017-04-05 16:50:06 +02:00
|
|
|
Error::ChunkTooSmall => write!(f, "Chunk size is too small."),
|
2018-02-22 14:52:29 +01:00
|
|
|
Error::ChunkTooLarge => write!(f, "Chunk size is too large."),
|
2017-04-19 20:31:53 +02:00
|
|
|
Error::SnapshotsUnsupported => write!(f, "Snapshots unsupported by consensus engine."),
|
2019-06-25 15:38:29 +02:00
|
|
|
Error::SnapshotAborted => write!(f, "Snapshot was aborted."),
|
2017-05-17 12:41:33 +02:00
|
|
|
Error::BadEpochProof(i) => write!(f, "Bad epoch proof for transition to epoch {}", i),
|
|
|
|
Error::WrongChunkFormat(ref msg) => write!(f, "Wrong chunk format: {}", msg),
|
2018-11-18 00:06:34 +01:00
|
|
|
Error::UnlinkedAncientBlockChain => write!(f, "Unlinked ancient blocks chain"),
|
2016-08-05 17:00:46 +02:00
|
|
|
}
|
2020-08-05 06:08:03 +02:00
|
|
|
}
|
2016-08-05 17:00:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl From<::std::io::Error> for Error {
|
|
|
|
fn from(err: ::std::io::Error) -> Self {
|
|
|
|
Error::Io(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-10 16:29:40 +02:00
|
|
|
impl From<TrieError> for Error {
|
|
|
|
fn from(err: TrieError) -> Self {
|
|
|
|
Error::Trie(err)
|
2016-08-05 17:00:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<DecoderError> for Error {
|
|
|
|
fn from(err: DecoderError) -> Self {
|
|
|
|
Error::Decoder(err)
|
|
|
|
}
|
2016-08-10 16:29:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<E> From<Box<E>> for Error
|
|
|
|
where
|
|
|
|
Error: From<E>,
|
|
|
|
{
|
|
|
|
fn from(err: Box<E>) -> Self {
|
|
|
|
Error::from(*err)
|
|
|
|
}
|
|
|
|
}
|