tempo_commonware_node/epoch/manager/
ingress.rs1use commonware_consensus::{Reporter, types::Epoch};
2use commonware_cryptography::{
3 bls12381::primitives::{group::Share, poly::Public, variant::MinSig},
4 ed25519::PublicKey,
5};
6use commonware_utils::set::Ordered;
7use eyre::WrapErr as _;
8use futures::channel::mpsc;
9use tracing::{Span, warn};
10
11#[derive(Clone, Debug)]
12pub(crate) struct Mailbox {
13 inner: mpsc::UnboundedSender<Message>,
14}
15
16impl Mailbox {
17 pub(super) fn new(inner: mpsc::UnboundedSender<Message>) -> Self {
18 Self { inner }
19 }
20}
21
22#[derive(Debug)]
23pub(super) struct Message {
24 pub(super) cause: Span,
25 pub(super) activity: Activity,
26}
27
28impl Message {
29 fn in_current_span(activity: impl Into<Activity>) -> Self {
30 Self {
31 cause: Span::current(),
32 activity: activity.into(),
33 }
34 }
35}
36
37#[derive(Debug)]
38pub(crate) enum Activity {
39 Enter(Enter),
40 Exit(Exit),
41}
42
43impl From<Enter> for Activity {
44 fn from(value: Enter) -> Self {
45 Self::Enter(value)
46 }
47}
48
49impl From<Exit> for Activity {
50 fn from(value: Exit) -> Self {
51 Self::Exit(value)
52 }
53}
54
55#[derive(Debug)]
56pub(crate) struct Enter {
57 pub(crate) epoch: Epoch,
58 pub(crate) public: Public<MinSig>,
59 pub(crate) share: Option<Share>,
60 pub(crate) participants: Ordered<PublicKey>,
61}
62
63#[derive(Debug)]
64pub(crate) struct Exit {
65 pub(crate) epoch: Epoch,
66}
67
68impl Reporter for Mailbox {
69 type Activity = Activity;
70
71 async fn report(&mut self, command: Self::Activity) {
72 if let Err(error) = self
74 .inner
75 .unbounded_send(Message::in_current_span(command))
76 .wrap_err("epoch manager no longer running")
77 {
78 warn!(%error, "failed to report epoch event to epoch manager")
79 }
80 }
81}