Skip to content

Commit

Permalink
change(diagnostics): Updates error messages to include inner error ty…
Browse files Browse the repository at this point in the history
…pes (#9066)

* add: add consensus validation reason to error messages

* add additional instances
  • Loading branch information
conradoplg authored Dec 4, 2024
1 parent eb9e1f1 commit a3bb1e2
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 30 deletions.
2 changes: 1 addition & 1 deletion zebra-chain/src/history_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub enum HistoryTreeError {
#[non_exhaustive]
InnerError { inner: zcash_history::Error },

#[error("I/O error")]
#[error("I/O error: {0}")]
IOError(#[from] io::Error),
}

Expand Down
8 changes: 4 additions & 4 deletions zebra-consensus/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,19 @@ pub enum VerifyBlockError {
#[error(transparent)]
Time(zebra_chain::block::BlockTimeError),

#[error("unable to commit block after semantic verification")]
#[error("unable to commit block after semantic verification: {0}")]
// TODO: make this into a concrete type, and add it to is_duplicate_request() (#2908)
Commit(#[source] BoxError),

#[cfg(feature = "getblocktemplate-rpcs")]
#[error("unable to validate block proposal: failed semantic verification (proof of work is not checked for proposals)")]
#[error("unable to validate block proposal: failed semantic verification (proof of work is not checked for proposals): {0}")]
// TODO: make this into a concrete type (see #5732)
ValidateProposal(#[source] BoxError),

#[error("invalid transaction")]
#[error("invalid transaction: {0}")]
Transaction(#[from] TransactionError),

#[error("invalid block subsidy")]
#[error("invalid block subsidy: {0}")]
Subsidy(#[from] SubsidyError),
}

Expand Down
4 changes: 2 additions & 2 deletions zebra-consensus/src/checkpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -992,9 +992,9 @@ pub enum VerifyCheckpointError {
CheckpointList(BoxError),
#[error(transparent)]
VerifyBlock(VerifyBlockError),
#[error("invalid block subsidy")]
#[error("invalid block subsidy: {0}")]
SubsidyError(#[from] SubsidyError),
#[error("invalid amount")]
#[error("invalid amount: {0}")]
AmountError(#[from] amount::Error),
#[error("too many queued blocks at this height")]
QueuedLimit,
Expand Down
24 changes: 13 additions & 11 deletions zebra-consensus/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pub enum TransactionError {
transaction_hash: zebra_chain::transaction::Hash,
},

#[error("coinbase transaction failed subsidy validation")]
#[error("coinbase transaction failed subsidy validation: {0}")]
#[cfg_attr(any(test, feature = "proptest-impl"), proptest(skip))]
Subsidy(#[from] SubsidyError),

Expand All @@ -140,7 +140,7 @@ pub enum TransactionError {
#[error("if there are no Spends or Outputs, the value balance MUST be 0.")]
BadBalance,

#[error("could not verify a transparent script")]
#[error("could not verify a transparent script: {0}")]
#[cfg_attr(any(test, feature = "proptest-impl"), proptest(skip))]
Script(#[from] zebra_script::Error),

Expand All @@ -149,29 +149,29 @@ pub enum TransactionError {

// TODO: the underlying error is bellman::VerificationError, but it does not implement
// Arbitrary as required here.
#[error("spend proof MUST be valid given a primary input formed from the other fields except spendAuthSig")]
#[error("spend proof MUST be valid given a primary input formed from the other fields except spendAuthSig: {0}")]
Groth16(String),

// TODO: the underlying error is io::Error, but it does not implement Clone as required here.
#[error("Groth16 proof is malformed")]
#[error("Groth16 proof is malformed: {0}")]
MalformedGroth16(String),

#[error(
"Sprout joinSplitSig MUST represent a valid signature under joinSplitPubKey of dataToBeSigned"
"Sprout joinSplitSig MUST represent a valid signature under joinSplitPubKey of dataToBeSigned: {0}"
)]
#[cfg_attr(any(test, feature = "proptest-impl"), proptest(skip))]
Ed25519(#[from] zebra_chain::primitives::ed25519::Error),

#[error("Sapling bindingSig MUST represent a valid signature under the transaction binding validating key bvk of SigHash")]
#[error("Sapling bindingSig MUST represent a valid signature under the transaction binding validating key bvk of SigHash: {0}")]
#[cfg_attr(any(test, feature = "proptest-impl"), proptest(skip))]
RedJubjub(zebra_chain::primitives::redjubjub::Error),

#[error("Orchard bindingSig MUST represent a valid signature under the transaction binding validating key bvk of SigHash")]
#[error("Orchard bindingSig MUST represent a valid signature under the transaction binding validating key bvk of SigHash: {0}")]
#[cfg_attr(any(test, feature = "proptest-impl"), proptest(skip))]
RedPallas(zebra_chain::primitives::reddsa::Error),

// temporary error type until #1186 is fixed
#[error("Downcast from BoxError to redjubjub::Error failed")]
#[error("Downcast from BoxError to redjubjub::Error failed: {0}")]
InternalDowncastError(String),

#[error("either vpub_old or vpub_new must be zero")]
Expand Down Expand Up @@ -201,12 +201,12 @@ pub enum TransactionError {
#[error("could not find a mempool transaction input UTXO in the best chain")]
TransparentInputNotFound,

#[error("could not validate nullifiers and anchors on best chain")]
#[error("could not validate nullifiers and anchors on best chain: {0}")]
#[cfg_attr(any(test, feature = "proptest-impl"), proptest(skip))]
// This error variant is at least 128 bytes
ValidateContextError(Box<ValidateContextError>),

#[error("could not validate mempool transaction lock time on best chain")]
#[error("could not validate mempool transaction lock time on best chain: {0}")]
#[cfg_attr(any(test, feature = "proptest-impl"), proptest(skip))]
// TODO: turn this into a typed error
ValidateMempoolLockTimeError(String),
Expand Down Expand Up @@ -236,7 +236,9 @@ pub enum TransactionError {
min_spend_height: block::Height,
},

#[error("failed to verify ZIP-317 transaction rules, transaction was not inserted to mempool")]
#[error(
"failed to verify ZIP-317 transaction rules, transaction was not inserted to mempool: {0}"
)]
#[cfg_attr(any(test, feature = "proptest-impl"), proptest(skip))]
Zip317(#[from] zebra_chain::transaction::zip317::Error),
}
Expand Down
4 changes: 2 additions & 2 deletions zebra-network/src/peer/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,10 @@ pub enum HandshakeError {
#[error("Peer closed connection")]
ConnectionClosed,
/// An error occurred while performing an IO operation.
#[error("Underlying IO error")]
#[error("Underlying IO error: {0}")]
Io(#[from] std::io::Error),
/// A serialization error occurred while reading or writing a message.
#[error("Serialization error")]
#[error("Serialization error: {0}")]
Serialization(#[from] SerializationError),
/// The remote peer offered a version older than our minimum version.
#[error("Peer offered obsolete version: {0:?}")]
Expand Down
6 changes: 3 additions & 3 deletions zebra-state/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,13 @@ pub enum ValidateContextError {
height: Option<block::Height>,
},

#[error("error updating a note commitment tree")]
#[error("error updating a note commitment tree: {0}")]
NoteCommitmentTreeError(#[from] zebra_chain::parallel::tree::NoteCommitmentTreeError),

#[error("error building the history tree")]
#[error("error building the history tree: {0}")]
HistoryTreeError(#[from] Arc<HistoryTreeError>),

#[error("block contains an invalid commitment")]
#[error("block contains an invalid commitment: {0}")]
InvalidBlockCommitment(#[from] block::CommitmentError),

#[error(
Expand Down
6 changes: 3 additions & 3 deletions zebrad/src/components/mempool/downloads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,16 @@ pub enum TransactionDownloadVerifyError {
#[error("transaction is already in state")]
InState,

#[error("error in state service")]
#[error("error in state service: {0}")]
StateError(#[source] CloneError),

#[error("error downloading transaction")]
#[error("error downloading transaction: {0}")]
DownloadFailed(#[source] CloneError),

#[error("transaction download / verification was cancelled")]
Cancelled,

#[error("transaction did not pass consensus validation")]
#[error("transaction did not pass consensus validation: {0}")]
Invalid(#[from] zebra_consensus::error::TransactionError),
}

Expand Down
8 changes: 5 additions & 3 deletions zebrad/src/components/mempool/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ pub enum MempoolError {
///
/// Note that the mempool caches this error. See [`super::storage::Storage`]
/// for more details.
#[error("the transaction will be rejected from the mempool until the next chain tip block")]
#[error(
"the transaction will be rejected from the mempool until the next chain tip block: {0}"
)]
StorageExactTip(#[from] ExactTipRejectionError),

/// Transaction rejected based on its effects (spends, outputs, transaction
Expand All @@ -33,7 +35,7 @@ pub enum MempoolError {
///
/// Note that the mempool caches this error. See [`super::storage::Storage`]
/// for more details.
#[error("any transaction with the same effects will be rejected from the mempool until the next chain tip block")]
#[error("any transaction with the same effects will be rejected from the mempool until the next chain tip block: {0}")]
StorageEffectsTip(#[from] SameEffectsTipRejectionError),

/// Transaction rejected based on its effects (spends, outputs, transaction
Expand All @@ -44,7 +46,7 @@ pub enum MempoolError {
///
/// Note that the mempool caches this error. See [`super::storage::Storage`]
/// for more details.
#[error("any transaction with the same effects will be rejected from the mempool until a chain reset")]
#[error("any transaction with the same effects will be rejected from the mempool until a chain reset: {0}")]
StorageEffectsChain(#[from] SameEffectsChainRejectionError),

/// Transaction rejected because the mempool already contains another
Expand Down
2 changes: 1 addition & 1 deletion zebrad/src/components/mempool/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub(crate) const MAX_EVICTION_MEMORY_ENTRIES: usize = 40_000;
#[cfg_attr(any(test, feature = "proptest-impl"), derive(Arbitrary))]
#[allow(dead_code)]
pub enum ExactTipRejectionError {
#[error("transaction did not pass consensus validation")]
#[error("transaction did not pass consensus validation: {0}")]
FailedVerification(#[from] zebra_consensus::error::TransactionError),
}

Expand Down

0 comments on commit a3bb1e2

Please sign in to comment.