kaspa_consensus_core/
blockstatus.rs

1use kaspa_utils::mem_size::MemSizeEstimator;
2use serde::{Deserialize, Serialize};
3
4#[derive(Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Debug)]
5pub enum BlockStatus {
6    /// StatusInvalid indicates that the block is invalid.
7    StatusInvalid,
8
9    /// StatusUTXOValid indicates the block is valid from any UTXO related aspects and has passed all the other validations as well.
10    StatusUTXOValid,
11
12    /// StatusUTXOPendingVerification indicates that the block is pending verification against its past UTXO-Set, either
13    /// because it was not yet verified since the block was never in the selected parent chain, or if the
14    /// block violates finality.
15    StatusUTXOPendingVerification,
16
17    /// StatusDisqualifiedFromChain indicates that the block is not eligible to be a selected parent.
18    StatusDisqualifiedFromChain,
19
20    /// StatusHeaderOnly indicates that the block transactions are not held (pruned or wasn't added yet)
21    StatusHeaderOnly,
22}
23
24impl MemSizeEstimator for BlockStatus {}
25
26impl BlockStatus {
27    pub fn has_block_header(self) -> bool {
28        matches!(
29            self,
30            Self::StatusHeaderOnly | Self::StatusUTXOValid | Self::StatusUTXOPendingVerification | Self::StatusDisqualifiedFromChain
31        )
32    }
33
34    pub fn is_header_only(self) -> bool {
35        self == Self::StatusHeaderOnly
36    }
37
38    pub fn has_block_body(self) -> bool {
39        matches!(self, Self::StatusUTXOValid | Self::StatusUTXOPendingVerification | Self::StatusDisqualifiedFromChain)
40    }
41
42    pub fn is_utxo_valid_or_pending(self) -> bool {
43        matches!(self, Self::StatusUTXOValid | Self::StatusUTXOPendingVerification)
44    }
45
46    pub fn is_valid(self) -> bool {
47        self != BlockStatus::StatusInvalid
48    }
49
50    pub fn is_invalid(self) -> bool {
51        self == BlockStatus::StatusInvalid
52    }
53}