mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 01:11:10 +00:00
Expunge error-chain (feat. tomaka) (#2662)
* Remove error_chain * Expunge error-chain from rpc and service. * Expunge from transaction pool. * Expunge from node/cli * Expunge from keystore. * Remove some boilerplate. * Fix remaining stuff. * Improve on deprecation message. * Fix issues. * Fix trnsaction pool tests. * Fix the rest. * Fix borked merge. * Update lock
This commit is contained in:
committed by
Gavin Wood
parent
69ffec5822
commit
c162fc5ff1
@@ -16,100 +16,69 @@
|
||||
|
||||
//! Error types in Consensus
|
||||
use runtime_version::RuntimeVersion;
|
||||
use error_chain::{error_chain, error_chain_processing, impl_error_chain_processed,
|
||||
impl_extract_backtrace, impl_error_chain_kind};
|
||||
use primitives::ed25519::{Public, Signature};
|
||||
use std::error;
|
||||
|
||||
error_chain! {
|
||||
errors {
|
||||
/// Missing state at block with given descriptor.
|
||||
StateUnavailable(b: String) {
|
||||
description("State missing at given block."),
|
||||
display("State unavailable at block {}", b),
|
||||
}
|
||||
/// Result type alias.
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
/// I/O terminated unexpectedly
|
||||
IoTerminated {
|
||||
description("I/O terminated unexpectedly."),
|
||||
display("I/O terminated unexpectedly."),
|
||||
}
|
||||
/// Error type.
|
||||
#[derive(Debug, derive_more::Display, derive_more::From)]
|
||||
pub enum Error {
|
||||
/// Missing state at block with given descriptor.
|
||||
#[display(fmt="State unavailable at block {}", _0)]
|
||||
StateUnavailable(String),
|
||||
/// I/O terminated unexpectedly
|
||||
#[display(fmt="I/O terminated unexpectedly.")]
|
||||
IoTerminated,
|
||||
/// Unable to schedule wakeup.
|
||||
#[display(fmt="Timer error: {}", _0)]
|
||||
FaultyTimer(tokio_timer::Error),
|
||||
/// Error while working with inherent data.
|
||||
#[display(fmt="InherentData error: {}", _0)]
|
||||
InherentData(String),
|
||||
/// Unable to propose a block.
|
||||
#[display(fmt="Unable to create block proposal.")]
|
||||
CannotPropose,
|
||||
/// Error checking signature
|
||||
#[display(fmt="Message signature {:?} by {:?} is invalid.", _0, _1)]
|
||||
InvalidSignature(Signature, Public),
|
||||
/// Invalid authorities set received from the runtime.
|
||||
#[display(fmt="Current state of blockchain has invalid authorities set")]
|
||||
InvalidAuthoritiesSet,
|
||||
/// Account is not an authority.
|
||||
#[display(fmt="Message sender {:?} is not a valid authority.", _0)]
|
||||
InvalidAuthority(Public),
|
||||
/// Authoring interface does not match the runtime.
|
||||
#[display(fmt="Authoring for current \
|
||||
runtime is not supported. Native ({}) cannot author for on-chain ({}).", native, on_chain)]
|
||||
IncompatibleAuthoringRuntime { native: RuntimeVersion, on_chain: RuntimeVersion },
|
||||
/// Authoring interface does not match the runtime.
|
||||
#[display(fmt="Authoring for current runtime is not supported since it has no version.")]
|
||||
RuntimeVersionMissing,
|
||||
/// Authoring interface does not match the runtime.
|
||||
#[display(fmt="Authoring in current build is not supported since it has no runtime.")]
|
||||
NativeRuntimeMissing,
|
||||
/// Justification requirements not met.
|
||||
#[display(fmt="Invalid justification.")]
|
||||
InvalidJustification,
|
||||
/// Some other error.
|
||||
#[display(fmt="Other error: {}", _0)]
|
||||
Other(Box<error::Error + Send>),
|
||||
/// Error from the client while importing
|
||||
#[display(fmt="Import failed: {}", _0)]
|
||||
ClientImport(String),
|
||||
/// Error from the client while importing
|
||||
#[display(fmt="Chain lookup failed: {}", _0)]
|
||||
ChainLookup(String),
|
||||
}
|
||||
|
||||
/// Unable to schedule wakeup.
|
||||
FaultyTimer(e: ::tokio_timer::Error) {
|
||||
description("Timer error"),
|
||||
display("Timer error: {}", e),
|
||||
}
|
||||
|
||||
/// Error while working with inherent data.
|
||||
InherentData(e: String) {
|
||||
description("InherentData error"),
|
||||
display("InherentData error: {}", e),
|
||||
}
|
||||
|
||||
/// Unable to propose a block.
|
||||
CannotPropose {
|
||||
description("Unable to create block proposal."),
|
||||
display("Unable to create block proposal."),
|
||||
}
|
||||
|
||||
/// Error checking signature
|
||||
InvalidSignature(s: Signature, a: Public) {
|
||||
description("Message signature is invalid"),
|
||||
display("Message signature {:?} by {:?} is invalid.", s, a),
|
||||
}
|
||||
|
||||
/// Invalid authorities set received from the runtime.
|
||||
InvalidAuthoritiesSet {
|
||||
description("authorities set is invalid"),
|
||||
display("Current state of blockchain has invalid authorities set"),
|
||||
}
|
||||
|
||||
/// Account is not an authority.
|
||||
InvalidAuthority(a: Public) {
|
||||
description("Message sender is not a valid authority"),
|
||||
display("Message sender {:?} is not a valid authority.", a),
|
||||
}
|
||||
|
||||
/// Authoring interface does not match the runtime.
|
||||
IncompatibleAuthoringRuntime(native: RuntimeVersion, on_chain: RuntimeVersion) {
|
||||
description("Authoring for current runtime is not supported"),
|
||||
display("Authoring for current runtime is not supported. Native ({}) cannot author for on-chain ({}).", native, on_chain),
|
||||
}
|
||||
|
||||
/// Authoring interface does not match the runtime.
|
||||
RuntimeVersionMissing {
|
||||
description("Current runtime has no version"),
|
||||
display("Authoring for current runtime is not supported since it has no version."),
|
||||
}
|
||||
|
||||
/// Authoring interface does not match the runtime.
|
||||
NativeRuntimeMissing {
|
||||
description("This build has no native runtime"),
|
||||
display("Authoring in current build is not supported since it has no runtime."),
|
||||
}
|
||||
|
||||
/// Justification requirements not met.
|
||||
InvalidJustification {
|
||||
description("Invalid justification"),
|
||||
display("Invalid justification."),
|
||||
}
|
||||
|
||||
/// Some other error.
|
||||
Other(e: Box<::std::error::Error + Send>) {
|
||||
description("Other error")
|
||||
display("Other error: {}", e.description())
|
||||
}
|
||||
|
||||
/// Error from the client while importing
|
||||
ClientImport(reason: String) {
|
||||
description("Import failed"),
|
||||
display("Import failed: {}", reason),
|
||||
}
|
||||
|
||||
/// Error from the client while importing
|
||||
ChainLookup(reason: String) {
|
||||
description("Looking up chain failed"),
|
||||
display("Chain lookup failed: {}", reason),
|
||||
impl error::Error for Error {
|
||||
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
|
||||
match self {
|
||||
Error::FaultyTimer(ref err) => Some(err),
|
||||
Error::Other(ref err) => Some(&**err),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,37 +20,36 @@ use super::MAX_BLOCK_SIZE;
|
||||
|
||||
use parity_codec::Encode;
|
||||
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, One, CheckedConversion};
|
||||
use error_chain::{error_chain, error_chain_processing, impl_error_chain_processed,
|
||||
impl_extract_backtrace, impl_error_chain_kind, bail};
|
||||
|
||||
// This is just a best effort to encode the number. None indicated that it's too big to encode
|
||||
// in a u128.
|
||||
type BlockNumber = Option<u128>;
|
||||
|
||||
error_chain! {
|
||||
errors {
|
||||
BadProposalFormat {
|
||||
description("Proposal provided not a block."),
|
||||
display("Proposal provided not a block."),
|
||||
}
|
||||
WrongParentHash(expected: String, got: String) {
|
||||
description("Proposal had wrong parent hash."),
|
||||
display("Proposal had wrong parent hash. Expected {:?}, got {:?}", expected, got),
|
||||
}
|
||||
WrongNumber(expected: BlockNumber, got: BlockNumber) {
|
||||
description("Proposal had wrong number."),
|
||||
display("Proposal had wrong number. Expected {:?}, got {:?}", expected, got),
|
||||
}
|
||||
ProposalTooLarge(size: usize) {
|
||||
description("Proposal exceeded the maximum size."),
|
||||
display(
|
||||
"Proposal exceeded the maximum size of {} by {} bytes.",
|
||||
MAX_BLOCK_SIZE, size.saturating_sub(MAX_BLOCK_SIZE)
|
||||
),
|
||||
}
|
||||
}
|
||||
/// Result type alias.
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
/// Error type.
|
||||
#[derive(Debug, derive_more::Display)]
|
||||
pub enum Error {
|
||||
/// Proposal provided not a block.
|
||||
#[display(fmt="Proposal provided not a block.")]
|
||||
BadProposalFormat,
|
||||
/// Proposal had wrong parent hash.
|
||||
#[display(fmt="Proposal had wrong parent hash. Expected {:?}, got {:?}", expected, got)]
|
||||
WrongParentHash { expected: String, got: String },
|
||||
/// Proposal had wrong number.
|
||||
#[display(fmt="Proposal had wrong number. Expected {:?}, got {:?}", expected, got)]
|
||||
WrongNumber { expected: BlockNumber, got: BlockNumber },
|
||||
/// Proposal exceeded the maximum size.
|
||||
#[display(
|
||||
fmt="Proposal exceeded the maximum size of {} by {} bytes.",
|
||||
"MAX_BLOCK_SIZE", "_0.saturating_sub(MAX_BLOCK_SIZE)"
|
||||
)]
|
||||
ProposalTooLarge(usize),
|
||||
}
|
||||
|
||||
impl std::error::Error for Error {}
|
||||
|
||||
/// Attempt to evaluate a substrate block as a node block, returning error
|
||||
/// upon any initial validity checks failing.
|
||||
pub fn evaluate_initial<Block: BlockT>(
|
||||
@@ -61,24 +60,24 @@ pub fn evaluate_initial<Block: BlockT>(
|
||||
|
||||
let encoded = Encode::encode(proposal);
|
||||
let proposal = Block::decode(&mut &encoded[..])
|
||||
.ok_or_else(|| ErrorKind::BadProposalFormat)?;
|
||||
.ok_or_else(|| Error::BadProposalFormat)?;
|
||||
|
||||
if encoded.len() > MAX_BLOCK_SIZE {
|
||||
bail!(ErrorKind::ProposalTooLarge(encoded.len()))
|
||||
return Err(Error::ProposalTooLarge(encoded.len()))
|
||||
}
|
||||
|
||||
if *parent_hash != *proposal.header().parent_hash() {
|
||||
bail!(ErrorKind::WrongParentHash(
|
||||
format!("{:?}", *parent_hash),
|
||||
format!("{:?}", proposal.header().parent_hash())
|
||||
));
|
||||
return Err(Error::WrongParentHash {
|
||||
expected: format!("{:?}", *parent_hash),
|
||||
got: format!("{:?}", proposal.header().parent_hash())
|
||||
});
|
||||
}
|
||||
|
||||
if parent_number + One::one() != *proposal.header().number() {
|
||||
bail!(ErrorKind::WrongNumber(
|
||||
parent_number.checked_into::<u128>().map(|x| x + 1),
|
||||
(*proposal.header().number()).checked_into::<u128>()
|
||||
));
|
||||
return Err(Error::WrongNumber {
|
||||
expected: parent_number.checked_into::<u128>().map(|x| x + 1),
|
||||
got: (*proposal.header().number()).checked_into::<u128>(),
|
||||
});
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -47,7 +47,7 @@ pub mod evaluation;
|
||||
// block size limit.
|
||||
const MAX_BLOCK_SIZE: usize = 4 * 1024 * 1024 + 512;
|
||||
|
||||
pub use self::error::{Error, ErrorKind};
|
||||
pub use self::error::Error;
|
||||
pub use block_import::{
|
||||
BlockImport, BlockOrigin, ForkChoiceStrategy, ImportedAux, ImportBlock, ImportResult,
|
||||
JustificationImport, FinalityProofImport, FinalityProofRequestBuilder,
|
||||
|
||||
Reference in New Issue
Block a user