fedimint_server/consensus/aleph_bft/
mod.rs

1pub mod backup;
2pub mod data_provider;
3pub mod finalization_handler;
4pub mod keychain;
5pub mod network;
6pub mod spawner;
7
8use aleph_bft::NodeIndex;
9use fedimint_core::encoding::{Decodable, Encodable};
10use fedimint_core::PeerId;
11use serde::{Deserialize, Serialize};
12
13/// The majority of these messages need to be delivered to the intended
14/// [Recipient] in order for aleph bft to make progress. However, alpeh bft does
15/// not assume a reliable network layer and implements all necessary retry
16/// logic. Therefore, the network layer can discard a message if its
17/// intended recipient is offline.
18#[derive(Clone, Debug, Encodable, Decodable, Serialize, Deserialize)]
19pub struct Message(Vec<u8>);
20
21/// This enum defines the intended recipient of a [Message].
22#[derive(Clone, Copy, Debug, PartialEq, Eq)]
23pub enum Recipient {
24    Everyone,
25    Peer(PeerId),
26}
27
28pub fn to_peer_id(node_index: NodeIndex) -> PeerId {
29    u16::try_from(usize::from(node_index))
30        .expect("The node index corresponds to a valid PeerId")
31        .into()
32}
33
34pub fn to_node_index(peer_id: PeerId) -> NodeIndex {
35    usize::from(u16::from(peer_id)).into()
36}