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::{data::Leaf2, traits::node_implementation::NodeType};
17
18/// Error type for `HotShot`
19#[derive(Debug, Error)]
20#[non_exhaustive]
21pub enum HotShotError<TYPES: NodeType> {
22    /// The consensus state machine is in an invalid state
23    #[error("Invalid state: {0}")]
24    InvalidState(String),
25
26    /// Leaf was not present in storage
27    #[error("Missing leaf with commitment: {0}")]
28    MissingLeaf(Commitment<Leaf2<TYPES>>),
29
30    /// Failed to serialize data
31    #[error("Failed to serialize: {0}")]
32    FailedToSerialize(String),
33
34    /// Failed to deserialize data
35    #[error("Failed to deserialize: {0}")]
36    FailedToDeserialize(String),
37
38    /// The view timed out
39    #[error("View {view_number} timed out: {state:?}")]
40    ViewTimedOut {
41        /// The view number that timed out
42        view_number: TYPES::View,
43        /// The state that the round was in when it timed out
44        state: RoundTimedoutState,
45    },
46}
47
48/// Contains information about what the state of the hotshot-consensus was when a round timed out
49#[derive(Debug, Clone, Serialize, Deserialize)]
50#[non_exhaustive]
51pub enum RoundTimedoutState {
52    /// Leader is in a Prepare phase and is waiting for a HighQc
53    LeaderWaitingForHighQc,
54    /// Leader is in a Prepare phase and timed out before the round min time is reached
55    LeaderMinRoundTimeNotReached,
56    /// Leader is waiting for prepare votes
57    LeaderWaitingForPrepareVotes,
58    /// Leader is waiting for precommit votes
59    LeaderWaitingForPreCommitVotes,
60    /// Leader is waiting for commit votes
61    LeaderWaitingForCommitVotes,
62
63    /// Replica is waiting for a prepare message
64    ReplicaWaitingForPrepare,
65    /// Replica is waiting for a pre-commit message
66    ReplicaWaitingForPreCommit,
67    /// Replica is waiting for a commit message
68    ReplicaWaitingForCommit,
69    /// Replica is waiting for a decide message
70    ReplicaWaitingForDecide,
71
72    /// HotShot-testing tried to collect round events, but it timed out
73    TestCollectRoundEventsTimedOut,
74}