Skip to main content

hotshot_example_types/membership/
mod.rs

1// Copyright (c) 2021-2024 Espresso Systems (espressosys.com)
2// This file is part of the HotShot repository.
3
4// You should have received a copy of the MIT License
5// along with the HotShot repository. If not, see <https://mit-license.org/>.
6
7//! elections used for consensus
8
9use std::sync::Arc;
10
11use async_broadcast::Receiver;
12use hotshot_types::{
13    PeerConfig,
14    event::Event,
15    traits::{
16        election::Membership, leaf_fetcher_network::LeafFetcherNetwork,
17        node_implementation::NodeType,
18    },
19};
20
21use crate::storage_types::TestStorage;
22
23/// leader completely randomized every view
24pub mod randomized_committee;
25
26/// quorum randomized every view, with configurable overlap
27pub mod randomized_committee_members;
28
29/// static (round robin) committee election
30pub mod static_committee;
31
32/// static (round robin leader for 2 consecutive views) committee election
33pub mod static_committee_leader_two_views;
34/// two static (round robin) committees for even and odd epochs
35pub mod two_static_committees;
36
37/// general helpers
38pub mod helpers;
39
40pub mod fetcher;
41
42pub mod stake_table;
43
44pub mod strict_membership;
45
46/// Test-only extension of [`Membership`] that lets tests install the
47/// `Leaf2Fetcher` wiring needed for epoch-root catchup. Production
48/// memberships don't need this — only types that route catchup through a
49/// test fetcher (e.g. `StrictMembership`) implement it.
50pub trait TestableMembership<TYPES: NodeType>: Membership<TYPES> {
51    /// Construct a membership for tests.
52    fn new(
53        quorum_members: Vec<PeerConfig<TYPES>>,
54        da_members: Vec<PeerConfig<TYPES>>,
55        public_key: TYPES::SignatureKey,
56        epoch_height: u64,
57    ) -> Self;
58
59    /// Install a fully wired leaf fetcher. Must be called before any code
60    /// path that triggers catchup (`get_epoch_root` / `get_epoch_drb`).
61    fn set_leaf_fetcher(
62        &self,
63        network: Arc<dyn LeafFetcherNetwork<TYPES>>,
64        storage: TestStorage<TYPES>,
65        public_key: TYPES::SignatureKey,
66        channel: Receiver<Event<TYPES>>,
67    );
68}