tempo_commonware_node/follow/upstream/ingress.rs
1use commonware_consensus::types::Height;
2use commonware_utils::channel::fallible::FallibleExt as _;
3use tempo_node::rpc::consensus::CertifiedBlock;
4use tokio::sync::{mpsc, oneshot};
5
6pub(super) enum Message {
7 /// Request for a finalization of a given height.
8 GetFinalization {
9 height: Height,
10 response: oneshot::Sender<Option<CertifiedBlock>>,
11 },
12}
13
14/// Mailbox to the Upstream actor to issue requests to.
15#[derive(Clone)]
16pub struct Mailbox(mpsc::UnboundedSender<Message>);
17
18impl Mailbox {
19 pub(super) fn new(tx: mpsc::UnboundedSender<Message>) -> Self {
20 Self(tx)
21 }
22
23 pub(crate) async fn get_finalization(&self, height: Height) -> Option<CertifiedBlock> {
24 self.0
25 .request(move |response| Message::GetFinalization { height, response })
26 .await
27 .flatten()
28 }
29}