diff --git a/phaselock-types/src/event.rs b/phaselock-types/src/event.rs new file mode 100644 index 0000000000..eface47bee --- /dev/null +++ b/phaselock-types/src/event.rs @@ -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 { + /// 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, +} + +/// 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 { + /// A view encountered an error and was interrupted + Error { + /// The underlying error + error: Arc, + }, + /// A new block was proposed + Propose { + /// The block that was proposed + block: Arc, + }, + /// 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>, + /// 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>, + }, + /// 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, + }, +} diff --git a/phaselock-types/src/lib.rs b/phaselock-types/src/lib.rs index 3e71fbb900..cd2619b9b6 100644 --- a/phaselock-types/src/lib.rs +++ b/phaselock-types/src/lib.rs @@ -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; diff --git a/src/types/event.rs b/src/types/event.rs index f408c63db9..473ce092b8 100644 --- a/src/types/event.rs +++ b/src/types/event.rs @@ -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 { - /// 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, -} - -/// 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 { - /// A view encountered an error and was interrupted - Error { - /// The underlying error - error: Arc, - }, - /// A new block was proposed - Propose { - /// The block that was proposed - block: Arc, - }, - /// 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>, - /// 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>, - }, - /// 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};