use crate::{
marshal::{
application::gates::{Gates, Staged},
core::{Mailbox, Variant},
},
simplex::Plan,
};
use commonware_actor::Feedback;
use commonware_cryptography::certificate::Scheme;
use commonware_p2p::Recipients;
use tracing::debug;
pub(crate) fn broadcast<S, V>(
gates: &Gates<V::Commitment, V::Block>,
marshal: &Mailbox<S, V>,
commitment: V::Commitment,
plan: Plan<S::PublicKey>,
) -> Feedback
where
S: Scheme,
V: Variant,
{
match plan {
Plan::Prepare { round } => {
let Some(block) = gates.send_staged(round, commitment) else {
debug!(%round, %commitment, "no unsent staged candidate to relay early");
return Feedback::Ok;
};
marshal.prepared(round, block, Recipients::All)
}
Plan::Propose { round } => {
let Some((Staged { block, ack }, sent)) = gates.take_staged(round, commitment) else {
debug!(%round, %commitment, "no staged proposal to relay");
return Feedback::Ok;
};
if sent {
marshal.verified_deferred(round, block, ack);
return Feedback::Ok;
}
marshal.proposed(round, block, Recipients::All, ack)
}
Plan::Forward { round, recipients } => marshal.forward(round, commitment, recipients),
}
}