Skip to main content

hashgraph_like_consensus/
error.rs

1//! Error types for the consensus library.
2//!
3//! All fallible operations return [`ConsensusError`]. Variants are grouped into
4//! configuration validation, vote/proposal validation, session state, and
5//! consensus result categories.
6
7use crate::signing::ConsensusSchemeError;
8
9/// Enumerates everything that can go wrong during consensus operations.
10#[derive(Debug, thiserror::Error)]
11pub enum ConsensusError {
12    // Configuration Validation Errors
13    #[error("consensus_threshold must be between 0.0 and 1.0")]
14    InvalidConsensusThreshold,
15    #[error("timeout must be greater than 0")]
16    InvalidTimeout,
17    #[error("expected_voters_count must be greater than 0")]
18    InvalidExpectedVotersCount,
19    #[error("max_rounds must be greater than 0")]
20    InvalidMaxRounds,
21
22    // Vote and Proposal Validation Errors
23    #[error("Invalid vote signature")]
24    InvalidVoteSignature,
25    #[error("Empty signature")]
26    EmptySignature,
27    #[error("Duplicate vote")]
28    DuplicateVote,
29    #[error("User already voted")]
30    UserAlreadyVoted,
31    #[error("Vote expired")]
32    VoteExpired,
33    #[error("Empty vote owner")]
34    EmptyVoteOwner,
35    #[error("Invalid vote hash")]
36    InvalidVoteHash,
37    #[error("Empty vote hash")]
38    EmptyVoteHash,
39    #[error("Proposal expired")]
40    ProposalExpired,
41    #[error("Vote proposal_id mismatch: vote belongs to different proposal")]
42    VoteProposalIdMismatch,
43    #[error("Received hash mismatch")]
44    ReceivedHashMismatch,
45    #[error("Parent hash mismatch")]
46    ParentHashMismatch,
47    #[error("Invalid vote timestamp")]
48    InvalidVoteTimestamp,
49    #[error("Vote timestamp is older than creation time")]
50    TimestampOlderThanCreationTime,
51
52    // Session/State Errors
53    #[error("Session not active")]
54    SessionNotActive,
55    #[error("Session not found")]
56    SessionNotFound,
57    #[error("Proposal already exist in consensus service")]
58    ProposalAlreadyExist,
59    #[error("Scope not found")]
60    ScopeNotFound,
61
62    // Consensus Result Errors
63    #[error("Insufficient votes at timeout")]
64    InsufficientVotesAtTimeout,
65    #[error("Consensus exceeded configured max rounds")]
66    MaxRoundsExceeded,
67    #[error("Consensus not reached")]
68    ConsensusNotReached,
69    #[error("Consensus failed")]
70    ConsensusFailed,
71
72    #[error("Signature scheme failure: {0}")]
73    SignatureScheme(#[from] ConsensusSchemeError),
74    #[error("Failed to get current time")]
75    FailedToGetCurrentTime(#[from] std::time::SystemTimeError),
76}