Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeiannucci committed Aug 27, 2024
1 parent ab7622b commit c374244
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 35 deletions.
72 changes: 38 additions & 34 deletions crates/task-impls/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,62 +236,66 @@ impl<TYPES: NodeType> HotShotEvent<TYPES> {
/// Return the view number for a hotshot event if present
pub fn view_number(&self) -> Option<TYPES::Time> {
match self {
HotShotEvent::Shutdown => None,
HotShotEvent::QuorumProposalRecv(proposal, _) => Some(proposal.data.view_number()),
HotShotEvent::QuorumVoteRecv(v) => Some(v.view_number()),
HotShotEvent::TimeoutVoteRecv(v) | HotShotEvent::TimeoutVoteSend(v) => {
Some(v.view_number())
}
HotShotEvent::DaProposalRecv(proposal, _) => Some(proposal.data.view_number()),
HotShotEvent::DaProposalValidated(proposal, _) => Some(proposal.data.view_number()),
HotShotEvent::DaVoteRecv(vote) => Some(vote.view_number()),
HotShotEvent::QuorumProposalSend(proposal, _) => Some(proposal.data.view_number()),
HotShotEvent::QuorumProposalRecv(proposal, _)
| HotShotEvent::QuorumProposalSend(proposal, _) => Some(proposal.data.view_number()),
HotShotEvent::QuorumVoteSend(vote) => Some(vote.view_number()),
HotShotEvent::QuorumVoteDependenciesValidated(view_number) => Some(*view_number),
HotShotEvent::QuorumProposalValidated(proposal, _) => Some(proposal.view_number()),
HotShotEvent::DaProposalSend(proposal, _) => Some(proposal.data.view_number()),
HotShotEvent::DaVoteSend(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::ViewChange(view_number) => Some(*view_number),
HotShotEvent::ViewSyncTimeout(view_number, _, _) => Some(*view_number),
HotShotEvent::ViewSyncPreCommitVoteRecv(vote) => Some(vote.view_number()),
HotShotEvent::ViewSyncCommitVoteRecv(vote) => Some(vote.view_number()),
HotShotEvent::ViewSyncFinalizeVoteRecv(vote) => Some(vote.view_number()),
HotShotEvent::ViewSyncPreCommitVoteSend(vote) => Some(vote.view_number()),
HotShotEvent::ViewSyncCommitVoteSend(vote) => Some(vote.view_number()),
HotShotEvent::ViewSyncFinalizeVoteSend(vote) => Some(vote.view_number()),
HotShotEvent::ViewSyncPreCommitCertificate2Recv(cert) => Some(cert.view_number()),
HotShotEvent::ViewSyncCommitCertificate2Recv(cert) => Some(cert.view_number()),
HotShotEvent::ViewSyncFinalizeCertificate2Recv(cert) => Some(cert.view_number()),
HotShotEvent::ViewSyncPreCommitCertificate2Send(cert, _) => Some(cert.view_number()),
HotShotEvent::ViewSyncCommitCertificate2Send(cert, _) => Some(cert.view_number()),
HotShotEvent::ViewSyncFinalizeCertificate2Send(cert, _) => Some(cert.view_number()),
HotShotEvent::ViewSyncTrigger(view_number) => Some(*view_number),
HotShotEvent::Timeout(view_number) => Some(*view_number),
HotShotEvent::TransactionSend(_, _) => None,
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::LeafDecided(_) | HotShotEvent::TransactionsRecv(_) => None,
HotShotEvent::Shutdown
| HotShotEvent::TransactionSend(_, _)
| HotShotEvent::LeafDecided(_)
| HotShotEvent::TransactionsRecv(_) => None,
HotShotEvent::VidDisperseSend(proposal, _) => Some(proposal.data.view_number()),
HotShotEvent::VidShareRecv(proposal) => Some(proposal.data.view_number()),
HotShotEvent::VidShareValidated(proposal) => Some(proposal.data.view_number()),
HotShotEvent::UpgradeProposalRecv(proposal, _) => Some(proposal.data.view_number()),
HotShotEvent::UpgradeProposalSend(proposal, _) => Some(proposal.data.view_number()),
HotShotEvent::UpgradeVoteRecv(vote) => Some(vote.view_number()),
HotShotEvent::UpgradeVoteSend(vote) => Some(vote.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::BlockReady(_, 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),
Expand Down
2 changes: 1 addition & 1 deletion crates/testing/src/byzantine/byzantine_behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES> + std::fmt::Debug, V: Version
}

// add current view or push event to the map if view number has been added
let events_for_current_view = self.events_for_view.entry(view_number).or_insert(vec![]);
let events_for_current_view = self.events_for_view.entry(view_number).or_default();
events_for_current_view.push(event.clone());

// ensure we are actually able to lookback enough views
Expand Down

0 comments on commit c374244

Please sign in to comment.