hotmint_consensus/
error.rs1use hotmint_types::{BlockHash, EpochNumber, EquivocationProof, ValidatorId, ViewNumber};
2use std::fmt;
3
4#[derive(Debug)]
5pub enum ConsensusError {
6 InvalidProposal(String),
7 InvalidVote(String),
8 InvalidCertificate(String),
9 SafetyViolation(String),
10 NotLeader {
11 view: ViewNumber,
12 leader: ValidatorId,
13 },
14 StaleMessage {
15 msg_view: ViewNumber,
16 current_view: ViewNumber,
17 },
18 MissingBlock(BlockHash),
19 NetworkError(String),
20 EpochMismatch {
21 expected: EpochNumber,
22 got: EpochNumber,
23 },
24 Equivocation(EquivocationProof),
25}
26
27impl fmt::Display for ConsensusError {
28 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29 match self {
30 Self::InvalidProposal(s) => write!(f, "invalid proposal: {s}"),
31 Self::InvalidVote(s) => write!(f, "invalid vote: {s}"),
32 Self::InvalidCertificate(s) => write!(f, "invalid certificate: {s}"),
33 Self::SafetyViolation(s) => write!(f, "safety violation: {s}"),
34 Self::NotLeader { view, leader } => {
35 write!(f, "not leader for {view}, leader is {leader}")
36 }
37 Self::StaleMessage {
38 msg_view,
39 current_view,
40 } => {
41 write!(f, "stale message from {msg_view}, current {current_view}")
42 }
43 Self::MissingBlock(h) => write!(f, "missing block {h}"),
44 Self::NetworkError(s) => write!(f, "network error: {s}"),
45 Self::EpochMismatch { expected, got } => {
46 write!(f, "epoch mismatch: expected {expected}, got {got}")
47 }
48 Self::Equivocation(proof) => {
49 write!(
50 f,
51 "equivocation by {} in view {}",
52 proof.validator, proof.view
53 )
54 }
55 }
56 }
57}