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 mailbox_size: usize,
55
56 pub namespace: Vec<u8>,
58
59 pub replay_buffer: NonZeroUsize,
61
62 pub write_buffer: NonZeroUsize,
64
65 pub buffer_pool: PoolRef,
67
68 pub leader_timeout: Duration,
71
72 pub notarization_timeout: Duration,
75
76 pub nullify_retry: Duration,
79
80 pub activity_timeout: View,
83
84 pub skip_timeout: View,
90
91 pub fetch_timeout: Duration,
93
94 pub max_fetch_count: usize,
96
97 pub fetch_rate_per_peer: Quota,
101
102 pub fetch_concurrent: usize,
104}
105
106impl<
107 C: Signer,
108 B: Blocker<PublicKey = C::PublicKey>,
109 V: Variant,
110 D: Digest,
111 A: Automaton<Context = Context<D>>,
112 R: Relay,
113 F: Reporter<Activity = Activity<V, D>>,
114 S: ThresholdSupervisor<
115 Seed = V::Signature,
116 Index = View,
117 Share = group::Share,
118 Identity = V::Public,
119 PublicKey = C::PublicKey,
120 >,
121 > Config<C, B, V, D, A, R, F, S>
122{
123 pub fn assert(&self) {
125 assert!(
126 self.leader_timeout > Duration::default(),
127 "leader timeout must be greater than zero"
128 );
129 assert!(
130 self.notarization_timeout > Duration::default(),
131 "notarization timeout must be greater than zero"
132 );
133 assert!(
134 self.leader_timeout <= self.notarization_timeout,
135 "leader timeout must be less than or equal to notarization timeout"
136 );
137 assert!(
138 self.nullify_retry > Duration::default(),
139 "nullify retry broadcast must be greater than zero"
140 );
141 assert!(
142 self.activity_timeout > 0,
143 "activity timeout must be greater than zero"
144 );
145 assert!(
146 self.skip_timeout > 0,
147 "skip timeout must be greater than zero"
148 );
149 assert!(
150 self.skip_timeout <= self.activity_timeout,
151 "skip timeout must be less than or equal to activity timeout"
152 );
153 assert!(
154 self.fetch_timeout > Duration::default(),
155 "fetch timeout must be greater than zero"
156 );
157 assert!(
158 self.max_fetch_count > 0,
159 "it must be possible to fetch at least one container per request"
160 );
161 assert!(
162 self.fetch_concurrent > 0,
163 "it must be possible to fetch from at least one peer at a time"
164 );
165 }
166}