spl_slashing/
error.rs

1//! Error types
2
3use {
4    num_derive::FromPrimitive,
5    solana_program::{decode_error::DecodeError, program_error::ProgramError},
6    thiserror::Error,
7};
8
9/// Errors that may be returned by the program.
10#[derive(Clone, Copy, Debug, Eq, Error, FromPrimitive, PartialEq)]
11pub enum SlashingError {
12    /// Violation is too old for statue of limitations
13    #[error("Exceeds statue of limitations")]
14    ExceedsStatueOfLimitations,
15
16    /// Invalid shred variant
17    #[error("Invalid shred variant")]
18    InvalidShredVariant,
19
20    /// Invalid merkle shred
21    #[error("Invalid Merkle shred")]
22    InvalidMerkleShred,
23
24    /// Invalid duplicate block payload proof
25    #[error("Invalid payload proof")]
26    InvalidPayloadProof,
27
28    /// Invalid duplicate block erasure meta proof
29    #[error("Invalid erasure meta conflict")]
30    InvalidErasureMetaConflict,
31
32    /// Invalid instruction
33    #[error("Invalid instruction")]
34    InvalidInstruction,
35
36    /// Invalid duplicate block last index proof
37    #[error("Invalid last index conflict")]
38    InvalidLastIndexConflict,
39
40    /// Invalid shred version on duplicate block proof shreds
41    #[error("Invalid shred version")]
42    InvalidShredVersion,
43
44    /// Invalid signature on duplicate block proof shreds
45    #[error("Invalid signature")]
46    InvalidSignature,
47
48    /// Legacy shreds are not supported
49    #[error("Legacy shreds are not eligible for slashing")]
50    LegacyShreds,
51
52    /// Unable to deserialize proof buffer
53    #[error("Proof buffer deserialization error")]
54    ProofBufferDeserializationError,
55
56    /// Proof buffer is too small
57    #[error("Proof buffer too small")]
58    ProofBufferTooSmall,
59
60    /// Shred deserialization error
61    #[error("Deserialization error")]
62    ShredDeserializationError,
63
64    /// Invalid shred type on duplicate block proof shreds
65    #[error("Shred type mismatch")]
66    ShredTypeMismatch,
67
68    /// Invalid slot on duplicate block proof shreds
69    #[error("Slot mismatch")]
70    SlotMismatch,
71}
72
73impl From<SlashingError> for ProgramError {
74    fn from(e: SlashingError) -> Self {
75        ProgramError::Custom(e as u32)
76    }
77}
78
79impl<T> DecodeError<T> for SlashingError {
80    fn type_of() -> &'static str {
81        "Slashing Error"
82    }
83}