zebrad/components/mempool/
error.rs

1//! Errors that can occur when interacting with the mempool.
2//!
3//! Most of the mempool errors are related to manipulating transactions in the
4//! mempool.
5
6use thiserror::Error;
7
8#[cfg(any(test, feature = "proptest-impl"))]
9use proptest_derive::Arbitrary;
10
11use super::storage::{
12    ExactTipRejectionError, SameEffectsChainRejectionError, SameEffectsTipRejectionError,
13};
14
15/// Mempool errors.
16#[derive(Error, Clone, Debug, PartialEq, Eq)]
17#[cfg_attr(any(test, feature = "proptest-impl"), derive(Arbitrary))]
18pub enum MempoolError {
19    /// Transaction rejected based on its authorizing data (scripts, proofs,
20    /// signatures). The rejection is valid for the current chain tip.
21    ///
22    /// See [`ExactTipRejectionError`] for more details.
23    ///
24    /// Note that the mempool caches this error. See [`super::storage::Storage`]
25    /// for more details.
26    #[error(
27        "the transaction will be rejected from the mempool until the next chain tip block: {0}"
28    )]
29    StorageExactTip(#[from] ExactTipRejectionError),
30
31    /// Transaction rejected based on its effects (spends, outputs, transaction
32    /// header). The rejection is valid for the current chain tip.
33    ///
34    /// See [`SameEffectsTipRejectionError`] for more details.
35    ///
36    /// Note that the mempool caches this error. See [`super::storage::Storage`]
37    /// for more details.
38    #[error("any transaction with the same effects will be rejected from the mempool until the next chain tip block: {0}")]
39    StorageEffectsTip(#[from] SameEffectsTipRejectionError),
40
41    /// Transaction rejected based on its effects (spends, outputs, transaction
42    /// header). The rejection is valid while the current chain continues to
43    /// grow.
44    ///
45    /// See [`SameEffectsChainRejectionError`] for more details.
46    ///
47    /// Note that the mempool caches this error. See [`super::storage::Storage`]
48    /// for more details.
49    #[error("any transaction with the same effects will be rejected from the mempool until a chain reset: {0}")]
50    StorageEffectsChain(#[from] SameEffectsChainRejectionError),
51
52    /// Transaction rejected because the mempool already contains another
53    /// transaction with the same hash.
54    #[error("transaction already exists in mempool")]
55    InMempool,
56
57    /// The transaction hash is already queued, so this request was ignored.
58    ///
59    /// Another peer has already gossiped the same hash to us, or the mempool crawler has fetched it.
60    #[error("transaction dropped because it is already queued for download")]
61    AlreadyQueued,
62
63    /// The queue is at capacity, so this request was ignored.
64    ///
65    /// The mempool crawler should discover this transaction later.
66    /// If it is mined into a block, it will be downloaded by the syncer, or the inbound block downloader.
67    ///
68    /// The queue's capacity is [`super::downloads::MAX_INBOUND_CONCURRENCY`].
69    #[error("transaction dropped because the queue is full")]
70    FullQueue,
71
72    /// The mempool is not enabled yet.
73    ///
74    /// Zebra enables the mempool when it is at the chain tip.
75    #[error("mempool is disabled since synchronization is behind the chain tip")]
76    Disabled,
77}