//! Mailbox for the [`Actor`]. //! //! [`Actor`]: super::Actor use crate::dkg::ReshareBlock; use commonware_actor::{ Feedback, mailbox::{Policy, Sender}, }; use commonware_consensus::{Reporter, marshal::Update}; use commonware_utils::{Acknowledgement, acknowledgement::Exact}; use std::{collections::VecDeque, sync::Arc}; /// Messages that can be sent to the orchestrator. pub enum Message where B: ReshareBlock, A: Acknowledgement, { Finalized { block: Arc, acknowledgement: A }, } impl Policy for Message where B: ReshareBlock, A: Acknowledgement, { type Overflow = VecDeque; fn handle(overflow: &mut VecDeque, message: Self) { // Ensure delivery overflow.push_back(message); } } /// Inbound communication channel for epoch transitions. #[derive(Debug, Clone)] pub struct Mailbox where B: ReshareBlock, A: Acknowledgement, { sender: Sender>, } impl Mailbox where B: ReshareBlock, A: Acknowledgement, { /// Create a new [Mailbox]. pub const fn new(sender: Sender>) -> Self { Self { sender } } } impl Reporter for Mailbox where B: ReshareBlock, A: Acknowledgement, { type Activity = Update; fn report(&mut self, activity: Self::Activity) -> Feedback { let Update::Block(block, acknowledgement) = activity else { return Feedback::Ok; }; self.sender.enqueue(Message::Finalized { block, acknowledgement, }) } }