fedimint_server/consensus/aleph_bft/
finalization_handler.rs

1use aleph_bft::{NodeIndex, Round};
2use fedimint_core::PeerId;
3
4use super::data_provider::UnitData;
5
6pub struct OrderedUnit {
7    pub creator: PeerId,
8    pub round: Round,
9    pub data: Option<UnitData>,
10}
11
12pub struct FinalizationHandler {
13    sender: async_channel::Sender<OrderedUnit>,
14}
15
16impl FinalizationHandler {
17    pub fn new(sender: async_channel::Sender<OrderedUnit>) -> Self {
18        Self { sender }
19    }
20}
21
22impl aleph_bft::FinalizationHandler<UnitData> for FinalizationHandler {
23    fn data_finalized(&mut self, _data: UnitData) {
24        unreachable!("This method is not called")
25    }
26
27    fn unit_finalized(&mut self, creator: NodeIndex, round: Round, data: Option<UnitData>) {
28        // the channel is unbounded
29        self.sender
30            .try_send(OrderedUnit {
31                creator: super::to_peer_id(creator),
32                round,
33                data,
34            })
35            .ok();
36    }
37}