commonware_consensus/threshold_simplex/
config.rs1use super::types::{Activity, Context, View};
2use crate::{Automaton, Relay, Reporter, ThresholdSupervisor};
3use commonware_cryptography::{
4 bls12381::primitives::{group, variant::Variant},
5 Digest, Signer,
6};
7use commonware_p2p::Blocker;
8use commonware_runtime::buffer::PoolRef;
9use governor::Quota;
10use std::{num::NonZeroUsize, time::Duration};
11
12pub struct Config<
14 C: Signer,
15 B: Blocker<PublicKey = C::PublicKey>,
16 V: Variant,
17 D: Digest,
18 A: Automaton<Context = Context<D>>,
19 R: Relay,
20 F: Reporter<Activity = Activity<V, D>>,
21 S: ThresholdSupervisor<
22 Index = View,
23 Identity = V::Public,
24 Seed = V::Signature,
25 PublicKey = C::PublicKey,
26 Share = group::Share,
27 >,
28> {
29 pub crypto: C,
31
32 pub blocker: B,
36
37 pub automaton: A,
39
40 pub relay: R,
42
43 pub reporter: F,
45
46 pub supervisor: S,
48
49 pub partition: String,
51
52 pub compression: Option<u8>,
54
55 pub mailbox_size: usize,
58
59 pub namespace: Vec<u8>,
61
62 pub replay_buffer: NonZeroUsize,
64
65 pub write_buffer: NonZeroUsize,
67
68 pub buffer_pool: PoolRef,
70
71 pub leader_timeout: Duration,
74
75 pub notarization_timeout: Duration,
78
79 pub nullify_retry: Duration,
82
83 pub activity_timeout: View,
86
87 pub skip_timeout: View,
93
94 pub fetch_timeout: Duration,
96
97 pub max_fetch_count: usize,
99
100 pub fetch_rate_per_peer: Quota,
104
105 pub fetch_concurrent: usize,
107}
108
109impl<
110 C: Signer,
111 B: Blocker<PublicKey = C::PublicKey>,
112 V: Variant,
113 D: Digest,
114 A: Automaton<Context = Context<D>>,
115 R: Relay,
116 F: Reporter<Activity = Activity<V, D>>,
117 S: ThresholdSupervisor<
118 Seed = V::Signature,
119 Index = View,
120 Share = group::Share,
121 Identity = V::Public,
122 PublicKey = C::PublicKey,
123 >,
124 > Config<C, B, V, D, A, R, F, S>
125{
126 pub fn assert(&self) {
128 assert!(
129 self.leader_timeout > Duration::default(),
130 "leader timeout must be greater than zero"
131 );
132 assert!(
133 self.notarization_timeout > Duration::default(),
134 "notarization timeout must be greater than zero"
135 );
136 assert!(
137 self.leader_timeout <= self.notarization_timeout,
138 "leader timeout must be less than or equal to notarization timeout"
139 );
140 assert!(
141 self.nullify_retry > Duration::default(),
142 "nullify retry broadcast must be greater than zero"
143 );
144 assert!(
145 self.activity_timeout > 0,
146 "activity timeout must be greater than zero"
147 );
148 assert!(
149 self.skip_timeout > 0,
150 "skip timeout must be greater than zero"
151 );
152 assert!(
153 self.skip_timeout <= self.activity_timeout,
154 "skip timeout must be less than or equal to activity timeout"
155 );
156 assert!(
157 self.fetch_timeout > Duration::default(),
158 "fetch timeout must be greater than zero"
159 );
160 assert!(
161 self.max_fetch_count > 0,
162 "it must be possible to fetch at least one container per request"
163 );
164 assert!(
165 self.fetch_concurrent > 0,
166 "it must be possible to fetch from at least one peer at a time"
167 );
168 }
169}