commonware-reshare 2026.4.0

Reshare a threshold secret over an epoched log.
//! Inbound communication channel for epoch transitions.

use commonware_consensus::types::Epoch;
use commonware_cryptography::{
    bls12381::primitives::{group, sharing::Sharing, variant::Variant},
    PublicKey,
};
use commonware_utils::{channel::mpsc, ordered::Set};
use tracing::error;

/// Messages that can be sent to the orchestrator.
pub enum Message<V: Variant, P: PublicKey> {
    Enter(EpochTransition<V, P>),
    Exit(Epoch),
}

/// A notification of an epoch transition.
pub struct EpochTransition<V: Variant, P: PublicKey> {
    /// The epoch to transition to.
    pub epoch: Epoch,
    /// The public polynomial for the epoch.
    pub poly: Option<Sharing<V>>,
    /// The share for the local participant for the epoch, if participating.
    pub share: Option<group::Share>,
    /// The dealers for the epoch.
    pub dealers: Set<P>,
}

/// Inbound communication channel for epoch transitions.
#[derive(Debug, Clone)]
pub struct Mailbox<V: Variant, P: PublicKey> {
    sender: mpsc::Sender<Message<V, P>>,
}

impl<V: Variant, P: PublicKey> Mailbox<V, P> {
    /// Create a new [Mailbox].
    pub const fn new(sender: mpsc::Sender<Message<V, P>>) -> Self {
        Self { sender }
    }

    pub async fn enter(&mut self, transition: EpochTransition<V, P>) {
        if let Err(err) = self.sender.send(Message::Enter(transition)).await {
            error!(?err, "failed to send epoch transition");
        }
    }

    pub async fn exit(&mut self, epoch: Epoch) {
        if let Err(err) = self.sender.send(Message::Exit(epoch)).await {
            error!(?err, "failed to send epoch exit");
        }
    }
}