Skip to main content

hotshot_types/new_protocol/
event.rs

1use crate::{
2    data::ViewNumber,
3    event::{Event, LeafInfo},
4    message::Proposal as SignedProposal,
5    new_protocol::Proposal,
6    simple_certificate::{SimpleCertificate, SuccessThreshold},
7    simple_vote::{QuorumData2, Vote2Data},
8    traits::node_implementation::NodeType,
9};
10
11/// High-level event emitted by the coordinator adapter. Covers both legacy HotShot
12/// events and new-protocol coordinator events.
13#[derive(Clone, Debug)]
14pub enum CoordinatorEvent<TYPES: NodeType> {
15    LegacyEvent(Event<TYPES>),
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: 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    /// Lets downstream consumers (e.g. query service) fill in a payload that
34    /// was missing when the corresponding view was decided.
35    BlockPayloadReconstructed {
36        view: ViewNumber,
37        header: TYPES::BlockHeader,
38        payload: TYPES::BlockPayload,
39    },
40}
41
42impl<TYPES: NodeType> std::fmt::Display for CoordinatorEvent<TYPES> {
43    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
44        match self {
45            Self::LegacyEvent(event) => {
46                write!(f, "Legacy: {} view={}", event.event, event.view_number)
47            },
48            Self::NewDecide { leaf_infos, .. } => {
49                let view = leaf_infos
50                    .first()
51                    .map(|info| *info.leaf.view_number())
52                    .unwrap_or_default();
53                write!(f, "NewDecide: view={view}")
54            },
55            Self::QuorumProposal { proposal, .. } => {
56                write!(
57                    f,
58                    "QuorumProposal: view={} epoch={}",
59                    proposal.data.view_number, proposal.data.epoch
60                )
61            },
62            Self::ExternalMessageReceived { .. } => {
63                write!(f, "ExternalMessageReceived")
64            },
65            Self::BlockPayloadReconstructed { view, .. } => {
66                write!(f, "BlockPayloadReconstructed: view={view}")
67            },
68        }
69    }
70}