Skip to content

Commit

Permalink
feat: Migrate event type
Browse files Browse the repository at this point in the history
  • Loading branch information
nmccarty committed Feb 15, 2022
1 parent e10b761 commit af8e756
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 74 deletions.
75 changes: 75 additions & 0 deletions phaselock-types/src/event.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//! Events that a `PhaseLock` instance can emit
use std::sync::Arc;

use crate::{data::Stage, error::PhaseLockError};

/// A status event emitted by a `PhaseLock` instance
///
/// This includes some metadata, such as the stage and view number that the event was generated in,
/// as well as an inner [`EventType`] describing the event proper.
#[derive(Clone, Debug)]
pub struct Event<B: Send + Sync, S: Send + Sync> {
/// The view number that this event originates from
pub view_number: u64,
/// The stage that this event originates from
pub stage: Stage,
/// The underlying event
pub event: EventType<B, S>,
}

/// The type and contents of a status event emitted by a `PhaseLock` instance
///
/// This enum does not include metadata shared among all variants, such as the stage and view
/// number, and is thus always returned wrapped in an [`Event`].
#[non_exhaustive]
#[derive(Clone, Debug)]
pub enum EventType<B: Send + Sync, S: Send + Sync> {
/// A view encountered an error and was interrupted
Error {
/// The underlying error
error: Arc<PhaseLockError>,
},
/// A new block was proposed
Propose {
/// The block that was proposed
block: Arc<B>,
},
/// A new decision event was issued
Decide {
/// The list of blocks that were committed by this decision
///
/// This list is sorted in reverse view number order, with the newest (highest view number)
/// block first in the list.
///
/// This list may be incomplete if the node is currently performing catchup.
block: Arc<Vec<B>>,
/// The list of states that were committed by this decision
///
/// This list is sorted in reverse view number order, with the newest (highest view number)
/// state first in the list.
///
/// This list may be incomplete if the node is currently performing catchup.
state: Arc<Vec<S>>,
},
/// A new view was started by this node
NewView {
/// The view being started
view_number: u64,
},
/// A view was canceled by a timeout interrupt
ViewTimeout {
/// The view that timed out
view_number: u64,
},
/// This node is the leader for this view
Leader {
/// The current view number
view_number: u64,
},
/// This node is a follower for this view
Follower {
/// The current view number
view_number: u64,
},
}
1 change: 1 addition & 0 deletions phaselock-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub use threshold_crypto as tc;

pub mod data;
pub mod error;
pub mod event;
pub mod message;
pub mod traits;

Expand Down
75 changes: 1 addition & 74 deletions src/types/event.rs
Original file line number Diff line number Diff line change
@@ -1,76 +1,3 @@
//! Events that a [`PhaseLock`](crate::PhaseLock) instance can emit
use crate::{data::Stage, PhaseLockError};

use std::sync::Arc;

/// A status event emitted by a [`PhaseLock`](crate::PhaseLock) instance
///
/// This includes some metadata, such as the stage and view number that the event was generated in,
/// as well as an inner [`EventType`] describing the event proper.
#[non_exhaustive]
#[derive(Clone, Debug)]
pub struct Event<B: Send + Sync, S: Send + Sync> {
/// The view number that this event originates from
pub view_number: u64,
/// The stage that this event originates from
pub stage: Stage,
/// The underlying event
pub event: EventType<B, S>,
}

/// The type and contents of a status event emitted by a [`PhaseLock`](crate::PhaseLock) instance
///
/// This enum does not include metadata shared among all variants, such as the stage and view
/// number, and is thus always returned wrapped in an [`Event`].
#[non_exhaustive]
#[derive(Clone, Debug)]
pub enum EventType<B: Send + Sync, S: Send + Sync> {
/// A view encountered an error and was interrupted
Error {
/// The underlying error
error: Arc<PhaseLockError>,
},
/// A new block was proposed
Propose {
/// The block that was proposed
block: Arc<B>,
},
/// A new decision event was issued
Decide {
/// The list of blocks that were committed by this decision
///
/// This list is sorted in reverse view number order, with the newest (highest view number)
/// block first in the list.
///
/// This list may be incomplete if the node is currently performing catchup.
block: Arc<Vec<B>>,
/// The list of states that were committed by this decision
///
/// This list is sorted in reverse view number order, with the newest (highest view number)
/// state first in the list.
///
/// This list may be incomplete if the node is currently performing catchup.
state: Arc<Vec<S>>,
},
/// A new view was started by this node
NewView {
/// The view being started
view_number: u64,
},
/// A view was canceled by a timeout interrupt
ViewTimeout {
/// The view that timed out
view_number: u64,
},
/// This node is the leader for this view
Leader {
/// The current view number
view_number: u64,
},
/// This node is a follower for this view
Follower {
/// The current view number
view_number: u64,
},
}
pub use phaselock_types::event::{Event, EventType};

0 comments on commit af8e756

Please sign in to comment.