use std::{sync::mpsc::Sender, time::SystemTime};
use ed25519_dalek::VerifyingKey;
use crate::{
hotstuff::{
messages::{NewView, Nudge, PhaseVote, Proposal},
types::PhaseCertificate,
},
pacemaker::{
messages::{AdvanceView, TimeoutVote},
types::TimeoutCertificate,
},
types::{
block::Block,
data_types::{BlockHeight, CryptoHash, ViewNumber},
update_sets::ValidatorSetUpdates,
},
};
pub enum Event {
InsertBlock(InsertBlockEvent),
CommitBlock(CommitBlockEvent),
PruneBlock(PruneBlockEvent),
UpdateHighestPC(UpdateHighestPCEvent),
UpdateLockedPC(UpdateLockedPCEvent),
UpdateHighestTC(UpdateHighestTCEvent),
UpdateValidatorSet(UpdateValidatorSetEvent),
Propose(ProposeEvent),
Nudge(NudgeEvent),
PhaseVote(PhaseVoteEvent),
NewView(NewViewEvent),
TimeoutVote(TimeoutVoteEvent),
AdvanceView(AdvanceViewEvent),
ReceiveProposal(ReceiveProposalEvent),
ReceiveNudge(ReceiveNudgeEvent),
ReceivePhaseVote(ReceivePhaseVoteEvent),
ReceiveNewView(ReceiveNewViewEvent),
ReceiveTimeoutVote(ReceiveTimeoutVoteEvent),
ReceiveAdvanceView(ReceiveAdvanceViewEvent),
StartView(StartViewEvent),
ViewTimeout(ViewTimeoutEvent),
CollectPC(CollectPCEvent),
CollectTC(CollectTCEvent),
StartSync(StartSyncEvent),
EndSync(EndSyncEvent),
ReceiveSyncRequest(ReceiveSyncRequestEvent),
SendSyncResponse(SendSyncResponseEvent),
}
impl Event {
pub fn publish(self, event_publisher: &Option<Sender<Event>>) {
if let Some(event_publisher) = event_publisher {
let _ = event_publisher.send(self);
}
}
}
pub struct InsertBlockEvent {
pub timestamp: SystemTime,
pub block: Block,
}
pub struct CommitBlockEvent {
pub timestamp: SystemTime,
pub block: CryptoHash,
}
pub struct PruneBlockEvent {
pub timestamp: SystemTime,
pub block: CryptoHash,
}
pub struct UpdateHighestPCEvent {
pub timestamp: SystemTime,
pub highest_pc: PhaseCertificate,
}
pub struct UpdateLockedPCEvent {
pub timestamp: SystemTime,
pub locked_pc: PhaseCertificate,
}
pub struct UpdateHighestTCEvent {
pub timestamp: SystemTime,
pub highest_tc: TimeoutCertificate,
}
pub struct UpdateValidatorSetEvent {
pub timestamp: SystemTime,
pub cause_block: CryptoHash,
pub validator_set_updates: ValidatorSetUpdates,
}
pub struct ProposeEvent {
pub timestamp: SystemTime,
pub proposal: Proposal,
}
pub struct NudgeEvent {
pub timestamp: SystemTime,
pub nudge: Nudge,
}
pub struct PhaseVoteEvent {
pub timestamp: SystemTime,
pub vote: PhaseVote,
}
pub struct NewViewEvent {
pub timestamp: SystemTime,
pub new_view: NewView,
}
pub struct AdvanceViewEvent {
pub timestamp: SystemTime,
pub advance_view: AdvanceView,
}
pub struct TimeoutVoteEvent {
pub timestamp: SystemTime,
pub timeout_vote: TimeoutVote,
}
pub struct ReceiveProposalEvent {
pub timestamp: SystemTime,
pub origin: VerifyingKey,
pub proposal: Proposal,
}
pub struct ReceiveNudgeEvent {
pub timestamp: SystemTime,
pub origin: VerifyingKey,
pub nudge: Nudge,
}
pub struct ReceivePhaseVoteEvent {
pub timestamp: SystemTime,
pub origin: VerifyingKey,
pub phase_vote: PhaseVote,
}
pub struct ReceiveNewViewEvent {
pub timestamp: SystemTime,
pub origin: VerifyingKey,
pub new_view: NewView,
}
pub struct ReceiveAdvanceViewEvent {
pub timestamp: SystemTime,
pub origin: VerifyingKey,
pub advance_view: AdvanceView,
}
pub struct ReceiveTimeoutVoteEvent {
pub timestamp: SystemTime,
pub origin: VerifyingKey,
pub timeout_vote: TimeoutVote,
}
pub struct StartViewEvent {
pub timestamp: SystemTime,
pub view: ViewNumber,
}
pub struct ViewTimeoutEvent {
pub timestamp: SystemTime,
pub view: ViewNumber,
}
pub struct CollectPCEvent {
pub timestamp: SystemTime,
pub phase_certificate: PhaseCertificate,
}
pub struct CollectTCEvent {
pub timestamp: SystemTime,
pub timeout_certificate: TimeoutCertificate,
}
pub struct StartSyncEvent {
pub timestamp: SystemTime,
pub peer: VerifyingKey,
}
pub struct EndSyncEvent {
pub timestamp: SystemTime,
pub peer: VerifyingKey,
pub blocks_synced: u64,
}
pub struct ReceiveSyncRequestEvent {
pub timestamp: SystemTime,
pub peer: VerifyingKey,
pub start_height: BlockHeight,
pub limit: u32,
}
pub struct SendSyncResponseEvent {
pub timestamp: SystemTime,
pub peer: VerifyingKey,
pub blocks: Vec<Block>,
pub highest_pc: PhaseCertificate,
}