Skip to main content

tempo_commonware_node/follow/
stubs.rs

1//! Stub implementations for running marshal in follow mode.
2//!
3//! The null broadcast stub satisfies marshal's type requirements but is never
4//! actually used because the follower never broadcasts blocks.
5
6use commonware_broadcast::buffered;
7use commonware_cryptography::{
8    Signer as _,
9    ed25519::{PrivateKey, PublicKey},
10};
11use commonware_math::algebra::Random as _;
12use commonware_p2p::utils::StaticProvider;
13use commonware_runtime::{BufferPooler, Clock, Metrics, Spawner};
14use commonware_utils::ordered::Set;
15use rand_08::SeedableRng as _;
16
17use crate::consensus::block::Block;
18
19/// Create a null broadcast mailbox
20///
21/// In follow mode, there are no consensus peers to broadcast state or
22/// request information from. The FollowResolver is backed by the
23/// execution node and upstream ws connection.
24pub(super) fn null_broadcast<E: Clock + Spawner + Metrics + BufferPooler>(
25    context: E,
26    mailbox_size: usize,
27) -> buffered::Mailbox<PublicKey, Block> {
28    // Generate a random public key for the unused broadcast engine
29    let mut rng = rand_08::rngs::StdRng::seed_from_u64(0);
30    let private_key = PrivateKey::random(&mut rng);
31    let public_key = private_key.public_key();
32
33    let config = buffered::Config {
34        public_key,
35        mailbox_size,
36        deque_size: 0,
37        priority: false,
38        codec_config: (),
39        peer_provider: StaticProvider::new(0, Set::default()),
40    };
41
42    let (_engine, mailbox) = buffered::Engine::new(context, config);
43    mailbox
44}