Skip to main content

tempo_commonware_node/consensus/application/
mod.rs

1//! The interface between the consensus layer and the execution layer.
2//!
3//! The application actor implements the [`commonware_consensus::Automaton`]
4//! trait to propose and verify blocks.
5
6use std::{sync::Arc, time::Duration};
7
8use commonware_consensus::types::FixedEpocher;
9use commonware_cryptography::ed25519::PublicKey;
10use commonware_runtime::{Metrics, Pacer, Spawner, Storage};
11
12use eyre::WrapErr as _;
13use rand_08::{CryptoRng, Rng};
14use tempo_node::TempoFullNode;
15
16mod actor;
17mod ingress;
18
19pub(super) use actor::Actor;
20pub(crate) use ingress::Mailbox;
21
22use crate::{epoch::SchemeProvider, subblocks};
23
24pub(super) async fn init<TContext>(
25    config: Config<TContext>,
26) -> eyre::Result<(Actor<TContext>, Mailbox)>
27where
28    TContext: Pacer + governor::clock::Clock + Rng + CryptoRng + Spawner + Storage + Metrics,
29{
30    let actor = Actor::init(config)
31        .await
32        .wrap_err("failed initializing actor")?;
33    let mailbox = actor.mailbox().clone();
34    Ok((actor, mailbox))
35}
36
37pub(super) struct Config<TContext> {
38    /// The execution context of the commonwarexyz application (tokio runtime, etc).
39    pub(super) context: TContext,
40
41    /// This node's ed25519 public key, used to look up the fee recipient from
42    /// the validator config v2 contract.
43    pub(super) public_key: PublicKey,
44
45    /// Number of messages from consensus to hold in our backlog
46    /// before blocking.
47    pub(super) mailbox_size: usize,
48
49    /// For subscribing to blocks distributed via the consensus p2p network.
50    pub(super) marshal: crate::alias::marshal::Mailbox,
51
52    pub(super) executor: crate::executor::Mailbox,
53
54    /// A handle to the execution node to verify and create new payloads.
55    pub(super) execution_node: Arc<TempoFullNode>,
56
57    /// A handle to the subblocks service to get subblocks for proposals.
58    pub(crate) subblocks: Option<subblocks::Mailbox>,
59
60    /// The minimum amount of time to wait before resolving a new payload from the builder.
61    pub(super) payload_resolve_time: Duration,
62
63    /// The minimum amount of time to wait before returning the built payload back to consensus for proposal.
64    pub(super) payload_return_time: Duration,
65
66    /// The epoch strategy used by tempo, to map block heights to epochs.
67    pub(super) epoch_strategy: FixedEpocher,
68
69    /// The scheme provider to use for the application.
70    pub(crate) scheme_provider: SchemeProvider,
71}