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