tempo_commonware_node/dkg/manager/
mod.rs

1use std::net::SocketAddr;
2
3use commonware_cryptography::{
4    bls12381::primitives::group::Share,
5    ed25519::{PrivateKey, PublicKey},
6};
7use commonware_runtime::{Clock, Metrics, Spawner, Storage};
8use commonware_utils::set::OrderedAssociated;
9use eyre::WrapErr as _;
10use futures::channel::mpsc;
11use rand_core::CryptoRngCore;
12use tempo_node::TempoFullNode;
13
14mod actor;
15mod ingress;
16mod validators;
17
18pub(crate) use actor::Actor;
19pub(crate) use ingress::Mailbox;
20
21use validators::DecodedValidator;
22
23use ingress::{Command, Message};
24
25use crate::epoch;
26
27pub(crate) async fn init<TContext, TPeerManager>(
28    context: TContext,
29    config: Config<TPeerManager>,
30) -> eyre::Result<(Actor<TContext, TPeerManager>, Mailbox)>
31where
32    TContext: Clock + CryptoRngCore + Metrics + Spawner + Storage,
33    TPeerManager: commonware_p2p::Manager<
34            PublicKey = PublicKey,
35            Peers = OrderedAssociated<PublicKey, SocketAddr>,
36        >,
37{
38    let (tx, rx) = mpsc::unbounded();
39
40    let actor = Actor::new(config, context, rx)
41        .await
42        .wrap_err("failed initializing actor")?;
43    let mailbox = Mailbox { inner: tx };
44    Ok((actor, mailbox))
45}
46
47pub(crate) struct Config<TPeerManager> {
48    pub(crate) epoch_manager: epoch::manager::Mailbox,
49
50    /// The namespace the dkg manager will use when sending messages during
51    /// a dkg ceremony.
52    pub(crate) namespace: Vec<u8>,
53
54    pub(crate) me: PrivateKey,
55
56    /// The number of heights per epoch.
57    pub(crate) epoch_length: u64,
58
59    pub(crate) mailbox_size: usize,
60
61    /// The mailbox to the marshal actor. Used to determine if an epoch
62    /// can be started at startup.
63    pub(crate) marshal: crate::alias::marshal::Mailbox,
64
65    /// The partition prefix to use when persisting ceremony metadata during
66    /// rounds.
67    pub(crate) partition_prefix: String,
68
69    /// The full execution layer node. On init, used to read the initial set
70    /// of peers and public polynomial (either from chainspec if running
71    /// pre-allegretto or from the genesis extra_data header and block state if
72    /// post-allegretto).
73    ///
74    /// During normal operation, used to read the validator config at the end
75    /// of each epoch.
76    pub(crate) execution_node: TempoFullNode,
77
78    /// This node's initial share of the bls12381 private key.
79    pub(crate) initial_share: Option<Share>,
80
81    /// The peer manager on which the dkg actor will register new peers for a
82    /// given epoch after reading them from the smart contract.
83    pub(crate) peer_manager: TPeerManager,
84}