solana_vote_interface/
error.rs

1//! Vote program errors
2
3use {
4    core::fmt,
5    num_derive::{FromPrimitive, ToPrimitive},
6};
7
8/// Reasons the vote might have had an error
9#[derive(Debug, Clone, PartialEq, Eq, FromPrimitive, ToPrimitive)]
10pub enum VoteError {
11    VoteTooOld,
12    SlotsMismatch,
13    SlotHashMismatch,
14    EmptySlots,
15    TimestampTooOld,
16    TooSoonToReauthorize,
17    // TODO: figure out how to migrate these new errors
18    LockoutConflict,
19    NewVoteStateLockoutMismatch,
20    SlotsNotOrdered,
21    ConfirmationsNotOrdered,
22    ZeroConfirmations,
23    ConfirmationTooLarge,
24    RootRollBack,
25    ConfirmationRollBack,
26    SlotSmallerThanRoot,
27    TooManyVotes,
28    VotesTooOldAllFiltered,
29    RootOnDifferentFork,
30    ActiveVoteAccountClose,
31    CommissionUpdateTooLate,
32    AssertionFailed,
33}
34
35impl core::error::Error for VoteError {}
36
37impl fmt::Display for VoteError {
38    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
39        f.write_str(match self {
40            Self::VoteTooOld => "vote already recorded or not in slot hashes history",
41            Self::SlotsMismatch => "vote slots do not match bank history",
42            Self::SlotHashMismatch => "vote hash does not match bank hash",
43            Self::EmptySlots => "vote has no slots, invalid",
44            Self::TimestampTooOld => "vote timestamp not recent",
45            Self::TooSoonToReauthorize => "authorized voter has already been changed this epoch",
46            Self::LockoutConflict => {
47                "Old state had vote which should not have been popped off by vote in new state"
48            }
49            Self::NewVoteStateLockoutMismatch => {
50                "Proposed state had earlier slot which should have been popped off by later vote"
51            }
52            Self::SlotsNotOrdered => "Vote slots are not ordered",
53            Self::ConfirmationsNotOrdered => "Confirmations are not ordered",
54            Self::ZeroConfirmations => "Zero confirmations",
55            Self::ConfirmationTooLarge => "Confirmation exceeds limit",
56            Self::RootRollBack => "Root rolled back",
57            Self::ConfirmationRollBack => {
58                "Confirmations for same vote were smaller in new proposed state"
59            }
60            Self::SlotSmallerThanRoot => "New state contained a vote slot smaller than the root",
61            Self::TooManyVotes => "New state contained too many votes",
62            Self::VotesTooOldAllFiltered => {
63                "every slot in the vote was older than the SlotHashes history"
64            }
65            Self::RootOnDifferentFork => "Proposed root is not in slot hashes",
66            Self::ActiveVoteAccountClose => {
67                "Cannot close vote account unless it stopped voting at least one full epoch ago"
68            }
69            Self::CommissionUpdateTooLate => "Cannot update commission at this point in the epoch",
70            Self::AssertionFailed => "Assertion failed",
71        })
72    }
73}