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
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
// 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::{
        DaProposal2, Leaf2, PackedBundle, QuorumProposal2, UpgradeProposal, VidDisperse,
        VidDisperseShare2,
    },
    message::Proposal,
    request_response::ProposalRequestPayload,
    simple_certificate::{
        DaCertificate2, NextEpochQuorumCertificate2, QuorumCertificate, QuorumCertificate2,
        TimeoutCertificate, TimeoutCertificate2, UpgradeCertificate, ViewSyncCommitCertificate2,
        ViewSyncFinalizeCertificate2, ViewSyncPreCommitCertificate2,
    },
    simple_vote::{
        DaVote2, QuorumVote2, TimeoutVote2, UpgradeVote, ViewSyncCommitVote2,
        ViewSyncFinalizeVote2, ViewSyncPreCommitVote2,
    },
    traits::{
        block_contents::BuilderFee, network::DataRequest, node_implementation::NodeType,
        signature_key::SignatureKey, BlockPayload,
    },
    utils::BuilderCommitment,
    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::View,
    /// Channel to send the response back to
    pub response_chan: Sender<Option<Proposal<TYPES, QuorumProposal2<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, QuorumProposal2<TYPES>>, TYPES::SignatureKey),
    /// A quorum vote has been received from the network; handled by the consensus task
    QuorumVoteRecv(QuorumVote2<TYPES>),
    /// A timeout vote received from the network; handled by consensus task
    TimeoutVoteRecv(TimeoutVote2<TYPES>),
    /// Send a timeout vote to the network; emitted by consensus task replicas
    TimeoutVoteSend(TimeoutVote2<TYPES>),
    /// A DA proposal has been received from the network; handled by the DA task
    DaProposalRecv(Proposal<TYPES, DaProposal2<TYPES>>, TYPES::SignatureKey),
    /// A DA proposal has been validated; handled by the DA task and VID task
    DaProposalValidated(Proposal<TYPES, DaProposal2<TYPES>>, TYPES::SignatureKey),
    /// A DA vote has been received by the network; handled by the DA task
    DaVoteRecv(DaVote2<TYPES>),
    /// A Data Availability Certificate (DAC) has been received by the network; handled by the consensus task
    DaCertificateRecv(DaCertificate2<TYPES>),
    /// A DAC is validated.
    DaCertificateValidated(DaCertificate2<TYPES>),
    /// Send a quorum proposal to the network; emitted by the leader in the consensus task
    QuorumProposalSend(Proposal<TYPES, QuorumProposal2<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(QuorumVote2<TYPES>),
    /// Broadcast a quorum vote to form an eQC; emitted by a replica in the consensus task after seeing a valid quorum proposal
    ExtendedQuorumVoteSend(QuorumVote2<TYPES>),
    /// 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(Proposal<TYPES, QuorumProposal2<TYPES>>, Leaf2<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, QuorumProposal2<TYPES>>),
    /// A quorum proposal was requested by a node for a view.
    QuorumProposalResponseRecv(Proposal<TYPES, QuorumProposal2<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, DaProposal2<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(DaVote2<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 next leader has collected enough votes to form a QC; emitted by the next leader in the consensus task; an internal event only
    Qc2Formed(Either<QuorumCertificate2<TYPES>, TimeoutCertificate2<TYPES>>),
    /// The next leader has collected enough votes from the next epoch nodes to form a QC; emitted by the next leader in the consensus task; an internal event only
    NextEpochQc2Formed(Either<NextEpochQuorumCertificate2<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(DaCertificate2<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::View, TYPES::Epoch),
    /// Timeout for the view sync protocol; emitted by a replica in the view sync task
    ViewSyncTimeout(TYPES::View, u64, ViewSyncPhase),

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

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

    /// Receive a `ViewSyncPreCommitCertificate` from the network; received by a replica in the view sync task
    ViewSyncPreCommitCertificateRecv(ViewSyncPreCommitCertificate2<TYPES>),
    /// Receive a `ViewSyncCommitCertificate` from the network; received by a replica in the view sync task
    ViewSyncCommitCertificateRecv(ViewSyncCommitCertificate2<TYPES>),
    /// Receive a `ViewSyncFinalizeCertificate` from the network; received by a replica in the view sync task
    ViewSyncFinalizeCertificateRecv(ViewSyncFinalizeCertificate2<TYPES>),

    /// Send a `ViewSyncPreCommitCertificate` from the network; emitted by a relay in the view sync task
    ViewSyncPreCommitCertificateSend(ViewSyncPreCommitCertificate2<TYPES>, TYPES::SignatureKey),
    /// Send a `ViewSyncCommitCertificate` from the network; emitted by a relay in the view sync task
    ViewSyncCommitCertificateSend(ViewSyncCommitCertificate2<TYPES>, TYPES::SignatureKey),
    /// Send a `ViewSyncFinalizeCertificate` from the network; emitted by a relay in the view sync task
    ViewSyncFinalizeCertificateSend(ViewSyncFinalizeCertificate2<TYPES>, TYPES::SignatureKey),

    /// Trigger the start of the view sync protocol; emitted by view sync task; internal trigger only
    ViewSyncTrigger(TYPES::View),
    /// 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::View, TYPES::Epoch),
    /// 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::View,
        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>),
    /// 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(
        TYPES::SignatureKey,
        Proposal<TYPES, VidDisperseShare2<TYPES>>,
    ),
    /// VID share data is validated.
    VidShareValidated(Proposal<TYPES, VidDisperseShare2<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>),
    /// 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, QuorumProposal2<TYPES>>),

    /// Send a VID request to the network; emitted to on of the members of DA committee.
    /// Includes the data request, node's public key and signature as well as public key of DA committee who we want to send to.
    VidRequestSend(
        DataRequest<TYPES>,
        // Sender
        TYPES::SignatureKey,
        // Recipient
        TYPES::SignatureKey,
    ),

    /// Receive a VID request from the network; Received by a node in the DA committee.
    /// Includes the data request and nodes public key.
    VidRequestRecv(DataRequest<TYPES>, TYPES::SignatureKey),

    /// Send a VID response to the network; emitted to the sending node.
    /// Includes nodes public key, recipient public key, and vid disperse
    VidResponseSend(
        /// Sender key
        TYPES::SignatureKey,
        /// Recipient key
        TYPES::SignatureKey,
        Proposal<TYPES, VidDisperseShare2<TYPES>>,
    ),

    /// Receive a VID response from the network; received by the node that triggered the VID request.
    VidResponseRecv(
        TYPES::SignatureKey,
        Proposal<TYPES, VidDisperseShare2<TYPES>>,
    ),

    /// A replica send us a High QC
    HighQcRecv(QuorumCertificate2<TYPES>, TYPES::SignatureKey),

    /// Send our HighQc to the next leader, should go to the same leader as our vote
    HighQcSend(
        QuorumCertificate2<TYPES>,
        TYPES::SignatureKey,
        TYPES::SignatureKey,
    ),
}

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::View> {
        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, _)
            | HotShotEvent::QuorumProposalValidated(proposal, _)
            | HotShotEvent::QuorumProposalResponseRecv(proposal)
            | HotShotEvent::QuorumProposalResponseSend(_, proposal)
            | HotShotEvent::QuorumProposalPreliminarilyValidated(proposal) => {
                Some(proposal.data.view_number())
            }
            HotShotEvent::QuorumVoteSend(vote) | HotShotEvent::ExtendedQuorumVoteSend(vote) => {
                Some(vote.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::Qc2Formed(cert) => match cert {
                either::Left(qc) => Some(qc.view_number()),
                either::Right(tc) => Some(tc.view_number()),
            },
            HotShotEvent::NextEpochQc2Formed(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::ViewSyncPreCommitCertificateRecv(cert)
            | HotShotEvent::ViewSyncPreCommitCertificateSend(cert, _) => Some(cert.view_number()),
            HotShotEvent::ViewSyncCommitCertificateRecv(cert)
            | HotShotEvent::ViewSyncCommitCertificateSend(cert, _) => Some(cert.view_number()),
            HotShotEvent::ViewSyncFinalizeCertificateRecv(cert)
            | HotShotEvent::ViewSyncFinalizeCertificateSend(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::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::ViewChange(view_number, _)
            | HotShotEvent::ViewSyncTimeout(view_number, _, _)
            | HotShotEvent::ViewSyncTrigger(view_number)
            | HotShotEvent::Timeout(view_number, ..) => Some(*view_number),
            HotShotEvent::DaCertificateRecv(cert) | HotShotEvent::DacSend(cert, _) => {
                Some(cert.view_number())
            }
            HotShotEvent::DaCertificateValidated(cert) => Some(cert.view_number),
            HotShotEvent::UpgradeCertificateFormed(cert) => Some(cert.view_number()),
            HotShotEvent::VidRequestSend(request, _, _)
            | HotShotEvent::VidRequestRecv(request, _) => Some(request.view),
            HotShotEvent::VidResponseSend(_, _, proposal)
            | HotShotEvent::VidResponseRecv(_, proposal) => Some(proposal.data.view_number),
            HotShotEvent::HighQcRecv(qc, _) | HotShotEvent::HighQcSend(qc, ..) => {
                Some(qc.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::ExtendedQuorumVoteSend(v) => {
                write!(
                    f,
                    "ExtendedQuorumVoteSend(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::QuorumProposalValidated(proposal, _) => write!(
                f,
                "QuorumProposalValidated(view_number={:?})",
                proposal.data.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::Qc2Formed(cert) => match cert {
                either::Left(qc) => write!(f, "QcFormed2(view_number={:?})", qc.view_number()),
                either::Right(tc) => write!(f, "QcFormed2(view_number={:?})", tc.view_number()),
            },
            HotShotEvent::NextEpochQc2Formed(cert) => match cert {
                either::Left(qc) => {
                    write!(f, "NextEpochQc2Formed(view_number={:?})", qc.view_number())
                }
                either::Right(tc) => {
                    write!(f, "NextEpochQc2Formed(view_number={:?})", tc.view_number())
                }
            },
            HotShotEvent::DacSend(cert, _) => {
                write!(f, "DacSend(view_number={:?})", cert.view_number())
            }
            HotShotEvent::ViewChange(view_number, epoch_number) => {
                write!(
                    f,
                    "ViewChange(view_number={view_number:?}, epoch_number={epoch_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::ViewSyncPreCommitCertificateRecv(cert) => {
                write!(
                    f,
                    "ViewSyncPreCommitCertificateRecv(view_number={:?})",
                    cert.view_number()
                )
            }
            HotShotEvent::ViewSyncCommitCertificateRecv(cert) => {
                write!(
                    f,
                    "ViewSyncCommitCertificateRecv(view_number={:?})",
                    cert.view_number()
                )
            }
            HotShotEvent::ViewSyncFinalizeCertificateRecv(cert) => {
                write!(
                    f,
                    "ViewSyncFinalizeCertificateRecv(view_number={:?})",
                    cert.view_number()
                )
            }
            HotShotEvent::ViewSyncPreCommitCertificateSend(cert, _) => {
                write!(
                    f,
                    "ViewSyncPreCommitCertificateSend(view_number={:?})",
                    cert.view_number()
                )
            }
            HotShotEvent::ViewSyncCommitCertificateSend(cert, _) => {
                write!(
                    f,
                    "ViewSyncCommitCertificateSend(view_number={:?})",
                    cert.view_number()
                )
            }
            HotShotEvent::ViewSyncFinalizeCertificateSend(cert, _) => {
                write!(
                    f,
                    "ViewSyncFinalizeCertificateSend(view_number={:?})",
                    cert.view_number()
                )
            }
            HotShotEvent::ViewSyncTrigger(view_number) => {
                write!(f, "ViewSyncTrigger(view_number={view_number:?})")
            }
            HotShotEvent::Timeout(view_number, epoch) => {
                write!(f, "Timeout(view_number={view_number:?}, epoch={epoch:?})")
            }
            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::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::QuorumProposalPreliminarilyValidated(proposal) => {
                write!(
                    f,
                    "QuorumProposalPreliminarilyValidated(view_number={:?}",
                    proposal.data.view_number()
                )
            }
            HotShotEvent::VidRequestSend(request, _, _) => {
                write!(f, "VidRequestSend(view_number={:?}", request.view)
            }
            HotShotEvent::VidRequestRecv(request, _) => {
                write!(f, "VidRequestRecv(view_number={:?}", request.view)
            }
            HotShotEvent::VidResponseSend(_, _, proposal) => {
                write!(
                    f,
                    "VidResponseSend(view_number={:?}",
                    proposal.data.view_number
                )
            }
            HotShotEvent::VidResponseRecv(_, proposal) => {
                write!(
                    f,
                    "VidResponseRecv(view_number={:?}",
                    proposal.data.view_number
                )
            }
            HotShotEvent::HighQcRecv(qc, _) => {
                write!(f, "HighQcRecv(view_number={:?}", qc.view_number())
            }
            HotShotEvent::HighQcSend(qc, ..) => {
                write!(f, "HighQcSend(view_number={:?}", qc.view_number())
            }
        }
    }
}