commonware_consensus/threshold_simplex/
config.rs

1use super::{Context, View};
2use crate::{Automaton, Committer, Relay, ThresholdSupervisor};
3use commonware_cryptography::{bls12381::primitives::group, Scheme};
4use commonware_utils::Array;
5use governor::Quota;
6use std::time::Duration;
7
8/// Configuration for the consensus engine.
9pub struct Config<
10    C: Scheme,
11    D: Array,
12    A: Automaton<Context = Context<D>>,
13    R: Relay,
14    F: Committer,
15    S: ThresholdSupervisor<Seed = group::Signature, Index = View, Share = group::Share>,
16> {
17    /// Cryptographic primitives.
18    pub crypto: C,
19
20    /// Automaton for the consensus engine.
21    pub automaton: A,
22
23    /// Relay for the consensus engine.
24    pub relay: R,
25
26    /// Committer for the consensus engine.
27    pub committer: F,
28
29    /// Supervisor for the consensus engine.
30    pub supervisor: S,
31
32    /// Maximum number of messages to buffer on channels inside the consensus
33    /// engine before blocking.
34    pub mailbox_size: usize,
35
36    /// Prefix for all signed messages to prevent replay attacks.
37    pub namespace: Vec<u8>,
38
39    /// Number of views to replay concurrently during startup.
40    pub replay_concurrency: usize,
41
42    /// Amount of time to wait for a leader to propose a payload
43    /// in a view.
44    pub leader_timeout: Duration,
45
46    /// Amount of time to wait for a quorum of notarizations in a view
47    /// before attempting to skip the view.
48    pub notarization_timeout: Duration,
49
50    /// Amount of time to wait before retrying a nullify broadcast if
51    /// stuck in a view.
52    pub nullify_retry: Duration,
53
54    /// Number of views behind finalized tip to track
55    /// activity derived from validator messages.
56    pub activity_timeout: View,
57
58    /// Timeout to wait for a peer to respond to a request.
59    pub fetch_timeout: Duration,
60
61    /// Maximum number of notarizations/nullifications to request/respond with at once.
62    pub max_fetch_count: usize,
63
64    /// Maximum number of bytes to respond with at once.
65    pub max_fetch_size: usize,
66
67    /// Maximum rate of requests to send to a given peer.
68    ///
69    /// Inbound rate limiting is handled by `commonware-p2p`.
70    pub fetch_rate_per_peer: Quota,
71
72    /// Number of concurrent requests to make at once.
73    pub fetch_concurrent: usize,
74}
75
76impl<
77        C: Scheme,
78        D: Array,
79        A: Automaton<Context = Context<D>>,
80        R: Relay,
81        F: Committer,
82        S: ThresholdSupervisor<Seed = group::Signature, Index = View, Share = group::Share>,
83    > Config<C, D, A, R, F, S>
84{
85    /// Assert enforces that all configuration values are valid.
86    pub fn assert(&self) {
87        assert!(
88            self.leader_timeout > Duration::default(),
89            "leader timeout must be greater than zero"
90        );
91        assert!(
92            self.notarization_timeout > Duration::default(),
93            "notarization timeout must be greater than zero"
94        );
95        assert!(
96            self.leader_timeout <= self.notarization_timeout,
97            "leader timeout must be less than or equal to notarization timeout"
98        );
99        assert!(
100            self.nullify_retry > Duration::default(),
101            "nullify retry broadcast must be greater than zero"
102        );
103        assert!(
104            self.activity_timeout > 0,
105            "activity timeout must be greater than zero"
106        );
107        assert!(
108            self.fetch_timeout > Duration::default(),
109            "fetch timeout must be greater than zero"
110        );
111        assert!(
112            self.max_fetch_count > 0,
113            "it must be possible to fetch at least one container per request"
114        );
115        assert!(
116            self.max_fetch_size > 0,
117            "it must be possible to fetch at least one byte"
118        );
119        assert!(
120            self.fetch_concurrent > 0,
121            "it must be possible to fetch from at least one peer at a time"
122        );
123        assert!(
124            self.replay_concurrency > 0,
125            "it must be possible to replay at least one view at a time"
126        );
127    }
128}