1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
// Copyright (c) 2021-2024 Espresso Systems (espressosys.com)
// This file is part of the HotShot repository.

// You should have received a copy of the MIT License
// along with the HotShot repository. If not, see <https://mit-license.org/>.

use std::fmt::Display;

use async_broadcast::Sender;
use either::Either;
use hotshot_task::task::TaskEvent;
use hotshot_types::{
    data::{
        DaProposal, Leaf, PackedBundle, QuorumProposal, UpgradeProposal, VidDisperse,
        VidDisperseShare,
    },
    message::Proposal,
    request_response::ProposalRequestPayload,
    simple_certificate::{
        DaCertificate, QuorumCertificate, TimeoutCertificate, UpgradeCertificate,
        ViewSyncCommitCertificate2, ViewSyncFinalizeCertificate2, ViewSyncPreCommitCertificate2,
    },
    simple_vote::{
        DaVote, QuorumVote, TimeoutVote, UpgradeVote, ViewSyncCommitVote, ViewSyncFinalizeVote,
        ViewSyncPreCommitVote,
    },
    traits::{
        block_contents::BuilderFee, node_implementation::NodeType, signature_key::SignatureKey,
        BlockPayload,
    },
    utils::{BuilderCommitment, View},
    vid::VidCommitment,
    vote::HasViewNumber,
};
use vec1::Vec1;

use crate::view_sync::ViewSyncPhase;

impl<TYPES: NodeType> TaskEvent for HotShotEvent<TYPES> {
    fn shutdown_event() -> Self {
        HotShotEvent::Shutdown
    }
}

/// Wrapper type for the event to notify tasks that a proposal for a view is missing
/// and the channel to send the event back to
#[derive(Debug, Clone)]
pub struct ProposalMissing<TYPES: NodeType> {
    /// View of missing proposal
    pub view: TYPES::Time,
    /// Channel to send the response back to
    pub response_chan: Sender<Option<Proposal<TYPES, QuorumProposal<TYPES>>>>,
}

impl<TYPES: NodeType> PartialEq for ProposalMissing<TYPES> {
    fn eq(&self, other: &Self) -> bool {
        self.view == other.view
    }
}

impl<TYPES: NodeType> Eq for ProposalMissing<TYPES> {}

/// Marker that the task completed
#[derive(Eq, PartialEq, Debug, Clone)]
pub struct HotShotTaskCompleted;

/// All of the possible events that can be passed between Sequencing `HotShot` tasks
#[derive(Eq, PartialEq, Debug, Clone)]
#[allow(clippy::large_enum_variant)]
pub enum HotShotEvent<TYPES: NodeType> {
    /// Shutdown the task
    Shutdown,
    /// A quorum proposal has been received from the network; handled by the consensus task
    QuorumProposalRecv(Proposal<TYPES, QuorumProposal<TYPES>>, TYPES::SignatureKey),
    /// A quorum vote has been received from the network; handled by the consensus task
    QuorumVoteRecv(QuorumVote<TYPES>),
    /// A timeout vote received from the network; handled by consensus task
    TimeoutVoteRecv(TimeoutVote<TYPES>),
    /// Send a timeout vote to the network; emitted by consensus task replicas
    TimeoutVoteSend(TimeoutVote<TYPES>),
    /// A DA proposal has been received from the network; handled by the DA task
    DaProposalRecv(Proposal<TYPES, DaProposal<TYPES>>, TYPES::SignatureKey),
    /// A DA proposal has been validated; handled by the DA task and VID task
    DaProposalValidated(Proposal<TYPES, DaProposal<TYPES>>, TYPES::SignatureKey),
    /// A DA vote has been received by the network; handled by the DA task
    DaVoteRecv(DaVote<TYPES>),
    /// A Data Availability Certificate (DAC) has been received by the network; handled by the consensus task
    DaCertificateRecv(DaCertificate<TYPES>),
    /// A DAC is validated.
    DaCertificateValidated(DaCertificate<TYPES>),
    /// Send a quorum proposal to the network; emitted by the leader in the consensus task
    QuorumProposalSend(Proposal<TYPES, QuorumProposal<TYPES>>, TYPES::SignatureKey),
    /// Send a quorum vote to the next leader; emitted by a replica in the consensus task after seeing a valid quorum proposal
    QuorumVoteSend(QuorumVote<TYPES>),
    /// All dependencies for the quorum vote are validated.
    QuorumVoteDependenciesValidated(TYPES::Time),
    /// A quorum proposal with the given parent leaf is validated.
    /// The full validation checks include:
    /// 1. The proposal is not for an old view
    /// 2. The proposal has been correctly signed by the leader of the current view
    /// 3. The justify QC is valid
    /// 4. The proposal passes either liveness or safety check.
    QuorumProposalValidated(QuorumProposal<TYPES>, Leaf<TYPES>),
    /// A quorum proposal is missing for a view that we need.
    QuorumProposalRequestSend(
        ProposalRequestPayload<TYPES>,
        <TYPES::SignatureKey as SignatureKey>::PureAssembledSignatureType,
    ),
    /// A quorum proposal was requested by a node for a view.
    QuorumProposalRequestRecv(
        ProposalRequestPayload<TYPES>,
        <TYPES::SignatureKey as SignatureKey>::PureAssembledSignatureType,
    ),
    /// A quorum proposal was missing for a view. As the leader, we send a reply to the recipient with their key.
    QuorumProposalResponseSend(TYPES::SignatureKey, Proposal<TYPES, QuorumProposal<TYPES>>),
    /// A quorum proposal was requested by a node for a view.
    QuorumProposalResponseRecv(Proposal<TYPES, QuorumProposal<TYPES>>),
    /// Send a DA proposal to the DA committee; emitted by the DA leader (which is the same node as the leader of view v + 1) in the DA task
    DaProposalSend(Proposal<TYPES, DaProposal<TYPES>>, TYPES::SignatureKey),
    /// Send a DA vote to the DA leader; emitted by DA committee members in the DA task after seeing a valid DA proposal
    DaVoteSend(DaVote<TYPES>),
    /// The next leader has collected enough votes to form a QC; emitted by the next leader in the consensus task; an internal event only
    QcFormed(Either<QuorumCertificate<TYPES>, TimeoutCertificate<TYPES>>),
    /// The DA leader has collected enough votes to form a DAC; emitted by the DA leader in the DA task; sent to the entire network via the networking task
    DacSend(DaCertificate<TYPES>, TYPES::SignatureKey),
    /// The current view has changed; emitted by the replica in the consensus task or replica in the view sync task; received by almost all other tasks
    ViewChange(TYPES::Time),
    /// Timeout for the view sync protocol; emitted by a replica in the view sync task
    ViewSyncTimeout(TYPES::Time, u64, ViewSyncPhase),

    /// Receive a `ViewSyncPreCommitVote` from the network; received by a relay in the view sync task
    ViewSyncPreCommitVoteRecv(ViewSyncPreCommitVote<TYPES>),
    /// Receive a `ViewSyncCommitVote` from the network; received by a relay in the view sync task
    ViewSyncCommitVoteRecv(ViewSyncCommitVote<TYPES>),
    /// Receive a `ViewSyncFinalizeVote` from the network; received by a relay in the view sync task
    ViewSyncFinalizeVoteRecv(ViewSyncFinalizeVote<TYPES>),

    /// Send a `ViewSyncPreCommitVote` from the network; emitted by a replica in the view sync task
    ViewSyncPreCommitVoteSend(ViewSyncPreCommitVote<TYPES>),
    /// Send a `ViewSyncCommitVote` from the network; emitted by a replica in the view sync task
    ViewSyncCommitVoteSend(ViewSyncCommitVote<TYPES>),
    /// Send a `ViewSyncFinalizeVote` from the network; emitted by a replica in the view sync task
    ViewSyncFinalizeVoteSend(ViewSyncFinalizeVote<TYPES>),

    /// Receive a `ViewSyncPreCommitCertificate2` from the network; received by a replica in the view sync task
    ViewSyncPreCommitCertificate2Recv(ViewSyncPreCommitCertificate2<TYPES>),
    /// Receive a `ViewSyncCommitCertificate2` from the network; received by a replica in the view sync task
    ViewSyncCommitCertificate2Recv(ViewSyncCommitCertificate2<TYPES>),
    /// Receive a `ViewSyncFinalizeCertificate2` from the network; received by a replica in the view sync task
    ViewSyncFinalizeCertificate2Recv(ViewSyncFinalizeCertificate2<TYPES>),

    /// Send a `ViewSyncPreCommitCertificate2` from the network; emitted by a relay in the view sync task
    ViewSyncPreCommitCertificate2Send(ViewSyncPreCommitCertificate2<TYPES>, TYPES::SignatureKey),
    /// Send a `ViewSyncCommitCertificate2` from the network; emitted by a relay in the view sync task
    ViewSyncCommitCertificate2Send(ViewSyncCommitCertificate2<TYPES>, TYPES::SignatureKey),
    /// Send a `ViewSyncFinalizeCertificate2` from the network; emitted by a relay in the view sync task
    ViewSyncFinalizeCertificate2Send(ViewSyncFinalizeCertificate2<TYPES>, TYPES::SignatureKey),

    /// Trigger the start of the view sync protocol; emitted by view sync task; internal trigger only
    ViewSyncTrigger(TYPES::Time),
    /// A consensus view has timed out; emitted by a replica in the consensus task; received by the view sync task; internal event only
    Timeout(TYPES::Time),
    /// Receive transactions from the network
    TransactionsRecv(Vec<TYPES::Transaction>),
    /// Send transactions to the network
    TransactionSend(TYPES::Transaction, TYPES::SignatureKey),
    /// Event to send block payload commitment and metadata from DA leader to the quorum; internal event only
    SendPayloadCommitmentAndMetadata(
        VidCommitment,
        BuilderCommitment,
        <TYPES::BlockPayload as BlockPayload<TYPES>>::Metadata,
        TYPES::Time,
        Vec1<BuilderFee<TYPES>>,
        Option<TYPES::AuctionResult>,
    ),
    /// Event when the transactions task has sequenced transactions. Contains the encoded transactions, the metadata, and the view number
    BlockRecv(PackedBundle<TYPES>),
    /// Event when the transactions task has a block formed
    BlockReady(VidDisperse<TYPES>, TYPES::Time),
    /// Event when consensus decided on a leaf
    LeafDecided(Vec<Leaf<TYPES>>),
    /// Send VID shares to VID storage nodes; emitted by the DA leader
    ///
    /// Like [`HotShotEvent::DaProposalSend`].
    VidDisperseSend(Proposal<TYPES, VidDisperse<TYPES>>, TYPES::SignatureKey),
    /// Vid disperse share has been received from the network; handled by the consensus task
    ///
    /// Like [`HotShotEvent::DaProposalRecv`].
    VidShareRecv(Proposal<TYPES, VidDisperseShare<TYPES>>),
    /// VID share data is validated.
    VidShareValidated(Proposal<TYPES, VidDisperseShare<TYPES>>),
    /// Upgrade proposal has been received from the network
    UpgradeProposalRecv(Proposal<TYPES, UpgradeProposal<TYPES>>, TYPES::SignatureKey),
    /// Upgrade proposal has been sent to the network
    UpgradeProposalSend(Proposal<TYPES, UpgradeProposal<TYPES>>, TYPES::SignatureKey),
    /// Upgrade vote has been received from the network
    UpgradeVoteRecv(UpgradeVote<TYPES>),
    /// Upgrade vote has been sent to the network
    UpgradeVoteSend(UpgradeVote<TYPES>),
    /// Upgrade certificate has been sent to the network
    UpgradeCertificateFormed(UpgradeCertificate<TYPES>),

    /* Consensus State Update Events */
    /// A undecided view has been created and added to the validated state storage.
    ValidatedStateUpdated(TYPES::Time, View<TYPES>),

    /// A new locked view has been created (2-chain)
    LockedViewUpdated(TYPES::Time),

    /// A new anchor view has been successfully reached by this node (3-chain).
    LastDecidedViewUpdated(TYPES::Time),

    /// A new high_qc has been reached by this node.
    UpdateHighQc(QuorumCertificate<TYPES>),

    /// A new high_qc has been updated in `Consensus`.
    HighQcUpdated(QuorumCertificate<TYPES>),

    /// A quorum proposal has been preliminarily validated.
    /// The preliminary checks include:
    /// 1. The proposal is not for an old view
    /// 2. The proposal has been correctly signed by the leader of the current view
    /// 3. The justify QC is valid
    QuorumProposalPreliminarilyValidated(Proposal<TYPES, QuorumProposal<TYPES>>),
}

impl<TYPES: NodeType> HotShotEvent<TYPES> {
    #[allow(clippy::too_many_lines)]
    /// Return the view number for a hotshot event if present
    pub fn view_number(&self) -> Option<TYPES::Time> {
        match self {
            HotShotEvent::QuorumVoteRecv(v) => Some(v.view_number()),
            HotShotEvent::TimeoutVoteRecv(v) | HotShotEvent::TimeoutVoteSend(v) => {
                Some(v.view_number())
            }
            HotShotEvent::QuorumProposalRecv(proposal, _)
            | HotShotEvent::QuorumProposalSend(proposal, _) => Some(proposal.data.view_number()),
            HotShotEvent::QuorumVoteSend(vote) => Some(vote.view_number()),
            HotShotEvent::QuorumProposalValidated(proposal, _) => Some(proposal.view_number()),
            HotShotEvent::DaProposalRecv(proposal, _)
            | HotShotEvent::DaProposalValidated(proposal, _)
            | HotShotEvent::DaProposalSend(proposal, _) => Some(proposal.data.view_number()),
            HotShotEvent::DaVoteRecv(vote) | HotShotEvent::DaVoteSend(vote) => {
                Some(vote.view_number())
            }
            HotShotEvent::QcFormed(cert) => match cert {
                either::Left(qc) => Some(qc.view_number()),
                either::Right(tc) => Some(tc.view_number()),
            },
            HotShotEvent::ViewSyncCommitVoteSend(vote)
            | HotShotEvent::ViewSyncCommitVoteRecv(vote) => Some(vote.view_number()),
            HotShotEvent::ViewSyncPreCommitVoteRecv(vote)
            | HotShotEvent::ViewSyncPreCommitVoteSend(vote) => Some(vote.view_number()),
            HotShotEvent::ViewSyncFinalizeVoteRecv(vote)
            | HotShotEvent::ViewSyncFinalizeVoteSend(vote) => Some(vote.view_number()),
            HotShotEvent::ViewSyncPreCommitCertificate2Recv(cert)
            | HotShotEvent::ViewSyncPreCommitCertificate2Send(cert, _) => Some(cert.view_number()),
            HotShotEvent::ViewSyncCommitCertificate2Recv(cert)
            | HotShotEvent::ViewSyncCommitCertificate2Send(cert, _) => Some(cert.view_number()),
            HotShotEvent::ViewSyncFinalizeCertificate2Recv(cert)
            | HotShotEvent::ViewSyncFinalizeCertificate2Send(cert, _) => Some(cert.view_number()),
            HotShotEvent::SendPayloadCommitmentAndMetadata(_, _, _, view_number, _, _) => {
                Some(*view_number)
            }
            HotShotEvent::BlockRecv(packed_bundle) => Some(packed_bundle.view_number),
            HotShotEvent::Shutdown
            | HotShotEvent::TransactionSend(_, _)
            | HotShotEvent::LeafDecided(_)
            | HotShotEvent::TransactionsRecv(_) => None,
            HotShotEvent::VidDisperseSend(proposal, _) => Some(proposal.data.view_number()),
            HotShotEvent::VidShareRecv(proposal) | HotShotEvent::VidShareValidated(proposal) => {
                Some(proposal.data.view_number())
            }
            HotShotEvent::UpgradeProposalRecv(proposal, _)
            | HotShotEvent::UpgradeProposalSend(proposal, _) => Some(proposal.data.view_number()),
            HotShotEvent::UpgradeVoteRecv(vote) | HotShotEvent::UpgradeVoteSend(vote) => {
                Some(vote.view_number())
            }
            HotShotEvent::QuorumProposalRequestSend(req, _)
            | HotShotEvent::QuorumProposalRequestRecv(req, _) => Some(req.view_number),
            HotShotEvent::QuorumProposalResponseSend(_, proposal)
            | HotShotEvent::QuorumProposalResponseRecv(proposal)
            | HotShotEvent::QuorumProposalPreliminarilyValidated(proposal) => {
                Some(proposal.data.view_number())
            }
            HotShotEvent::QuorumVoteDependenciesValidated(view_number)
            | HotShotEvent::ViewChange(view_number)
            | HotShotEvent::ViewSyncTimeout(view_number, _, _)
            | HotShotEvent::ViewSyncTrigger(view_number)
            | HotShotEvent::Timeout(view_number)
            | HotShotEvent::BlockReady(_, view_number)
            | HotShotEvent::LockedViewUpdated(view_number)
            | HotShotEvent::LastDecidedViewUpdated(view_number)
            | HotShotEvent::ValidatedStateUpdated(view_number, _) => Some(*view_number),
            HotShotEvent::DaCertificateRecv(cert) | HotShotEvent::DacSend(cert, _) => {
                Some(cert.view_number())
            }
            HotShotEvent::UpdateHighQc(cert) | HotShotEvent::HighQcUpdated(cert) => {
                Some(cert.view_number())
            }
            HotShotEvent::DaCertificateValidated(cert) => Some(cert.view_number),
            HotShotEvent::UpgradeCertificateFormed(cert) => Some(cert.view_number()),
        }
    }
}

impl<TYPES: NodeType> Display for HotShotEvent<TYPES> {
    #[allow(clippy::too_many_lines)]
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            HotShotEvent::Shutdown => write!(f, "Shutdown"),
            HotShotEvent::QuorumProposalRecv(proposal, _) => write!(
                f,
                "QuorumProposalRecv(view_number={:?})",
                proposal.data.view_number()
            ),
            HotShotEvent::QuorumVoteRecv(v) => {
                write!(f, "QuorumVoteRecv(view_number={:?})", v.view_number())
            }
            HotShotEvent::TimeoutVoteRecv(v) => {
                write!(f, "TimeoutVoteRecv(view_number={:?})", v.view_number())
            }
            HotShotEvent::TimeoutVoteSend(v) => {
                write!(f, "TimeoutVoteSend(view_number={:?})", v.view_number())
            }
            HotShotEvent::DaProposalRecv(proposal, _) => write!(
                f,
                "DaProposalRecv(view_number={:?})",
                proposal.data.view_number()
            ),
            HotShotEvent::DaProposalValidated(proposal, _) => write!(
                f,
                "DaProposalValidated(view_number={:?})",
                proposal.data.view_number()
            ),
            HotShotEvent::DaVoteRecv(vote) => {
                write!(f, "DaVoteRecv(view_number={:?})", vote.view_number())
            }
            HotShotEvent::DaCertificateRecv(cert) => {
                write!(f, "DaCertificateRecv(view_number={:?})", cert.view_number())
            }
            HotShotEvent::DaCertificateValidated(cert) => write!(
                f,
                "DaCertificateValidated(view_number={:?})",
                cert.view_number()
            ),
            HotShotEvent::QuorumProposalSend(proposal, _) => write!(
                f,
                "QuorumProposalSend(view_number={:?})",
                proposal.data.view_number()
            ),
            HotShotEvent::QuorumVoteSend(vote) => {
                write!(f, "QuorumVoteSend(view_number={:?})", vote.view_number())
            }
            HotShotEvent::QuorumVoteDependenciesValidated(view_number) => {
                write!(
                    f,
                    "QuorumVoteDependenciesValidated(view_number={view_number:?})"
                )
            }
            HotShotEvent::QuorumProposalValidated(proposal, _) => write!(
                f,
                "QuorumProposalValidated(view_number={:?})",
                proposal.view_number()
            ),
            HotShotEvent::DaProposalSend(proposal, _) => write!(
                f,
                "DaProposalSend(view_number={:?})",
                proposal.data.view_number()
            ),
            HotShotEvent::DaVoteSend(vote) => {
                write!(f, "DaVoteSend(view_number={:?})", vote.view_number())
            }
            HotShotEvent::QcFormed(cert) => match cert {
                either::Left(qc) => write!(f, "QcFormed(view_number={:?})", qc.view_number()),
                either::Right(tc) => write!(f, "QcFormed(view_number={:?})", tc.view_number()),
            },
            HotShotEvent::DacSend(cert, _) => {
                write!(f, "DacSend(view_number={:?})", cert.view_number())
            }
            HotShotEvent::ViewChange(view_number) => {
                write!(f, "ViewChange(view_number={view_number:?})")
            }
            HotShotEvent::ViewSyncTimeout(view_number, _, _) => {
                write!(f, "ViewSyncTimeout(view_number={view_number:?})")
            }
            HotShotEvent::ViewSyncPreCommitVoteRecv(vote) => write!(
                f,
                "ViewSyncPreCommitVoteRecv(view_number={:?})",
                vote.view_number()
            ),
            HotShotEvent::ViewSyncCommitVoteRecv(vote) => write!(
                f,
                "ViewSyncCommitVoteRecv(view_number={:?})",
                vote.view_number()
            ),
            HotShotEvent::ViewSyncFinalizeVoteRecv(vote) => write!(
                f,
                "ViewSyncFinalizeVoteRecv(view_number={:?})",
                vote.view_number()
            ),
            HotShotEvent::ViewSyncPreCommitVoteSend(vote) => write!(
                f,
                "ViewSyncPreCommitVoteSend(view_number={:?})",
                vote.view_number()
            ),
            HotShotEvent::ViewSyncCommitVoteSend(vote) => write!(
                f,
                "ViewSyncCommitVoteSend(view_number={:?})",
                vote.view_number()
            ),
            HotShotEvent::ViewSyncFinalizeVoteSend(vote) => write!(
                f,
                "ViewSyncFinalizeVoteSend(view_number={:?})",
                vote.view_number()
            ),
            HotShotEvent::ViewSyncPreCommitCertificate2Recv(cert) => {
                write!(
                    f,
                    "ViewSyncPreCommitCertificate2Recv(view_number={:?})",
                    cert.view_number()
                )
            }
            HotShotEvent::ViewSyncCommitCertificate2Recv(cert) => {
                write!(
                    f,
                    "ViewSyncCommitCertificate2Recv(view_number={:?})",
                    cert.view_number()
                )
            }
            HotShotEvent::ViewSyncFinalizeCertificate2Recv(cert) => {
                write!(
                    f,
                    "ViewSyncFinalizeCertificate2Recv(view_number={:?})",
                    cert.view_number()
                )
            }
            HotShotEvent::ViewSyncPreCommitCertificate2Send(cert, _) => {
                write!(
                    f,
                    "ViewSyncPreCommitCertificate2Send(view_number={:?})",
                    cert.view_number()
                )
            }
            HotShotEvent::ViewSyncCommitCertificate2Send(cert, _) => {
                write!(
                    f,
                    "ViewSyncCommitCertificate2Send(view_number={:?})",
                    cert.view_number()
                )
            }
            HotShotEvent::ViewSyncFinalizeCertificate2Send(cert, _) => {
                write!(
                    f,
                    "ViewSyncFinalizeCertificate2Send(view_number={:?})",
                    cert.view_number()
                )
            }
            HotShotEvent::ViewSyncTrigger(view_number) => {
                write!(f, "ViewSyncTrigger(view_number={view_number:?})")
            }
            HotShotEvent::Timeout(view_number) => write!(f, "Timeout(view_number={view_number:?})"),
            HotShotEvent::TransactionsRecv(_) => write!(f, "TransactionsRecv"),
            HotShotEvent::TransactionSend(_, _) => write!(f, "TransactionSend"),
            HotShotEvent::SendPayloadCommitmentAndMetadata(_, _, _, view_number, _, _) => {
                write!(
                    f,
                    "SendPayloadCommitmentAndMetadata(view_number={view_number:?})"
                )
            }
            HotShotEvent::BlockRecv(packed_bundle) => {
                write!(f, "BlockRecv(view_number={:?})", packed_bundle.view_number)
            }
            HotShotEvent::BlockReady(_, view_number) => {
                write!(f, "BlockReady(view_number={view_number:?})")
            }
            HotShotEvent::LeafDecided(leaves) => {
                let view_numbers: Vec<<TYPES as NodeType>::Time> =
                    leaves.iter().map(Leaf::view_number).collect();
                write!(f, "LeafDecided({view_numbers:?})")
            }
            HotShotEvent::VidDisperseSend(proposal, _) => write!(
                f,
                "VidDisperseSend(view_number={:?})",
                proposal.data.view_number()
            ),
            HotShotEvent::VidShareRecv(proposal) => write!(
                f,
                "VIDShareRecv(view_number={:?})",
                proposal.data.view_number()
            ),
            HotShotEvent::VidShareValidated(proposal) => write!(
                f,
                "VIDShareValidated(view_number={:?})",
                proposal.data.view_number()
            ),
            HotShotEvent::UpgradeProposalRecv(proposal, _) => write!(
                f,
                "UpgradeProposalRecv(view_number={:?})",
                proposal.data.view_number()
            ),
            HotShotEvent::UpgradeProposalSend(proposal, _) => write!(
                f,
                "UpgradeProposalSend(view_number={:?})",
                proposal.data.view_number()
            ),
            HotShotEvent::UpgradeVoteRecv(vote) => {
                write!(f, "UpgradeVoteRecv(view_number={:?})", vote.view_number())
            }
            HotShotEvent::UpgradeVoteSend(vote) => {
                write!(f, "UpgradeVoteSend(view_number={:?})", vote.view_number())
            }
            HotShotEvent::UpgradeCertificateFormed(cert) => write!(
                f,
                "UpgradeCertificateFormed(view_number={:?})",
                cert.view_number()
            ),
            HotShotEvent::QuorumProposalRequestSend(view_number, _) => {
                write!(f, "QuorumProposalRequestSend(view_number={view_number:?})")
            }
            HotShotEvent::QuorumProposalRequestRecv(view_number, _) => {
                write!(f, "QuorumProposalRequestRecv(view_number={view_number:?})")
            }
            HotShotEvent::QuorumProposalResponseSend(_, proposal) => {
                write!(
                    f,
                    "QuorumProposalResponseSend(view_number={:?})",
                    proposal.data.view_number
                )
            }
            HotShotEvent::QuorumProposalResponseRecv(proposal) => {
                write!(
                    f,
                    "QuorumProposalResponseRecv(view_number={:?})",
                    proposal.data.view_number
                )
            }
            HotShotEvent::ValidatedStateUpdated(view_number, _) => {
                write!(f, "ValidatedStateUpdated(view_number={view_number:?})")
            }
            HotShotEvent::LockedViewUpdated(view_number) => {
                write!(f, "LockedViewUpdated(view_number={view_number:?})")
            }
            HotShotEvent::LastDecidedViewUpdated(view_number) => {
                write!(f, "LastDecidedViewUpdated(view_number={view_number:?})")
            }
            HotShotEvent::UpdateHighQc(cert) => {
                write!(f, "UpdateHighQc(view_number={:?})", cert.view_number())
            }
            HotShotEvent::HighQcUpdated(cert) => {
                write!(f, "HighQcUpdated(view_number={:?})", cert.view_number())
            }
            HotShotEvent::QuorumProposalPreliminarilyValidated(proposal) => {
                write!(
                    f,
                    "QuorumProposalPreliminarilyValidated(view_number={:?}",
                    proposal.data.view_number()
                )
            }
        }
    }
}