Skip to main content

hotshot_types/new_protocol/
event.rs

1use std::sync::Arc;
2
3use crate::{
4    data::ViewNumber,
5    event::LeafInfo,
6    message::Proposal as SignedProposal,
7    new_protocol::Proposal,
8    simple_certificate::{SimpleCertificate, SuccessThreshold},
9    simple_vote::{QuorumData2, Vote2Data},
10    traits::node_implementation::NodeType,
11};
12
13/// What the coordinator reports to the node.
14#[derive(Clone, Debug)]
15pub enum CoordinatorEvent<TYPES: NodeType> {
16    NewDecide {
17        leaf_infos: Vec<LeafInfo<TYPES>>,
18        /// Certificate1 that certifies the most recent (first) leaf in the chain.
19        /// Each older leaf's cert1 is the next leaf's `justify_qc`.
20        cert1: SimpleCertificate<TYPES, QuorumData2<TYPES>, SuccessThreshold>,
21        /// Cert2 which finalizes the most recent leaf in the chain
22        cert2: Option<SimpleCertificate<TYPES, Vote2Data<TYPES>, SuccessThreshold>>,
23    },
24    QuorumProposal {
25        proposal: Box<SignedProposal<TYPES, Proposal<TYPES>>>,
26        sender: TYPES::SignatureKey,
27    },
28    ExternalMessageReceived {
29        sender: TYPES::SignatureKey,
30        data: Vec<u8>,
31    },
32    /// Emitted when a node has reconstructed a block payload from VID shares.
33    /// A payload obtained before its view decides rides along in `NewDecide`;
34    /// this lets downstream consumers (e.g. the query service) fill in a
35    /// payload that was still missing when the view decided.
36    BlockPayloadReconstructed {
37        view: ViewNumber,
38        header: TYPES::BlockHeader,
39        payload: Arc<TYPES::BlockPayload>,
40    },
41}
42
43impl<TYPES: NodeType> std::fmt::Display for CoordinatorEvent<TYPES> {
44    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
45        match self {
46            Self::NewDecide { leaf_infos, .. } => {
47                let view = leaf_infos
48                    .first()
49                    .map(|info| *info.leaf.view_number())
50                    .unwrap_or_default();
51                write!(f, "NewDecide: view={view}")
52            },
53            Self::QuorumProposal { proposal, .. } => {
54                write!(
55                    f,
56                    "QuorumProposal: view={} epoch={}",
57                    proposal.data.view_number, proposal.data.epoch
58                )
59            },
60            Self::ExternalMessageReceived { .. } => {
61                write!(f, "ExternalMessageReceived")
62            },
63            Self::BlockPayloadReconstructed { view, .. } => {
64                write!(f, "BlockPayloadReconstructed: view={view}")
65            },
66        }
67    }
68}