2020-09-21 11:54:06 -07:00
|
|
|
//! Consensus validation errors
|
|
|
|
|
|
|
|
use thiserror::Error;
|
|
|
|
|
2020-10-12 13:54:48 -07:00
|
|
|
#[derive(Error, Debug, PartialEq)]
|
|
|
|
pub enum SubsidyError {
|
|
|
|
#[error("no coinbase transaction in block")]
|
|
|
|
NoCoinbase,
|
|
|
|
|
|
|
|
#[error("founders reward output not found")]
|
|
|
|
FoundersRewardNotFound,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Error, Debug, PartialEq)]
|
2020-09-21 11:54:06 -07:00
|
|
|
pub enum TransactionError {
|
|
|
|
#[error("first transaction must be coinbase")]
|
|
|
|
CoinbasePosition,
|
|
|
|
|
|
|
|
#[error("coinbase input found in non-coinbase transaction")]
|
|
|
|
CoinbaseInputFound,
|
2020-10-12 13:54:48 -07:00
|
|
|
|
|
|
|
#[error("coinbase transaction failed subsidy validation")]
|
|
|
|
Subsidy(#[from] SubsidyError),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<SubsidyError> for BlockError {
|
|
|
|
fn from(err: SubsidyError) -> BlockError {
|
|
|
|
BlockError::Transaction(TransactionError::Subsidy(err))
|
|
|
|
}
|
2020-09-21 11:54:06 -07:00
|
|
|
}
|
|
|
|
|
2020-10-12 13:54:48 -07:00
|
|
|
#[derive(Error, Debug, PartialEq)]
|
2020-09-21 11:54:06 -07:00
|
|
|
pub enum BlockError {
|
|
|
|
#[error("block contains invalid transactions")]
|
|
|
|
Transaction(#[from] TransactionError),
|
|
|
|
|
|
|
|
#[error("block haves no transactions")]
|
|
|
|
NoTransactions,
|
|
|
|
|
|
|
|
#[error("block {0:?} is already in the chain at depth {1:?}")]
|
|
|
|
AlreadyInChain(zebra_chain::block::Hash, u32),
|
|
|
|
|
|
|
|
#[error("invalid block {0:?}: missing block height")]
|
|
|
|
MissingHeight(zebra_chain::block::Hash),
|
|
|
|
|
|
|
|
#[error("invalid block height {0:?} in {1:?}: greater than the maximum height {2:?}")]
|
|
|
|
MaxHeight(
|
|
|
|
zebra_chain::block::Height,
|
|
|
|
zebra_chain::block::Hash,
|
|
|
|
zebra_chain::block::Height,
|
|
|
|
),
|
|
|
|
|
|
|
|
#[error("invalid difficulty threshold in block header {0:?} {1:?}")]
|
|
|
|
InvalidDifficulty(zebra_chain::block::Height, zebra_chain::block::Hash),
|
|
|
|
|
|
|
|
#[error("block {0:?} failed the difficulty filter: hash {1:?} must be less than or equal to the difficulty threshold {2:?}")]
|
|
|
|
DifficultyFilter(
|
|
|
|
zebra_chain::block::Height,
|
|
|
|
zebra_chain::block::Hash,
|
|
|
|
zebra_chain::work::difficulty::ExpandedDifficulty,
|
|
|
|
),
|
|
|
|
}
|