mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 15:11:03 +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
@@ -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(())
|
||||
|
||||
Reference in New Issue
Block a user