use crate::{ simplex::{metrics::TimeoutReason, types::Vote}, types::{Participant, View}, }; use commonware_cryptography::{certificate::Scheme, Digest}; use commonware_utils::channel::{fallible::AsyncFallibleExt, mpsc, oneshot}; /// Messages sent to the [super::actor::Actor]. pub enum Message { /// View update with leader info. Update { current: View, leader: Participant, finalized: View, response: oneshot::Sender>, }, /// A constructed vote (needed for quorum). Constructed(Vote), } #[derive(Clone)] pub struct Mailbox { sender: mpsc::Sender>, } impl Mailbox { /// Create a new mailbox. pub const fn new(sender: mpsc::Sender>) -> Self { Self { sender } } /// Send an update message. /// /// Returns `None` if the leader is active, or `Some(reason)` if the round /// should be nullified. pub async fn update( &mut self, current: View, leader: Participant, finalized: View, ) -> Option { self.sender .request_or( |response| Message::Update { current, leader, finalized, response, }, None, ) .await } /// Send a constructed vote. pub async fn constructed(&mut self, message: Vote) { self.sender.send_lossy(Message::Constructed(message)).await; } }