hotshot_types/error.rs
1// Copyright (c) 2021-2024 Espresso Systems (espressosys.com)
2// This file is part of the HotShot repository.
3
4// You should have received a copy of the MIT License
5// along with the HotShot repository. If not, see <https://mit-license.org/>.
6
7//! Error type for `HotShot`
8//!
9//! This module provides [`HotShotError`], which is an enum representing possible faults that can
10//! occur while interacting with this crate.
11
12use committable::Commitment;
13use serde::{Deserialize, Serialize};
14use thiserror::Error;
15
16use crate::{
17 data::{Leaf2, ViewNumber},
18 traits::node_implementation::NodeType,
19};
20
21/// Error type for `HotShot`
22#[derive(Debug, Error)]
23#[non_exhaustive]
24pub enum HotShotError<TYPES: NodeType> {
25 /// The consensus state machine is in an invalid state
26 #[error("Invalid state: {0}")]
27 InvalidState(String),
28
29 /// Leaf was not present in storage
30 #[error("Missing leaf with commitment: {0}")]
31 MissingLeaf(Commitment<Leaf2<TYPES>>),
32
33 /// Failed to serialize data
34 #[error("Failed to serialize: {0}")]
35 FailedToSerialize(String),
36
37 /// Failed to deserialize data
38 #[error("Failed to deserialize: {0}")]
39 FailedToDeserialize(String),
40
41 /// The view timed out
42 #[error("View {view_number} timed out: {state:?}")]
43 ViewTimedOut {
44 /// The view number that timed out
45 view_number: ViewNumber,
46 /// The state that the round was in when it timed out
47 state: RoundTimedoutState,
48 },
49}
50
51/// Contains information about what the state of the hotshot-consensus was when a round timed out
52#[derive(Debug, Clone, Serialize, Deserialize)]
53#[non_exhaustive]
54pub enum RoundTimedoutState {
55 /// Leader is in a Prepare phase and is waiting for a HighQc
56 LeaderWaitingForHighQc,
57 /// Leader is in a Prepare phase and timed out before the round min time is reached
58 LeaderMinRoundTimeNotReached,
59 /// Leader is waiting for prepare votes
60 LeaderWaitingForPrepareVotes,
61 /// Leader is waiting for precommit votes
62 LeaderWaitingForPreCommitVotes,
63 /// Leader is waiting for commit votes
64 LeaderWaitingForCommitVotes,
65
66 /// Replica is waiting for a prepare message
67 ReplicaWaitingForPrepare,
68 /// Replica is waiting for a pre-commit message
69 ReplicaWaitingForPreCommit,
70 /// Replica is waiting for a commit message
71 ReplicaWaitingForCommit,
72 /// Replica is waiting for a decide message
73 ReplicaWaitingForDecide,
74
75 /// HotShot-testing tried to collect round events, but it timed out
76 TestCollectRoundEventsTimedOut,
77}