penumbra_sdk_tct/
error.rs

1//! Errors that can occur when inserting into a [`Tree`], deserializing [`Proof`](super::Proof)s, or
2//! checking internal invariants.
3
4use crate::builder;
5#[cfg(doc)]
6use crate::prelude::*;
7
8#[doc(inline)]
9pub use crate::tree::RootDecodeError;
10
11pub mod proof {
12    //! Errors from deserializing or verifying inclusion proofs.
13    #[doc(inline)]
14    pub use crate::internal::{
15        path::PathDecodeError,
16        proof::{ProofDecodeError as DecodeError, VerifyError},
17    };
18}
19
20pub mod block {
21    //! Errors for [`block`](self) builders.
22
23    /// An error occurred when decoding a [`block::Root`](crate::builder::block::Root) from bytes.
24    #[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
25    #[error("could not decode block root")]
26    pub struct RootDecodeError;
27
28    /// When inserting into a [`block::Builder`](crate::builder::block::Builder), this error is
29    /// returned when it is full.
30    #[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
31    #[error("block is full")]
32    #[non_exhaustive]
33    pub struct InsertError;
34}
35
36pub mod epoch {
37    //! Errors for [`epoch`] builders.
38    use super::*;
39
40    /// An error occurred when decoding an [`epoch::Root`](builder::epoch::Root) from bytes.
41    #[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
42    #[error("could not decode epoch root")]
43    pub struct RootDecodeError;
44
45    /// A [`Commitment`] could not be inserted into the [`epoch::Builder`](builder::epoch::Builder).
46    #[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
47    pub enum InsertError {
48        /// The [`epoch::Builder`](builder::epoch::Builder) was full.
49        #[error("epoch is full")]
50        #[non_exhaustive]
51        Full,
52        /// The most recent block in the [`epoch::Builder`](builder::epoch::Builder) was full.
53        #[error("most recent block in epoch is full")]
54        #[non_exhaustive]
55        BlockFull,
56    }
57
58    /// The [`epoch::Builder`](builder::epoch::Builder) was full when attempting to insert a block.
59    #[derive(Debug, Clone, Error)]
60    #[error("epoch is full")]
61    #[non_exhaustive]
62    pub struct InsertBlockError(pub builder::block::Finalized);
63}
64
65/// An error occurred when trying to insert a [`Commitment`] into a [`Tree`].
66#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
67pub enum InsertError {
68    /// The [`Tree`] was full.
69    #[error("tree is full")]
70    Full,
71    /// The most recent epoch of the [`Tree`] was full.
72    #[error("most recent epoch in tree is full")]
73    EpochFull,
74    /// The most recent block of the most recent epoch of the [`Tree`] was full.
75    #[error("most recent block in most recent epoch of tree is full")]
76    BlockFull,
77}
78
79/// An error occurred when trying to insert a block into the [`Tree`].
80#[derive(Debug, Clone, Error)]
81pub enum InsertBlockError {
82    /// The [`Tree`] was full.
83    #[error("tree is full")]
84    #[non_exhaustive]
85    Full(builder::block::Finalized),
86    /// The most recent epoch of the [`Tree`] was full.
87    #[error("most recent epoch is full")]
88    #[non_exhaustive]
89    EpochFull(builder::block::Finalized),
90}
91
92impl From<InsertBlockError> for builder::block::Finalized {
93    fn from(error: InsertBlockError) -> Self {
94        match error {
95            InsertBlockError::Full(block) => block,
96            InsertBlockError::EpochFull(block) => block,
97        }
98    }
99}
100
101/// The [`Tree`] was full when trying to insert an epoch into it.
102#[derive(Debug, Clone, Error)]
103#[error("tree is full")]
104#[non_exhaustive]
105pub struct InsertEpochError(pub builder::epoch::Finalized);
106
107impl From<InsertEpochError> for builder::epoch::Finalized {
108    fn from(error: InsertEpochError) -> Self {
109        error.0
110    }
111}
112
113#[cfg(test)]
114mod test {
115    use super::*;
116
117    #[test]
118    fn insert_errors_sync_send() {
119        static_assertions::assert_impl_all!(InsertError: Sync, Send);
120        static_assertions::assert_impl_all!(InsertBlockError: Sync, Send);
121        static_assertions::assert_impl_all!(InsertEpochError: Sync, Send);
122    }
123}