sui_config/
p2p.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use std::{net::SocketAddr, num::NonZeroU32, time::Duration};
5
6use serde::{Deserialize, Serialize};
7use sui_types::{
8    messages_checkpoint::{CheckpointDigest, CheckpointSequenceNumber},
9    multiaddr::Multiaddr,
10};
11
12#[derive(Clone, Debug, Deserialize, Serialize)]
13#[serde(rename_all = "kebab-case")]
14pub struct P2pConfig {
15    /// The address that the p2p network will bind on.
16    #[serde(default = "default_listen_address")]
17    pub listen_address: SocketAddr,
18    /// The external address other nodes can use to reach this node.
19    /// This will be shared with other peers through the discovery service
20    #[serde(skip_serializing_if = "Option::is_none")]
21    pub external_address: Option<Multiaddr>,
22    /// SeedPeers are preferred and the node will always try to ensure a
23    /// connection is established with these nodes.
24    #[serde(skip_serializing_if = "Vec::is_empty", default)]
25    pub seed_peers: Vec<SeedPeer>,
26    /// Manually configured peer addresses. These override addresses loaded from on-chain configs.
27    #[serde(skip_serializing_if = "Vec::is_empty", default)]
28    pub peer_address_overrides: Vec<PeerAddresses>,
29    #[serde(skip_serializing_if = "Option::is_none")]
30    pub anemo_config: Option<anemo::Config>,
31    #[serde(skip_serializing_if = "Option::is_none")]
32    pub state_sync: Option<StateSyncConfig>,
33    #[serde(skip_serializing_if = "Option::is_none")]
34    pub discovery: Option<DiscoveryConfig>,
35    #[serde(skip_serializing_if = "Option::is_none")]
36    pub randomness: Option<RandomnessConfig>,
37    /// Size in bytes above which network messages are considered excessively large. Excessively
38    /// large messages will still be handled, but logged and reported in metrics for debugging.
39    ///
40    /// If unspecified, this will default to 8 MiB.
41    #[serde(skip_serializing_if = "Option::is_none")]
42    pub excessive_message_size: Option<usize>,
43}
44
45fn default_listen_address() -> SocketAddr {
46    "0.0.0.0:8084".parse().unwrap()
47}
48
49impl Default for P2pConfig {
50    fn default() -> Self {
51        Self {
52            listen_address: default_listen_address(),
53            external_address: Default::default(),
54            seed_peers: Default::default(),
55            peer_address_overrides: Default::default(),
56            anemo_config: Default::default(),
57            state_sync: None,
58            discovery: None,
59            randomness: None,
60            excessive_message_size: None,
61        }
62    }
63}
64
65impl P2pConfig {
66    pub fn excessive_message_size(&self) -> usize {
67        const EXCESSIVE_MESSAGE_SIZE: usize = 32 << 20;
68
69        self.excessive_message_size
70            .unwrap_or(EXCESSIVE_MESSAGE_SIZE)
71    }
72
73    pub fn set_discovery_config(mut self, discovery_config: DiscoveryConfig) -> Self {
74        self.discovery = Some(discovery_config);
75        self
76    }
77}
78
79#[derive(Clone, Debug, Deserialize, Serialize)]
80#[serde(rename_all = "kebab-case")]
81pub struct SeedPeer {
82    #[serde(skip_serializing_if = "Option::is_none")]
83    pub peer_id: Option<anemo::PeerId>,
84    pub address: Multiaddr,
85}
86
87#[derive(Clone, Debug, Deserialize, Serialize)]
88#[serde(rename_all = "kebab-case")]
89pub struct AllowlistedPeer {
90    pub peer_id: anemo::PeerId,
91    #[serde(skip_serializing_if = "Option::is_none")]
92    pub address: Option<Multiaddr>,
93}
94
95#[derive(Clone, Debug, Deserialize, Serialize)]
96#[serde(rename_all = "kebab-case")]
97pub struct PeerAddresses {
98    pub peer_id: anemo::PeerId,
99    pub addresses: Vec<Multiaddr>,
100}
101
102#[derive(Clone, Debug, Default, Deserialize, Serialize)]
103#[serde(rename_all = "kebab-case")]
104pub struct StateSyncConfig {
105    /// List of "known-good" checkpoints that state sync will be forced to use. State sync will
106    /// skip verification of pinned checkpoints, and reject checkpoints with digests that don't
107    /// match pinned values for a given sequence number.
108    ///
109    /// This can be used:
110    /// - in case of a fork, to prevent the node from syncing to the wrong chain.
111    /// - in case of a network stall, to force the node to proceed with a manually-injected
112    ///   checkpoint.
113    #[serde(skip_serializing_if = "Vec::is_empty", default)]
114    pub pinned_checkpoints: Vec<(CheckpointSequenceNumber, CheckpointDigest)>,
115
116    /// Query peers for their latest checkpoint every interval period.
117    ///
118    /// If unspecified, this will default to `5,000` milliseconds.
119    #[serde(skip_serializing_if = "Option::is_none")]
120    pub interval_period_ms: Option<u64>,
121
122    /// Size of the StateSync actor's mailbox.
123    ///
124    /// If unspecified, this will default to `1,024`.
125    #[serde(skip_serializing_if = "Option::is_none")]
126    pub mailbox_capacity: Option<usize>,
127
128    /// Size of the broadcast channel use for notifying other systems of newly sync'ed checkpoints.
129    ///
130    /// If unspecified, this will default to `1,024`.
131    #[serde(skip_serializing_if = "Option::is_none")]
132    pub synced_checkpoint_broadcast_channel_capacity: Option<usize>,
133
134    /// Set the upper bound on the number of checkpoint headers to be downloaded concurrently.
135    ///
136    /// If unspecified, this will default to `400`.
137    #[serde(skip_serializing_if = "Option::is_none")]
138    pub checkpoint_header_download_concurrency: Option<usize>,
139
140    /// Set the upper bound on the number of checkpoint contents to be downloaded concurrently.
141    ///
142    /// If unspecified, this will default to `400`.
143    #[serde(skip_serializing_if = "Option::is_none")]
144    pub checkpoint_content_download_concurrency: Option<usize>,
145
146    /// Set the upper bound on the number of individual transactions contained in checkpoint
147    /// contents to be downloaded concurrently. If both this value and
148    /// `checkpoint_content_download_concurrency` are set, the lower of the two will apply.
149    ///
150    /// If unspecified, this will default to `50,000`.
151    #[serde(skip_serializing_if = "Option::is_none")]
152    pub checkpoint_content_download_tx_concurrency: Option<u64>,
153
154    /// Set the timeout that should be used when sending most state-sync RPC requests.
155    ///
156    /// If unspecified, this will default to `10,000` milliseconds.
157    #[serde(skip_serializing_if = "Option::is_none")]
158    pub timeout_ms: Option<u64>,
159
160    /// Set the timeout that should be used when sending RPC requests to sync checkpoint contents.
161    ///
162    /// If unspecified, this will default to `10,000` milliseconds.
163    #[serde(skip_serializing_if = "Option::is_none")]
164    pub checkpoint_content_timeout_ms: Option<u64>,
165
166    /// Per-peer rate-limit (in requests/sec) for the PushCheckpointSummary RPC.
167    ///
168    /// If unspecified, this will default to no limit.
169    #[serde(skip_serializing_if = "Option::is_none")]
170    pub push_checkpoint_summary_rate_limit: Option<NonZeroU32>,
171
172    /// Per-peer rate-limit (in requests/sec) for the GetCheckpointSummary RPC.
173    ///
174    /// If unspecified, this will default to no limit.
175    #[serde(skip_serializing_if = "Option::is_none")]
176    pub get_checkpoint_summary_rate_limit: Option<NonZeroU32>,
177
178    /// Per-peer rate-limit (in requests/sec) for the GetCheckpointContents RPC.
179    ///
180    /// If unspecified, this will default to no limit.
181    #[serde(skip_serializing_if = "Option::is_none")]
182    pub get_checkpoint_contents_rate_limit: Option<NonZeroU32>,
183
184    /// Per-peer inflight limit for the GetCheckpointContents RPC.
185    ///
186    /// If unspecified, this will default to no limit.
187    #[serde(skip_serializing_if = "Option::is_none")]
188    pub get_checkpoint_contents_inflight_limit: Option<usize>,
189
190    /// Per-checkpoint inflight limit for the GetCheckpointContents RPC. This is enforced globally
191    /// across all peers.
192    ///
193    /// If unspecified, this will default to no limit.
194    #[serde(skip_serializing_if = "Option::is_none")]
195    pub get_checkpoint_contents_per_checkpoint_limit: Option<usize>,
196
197    /// The amount of time to wait before retry if there are no peers to sync content from.
198    /// If unspecified, this will set to default value
199    #[serde(skip_serializing_if = "Option::is_none")]
200    pub wait_interval_when_no_peer_to_sync_content_ms: Option<u64>,
201
202    /// If true, the v2 version of get_checkpoint_contents will be used.
203    ///
204    /// If unspecified, this will default to true.
205    #[serde(skip_serializing_if = "Option::is_none")]
206    pub use_get_checkpoint_contents_v2: Option<bool>,
207
208    /// Maximum lookahead (in checkpoint sequence numbers) for storing unverified checkpoint
209    /// summaries received via PushCheckpointSummary.
210    ///
211    /// If unspecified, this will default to `1,000`.
212    #[serde(skip_serializing_if = "Option::is_none")]
213    pub max_checkpoint_lookahead: Option<u64>,
214
215    /// Maximum number of checkpoint headers to attempt to sync in a single sync task.
216    ///
217    /// If unspecified, this will default to `400`.
218    #[serde(skip_serializing_if = "Option::is_none")]
219    pub max_checkpoint_sync_batch_size: Option<u64>,
220
221    /// Maximum serialized size in bytes for a CertifiedCheckpointSummary received via
222    /// PushCheckpointSummary.
223    ///
224    /// If unspecified, this will default to `262,144` (256 KiB).
225    #[serde(skip_serializing_if = "Option::is_none")]
226    pub max_checkpoint_summary_size: Option<usize>,
227
228    /// Minimum timeout for checkpoint content downloads (adaptive timeout lower bound).
229    ///
230    /// If unspecified, this will default to `10,000` milliseconds.
231    #[serde(skip_serializing_if = "Option::is_none")]
232    pub checkpoint_content_timeout_min_ms: Option<u64>,
233
234    /// Maximum timeout for checkpoint content downloads (adaptive timeout upper bound).
235    ///
236    /// If unspecified, this will default to `30,000` milliseconds.
237    #[serde(skip_serializing_if = "Option::is_none")]
238    pub checkpoint_content_timeout_max_ms: Option<u64>,
239
240    /// Time window for peer scoring samples.
241    ///
242    /// If unspecified, this will default to `60,000` milliseconds.
243    #[serde(skip_serializing_if = "Option::is_none")]
244    pub peer_scoring_window_ms: Option<u64>,
245
246    /// Probability of selecting an unknown peer to explore its throughput.
247    ///
248    /// If unspecified, this will default to `0.1`.
249    #[serde(skip_serializing_if = "Option::is_none")]
250    pub exploration_probability: Option<f64>,
251
252    /// Failure rate threshold for marking a peer as failing.
253    /// A peer is marked as failing if its failure rate exceeds this threshold.
254    ///
255    /// If unspecified, this will default to `0.3` (30%).
256    #[serde(skip_serializing_if = "Option::is_none")]
257    pub peer_failure_rate: Option<f64>,
258}
259
260impl StateSyncConfig {
261    pub fn interval_period(&self) -> Duration {
262        const INTERVAL_PERIOD_MS: u64 = 5_000; // 5 seconds
263
264        Duration::from_millis(self.interval_period_ms.unwrap_or(INTERVAL_PERIOD_MS))
265    }
266
267    pub fn mailbox_capacity(&self) -> usize {
268        const MAILBOX_CAPACITY: usize = 1_024;
269
270        self.mailbox_capacity.unwrap_or(MAILBOX_CAPACITY)
271    }
272
273    pub fn synced_checkpoint_broadcast_channel_capacity(&self) -> usize {
274        const SYNCED_CHECKPOINT_BROADCAST_CHANNEL_CAPACITY: usize = 1_024;
275
276        self.synced_checkpoint_broadcast_channel_capacity
277            .unwrap_or(SYNCED_CHECKPOINT_BROADCAST_CHANNEL_CAPACITY)
278    }
279
280    pub fn checkpoint_header_download_concurrency(&self) -> usize {
281        const CHECKPOINT_HEADER_DOWNLOAD_CONCURRENCY: usize = 400;
282
283        self.checkpoint_header_download_concurrency
284            .unwrap_or(CHECKPOINT_HEADER_DOWNLOAD_CONCURRENCY)
285    }
286
287    pub fn checkpoint_content_download_concurrency(&self) -> usize {
288        const CHECKPOINT_CONTENT_DOWNLOAD_CONCURRENCY: usize = 400;
289
290        self.checkpoint_content_download_concurrency
291            .unwrap_or(CHECKPOINT_CONTENT_DOWNLOAD_CONCURRENCY)
292    }
293
294    pub fn checkpoint_content_download_tx_concurrency(&self) -> u64 {
295        const CHECKPOINT_CONTENT_DOWNLOAD_TX_CONCURRENCY: u64 = 50_000;
296
297        self.checkpoint_content_download_tx_concurrency
298            .unwrap_or(CHECKPOINT_CONTENT_DOWNLOAD_TX_CONCURRENCY)
299    }
300
301    pub fn timeout(&self) -> Duration {
302        const DEFAULT_TIMEOUT: Duration = Duration::from_secs(10);
303
304        self.timeout_ms
305            .map(Duration::from_millis)
306            .unwrap_or(DEFAULT_TIMEOUT)
307    }
308
309    pub fn checkpoint_content_timeout(&self) -> Duration {
310        const DEFAULT_TIMEOUT: Duration = Duration::from_secs(60);
311
312        self.checkpoint_content_timeout_ms
313            .map(Duration::from_millis)
314            .unwrap_or(DEFAULT_TIMEOUT)
315    }
316
317    pub fn wait_interval_when_no_peer_to_sync_content(&self) -> Duration {
318        self.wait_interval_when_no_peer_to_sync_content_ms
319            .map(Duration::from_millis)
320            .unwrap_or(self.default_wait_interval_when_no_peer_to_sync_content())
321    }
322
323    fn default_wait_interval_when_no_peer_to_sync_content(&self) -> Duration {
324        if cfg!(msim) {
325            Duration::from_secs(5)
326        } else {
327            Duration::from_secs(10)
328        }
329    }
330
331    pub fn use_get_checkpoint_contents_v2(&self) -> bool {
332        const DEFAULT_USE_GET_CHECKPOINT_CONTENTS_V2: bool = true;
333
334        self.use_get_checkpoint_contents_v2
335            .unwrap_or(DEFAULT_USE_GET_CHECKPOINT_CONTENTS_V2)
336    }
337
338    pub fn max_checkpoint_lookahead(&self) -> u64 {
339        const DEFAULT_MAX_CHECKPOINT_LOOKAHEAD: u64 = 1_000;
340
341        self.max_checkpoint_lookahead
342            .unwrap_or(DEFAULT_MAX_CHECKPOINT_LOOKAHEAD)
343    }
344
345    pub fn max_checkpoint_sync_batch_size(&self) -> u64 {
346        const DEFAULT_MAX_CHECKPOINT_SYNC_BATCH_SIZE: u64 = 400;
347
348        self.max_checkpoint_sync_batch_size
349            .unwrap_or(DEFAULT_MAX_CHECKPOINT_SYNC_BATCH_SIZE)
350    }
351
352    pub fn max_checkpoint_summary_size(&self) -> usize {
353        const DEFAULT_MAX_CHECKPOINT_SUMMARY_SIZE: usize = 256 * 1024; // 256 KiB
354
355        self.max_checkpoint_summary_size
356            .unwrap_or(DEFAULT_MAX_CHECKPOINT_SUMMARY_SIZE)
357    }
358
359    pub fn checkpoint_content_timeout_min(&self) -> Duration {
360        const DEFAULT: Duration = Duration::from_secs(5);
361        self.checkpoint_content_timeout_min_ms
362            .map(Duration::from_millis)
363            .unwrap_or(DEFAULT)
364    }
365
366    pub fn checkpoint_content_timeout_max(&self) -> Duration {
367        const DEFAULT: Duration = Duration::from_secs(30);
368        self.checkpoint_content_timeout_max_ms
369            .map(Duration::from_millis)
370            .unwrap_or(DEFAULT)
371    }
372
373    pub fn peer_scoring_window(&self) -> Duration {
374        const DEFAULT: Duration = Duration::from_secs(60);
375        self.peer_scoring_window_ms
376            .map(Duration::from_millis)
377            .unwrap_or(DEFAULT)
378    }
379
380    pub fn exploration_probability(&self) -> f64 {
381        const DEFAULT: f64 = 0.1;
382        self.exploration_probability.unwrap_or(DEFAULT)
383    }
384
385    pub fn peer_failure_rate(&self) -> f64 {
386        const DEFAULT: f64 = 0.3;
387        self.peer_failure_rate.unwrap_or(DEFAULT)
388    }
389
390    pub fn randomized_for_testing() -> Self {
391        use rand::Rng;
392        let mut rng = rand::thread_rng();
393        let config = Self {
394            mailbox_capacity: Some(rng.gen_range(16..=2048)),
395            synced_checkpoint_broadcast_channel_capacity: Some(rng.gen_range(16..=2048)),
396            checkpoint_header_download_concurrency: Some(rng.gen_range(10..=500)),
397            checkpoint_content_download_concurrency: Some(rng.gen_range(10..=500)),
398            max_checkpoint_lookahead: Some(rng.gen_range(100..=2000)),
399            max_checkpoint_sync_batch_size: Some(rng.gen_range(100..=500)),
400            max_checkpoint_summary_size: Some(rng.gen_range(64 * 1024..=512 * 1024)),
401            ..Default::default()
402        };
403        tracing::info!(
404            mailbox_capacity = config.mailbox_capacity.unwrap(),
405            broadcast_capacity = config.synced_checkpoint_broadcast_channel_capacity.unwrap(),
406            header_concurrency = config.checkpoint_header_download_concurrency.unwrap(),
407            content_concurrency = config.checkpoint_content_download_concurrency.unwrap(),
408            lookahead = config.max_checkpoint_lookahead.unwrap(),
409            batch_size = config.max_checkpoint_sync_batch_size.unwrap(),
410            summary_size = config.max_checkpoint_summary_size.unwrap(),
411            "StateSyncConfig::randomized_for_testing"
412        );
413        config
414    }
415}
416
417/// Access Type of a node.
418/// AccessType info is shared in the discovery process.
419/// * If the node marks itself as Public, other nodes may try to connect to it.
420/// * If the node marks itself as Private, only nodes that have it in
421///   their `allowlisted_peers` or `seed_peers` will try to connect to it. The
422///   node's info will not be shared through discovery.
423/// * Trusted is the same as Private, except it allows sharing the node's info
424///   only to other preconfigured peers (i.e. those in `allowlisted_peers` and
425///   `seed_peers`).
426/// * If not set, defaults to Public.
427///
428/// AccessType is useful when a network of nodes want to stay private. To achieve this,
429/// mark every node in this network as `Private` or `Trusted`, and allowlist/seed them
430/// to each other.
431#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
432pub enum AccessType {
433    Public,
434    Private,
435    Trusted,
436}
437
438#[derive(Clone, Debug, Default, Deserialize, Serialize)]
439#[serde(rename_all = "kebab-case")]
440pub struct DiscoveryConfig {
441    /// Query peers for their latest checkpoint every interval period.
442    ///
443    /// If unspecified, this will default to `5,000` milliseconds.
444    #[serde(skip_serializing_if = "Option::is_none")]
445    pub interval_period_ms: Option<u64>,
446
447    /// Target number of concurrent connections to establish.
448    ///
449    /// If unspecified, this will default to `4`.
450    #[serde(skip_serializing_if = "Option::is_none")]
451    pub target_concurrent_connections: Option<usize>,
452
453    /// Number of peers to query each interval.
454    ///
455    /// Sets the number of peers, to be randomly selected, that are queried for their known peers
456    /// each interval.
457    ///
458    /// If unspecified, this will default to `1`.
459    #[serde(skip_serializing_if = "Option::is_none")]
460    pub peers_to_query: Option<usize>,
461
462    /// Per-peer rate-limit (in requests/sec) for the GetKnownPeers RPC.
463    ///
464    /// If unspecified, this will default to no limit.
465    #[serde(skip_serializing_if = "Option::is_none")]
466    pub get_known_peers_rate_limit: Option<NonZeroU32>,
467
468    /// See docstring for `AccessType`.
469    #[serde(skip_serializing_if = "Option::is_none")]
470    pub access_type: Option<AccessType>,
471
472    /// Like `seed_peers` in `P2pConfig`, allowlisted peers will always be allowed to establish
473    /// connection with this node regardless of the concurrency limit.
474    /// Unlike `seed_peers`, a node does not reach out to `allowlisted_peers` preferentially.
475    /// It is also used to determine if a peer is accessible when its AccessType is Private.
476    /// For example, a node will ignore a peer with Private AccessType if the peer is not in
477    /// its `allowlisted_peers`. Namely, the node will not try to establish connections
478    /// to this peer, nor advertise this peer's info to other peers in the network.
479    #[serde(skip_serializing_if = "Vec::is_empty", default)]
480    pub allowlisted_peers: Vec<AllowlistedPeer>,
481
482    /// Size of the Discovery loop's mailbox.
483    ///
484    /// If unspecified, this will default to `1,024`.
485    #[serde(skip_serializing_if = "Option::is_none")]
486    pub mailbox_capacity: Option<usize>,
487
488    /// Use get_known_peers_v3 RPC to fetch peer info.
489    ///
490    /// If unspecified, this will default to `false`.
491    #[serde(skip_serializing_if = "Option::is_none")]
492    pub use_get_known_peers_v3: Option<bool>,
493}
494
495impl DiscoveryConfig {
496    pub fn interval_period(&self) -> Duration {
497        const INTERVAL_PERIOD_MS: u64 = 5_000; // 5 seconds
498
499        Duration::from_millis(self.interval_period_ms.unwrap_or(INTERVAL_PERIOD_MS))
500    }
501
502    pub fn target_concurrent_connections(&self) -> usize {
503        const TARGET_CONCURRENT_CONNECTIONS: usize = 4;
504
505        self.target_concurrent_connections
506            .unwrap_or(TARGET_CONCURRENT_CONNECTIONS)
507    }
508
509    pub fn peers_to_query(&self) -> usize {
510        const PEERS_TO_QUERY: usize = 1;
511
512        self.peers_to_query.unwrap_or(PEERS_TO_QUERY)
513    }
514
515    pub fn access_type(&self) -> AccessType {
516        // defaults None to Public
517        self.access_type.unwrap_or(AccessType::Public)
518    }
519
520    pub fn mailbox_capacity(&self) -> usize {
521        const MAILBOX_CAPACITY: usize = 1_024;
522
523        self.mailbox_capacity.unwrap_or(MAILBOX_CAPACITY)
524    }
525
526    pub fn use_get_known_peers_v3(&self) -> bool {
527        self.use_get_known_peers_v3.unwrap_or(false)
528    }
529}
530
531#[derive(Clone, Debug, Default, Deserialize, Serialize)]
532#[serde(rename_all = "kebab-case")]
533pub struct RandomnessConfig {
534    /// Maximum number of rounds ahead of our most recent completed round for which we should
535    /// accept partial signatures from other validators.
536    ///
537    /// If unspecified, this will default to 50.
538    #[serde(skip_serializing_if = "Option::is_none")]
539    pub max_partial_sigs_rounds_ahead: Option<u64>,
540
541    /// Maximum number of rounds for which partial signatures should be concurrently sent.
542    ///
543    /// If unspecified, this will default to 20.
544    #[serde(skip_serializing_if = "Option::is_none")]
545    pub max_partial_sigs_concurrent_sends: Option<usize>,
546
547    /// Interval at which to retry sending partial signatures until the round is complete.
548    ///
549    /// If unspecified, this will default to `5,000` milliseconds.
550    #[serde(skip_serializing_if = "Option::is_none")]
551    pub partial_signature_retry_interval_ms: Option<u64>,
552
553    /// Size of the Randomness actor's mailbox. This should be set large enough to never
554    /// overflow unless a bug is encountered.
555    ///
556    /// If unspecified, this will default to `1,000,000`.
557    #[serde(skip_serializing_if = "Option::is_none")]
558    pub mailbox_capacity: Option<usize>,
559
560    /// Per-peer inflight limit for the SendPartialSignatures RPC.
561    ///
562    /// If unspecified, this will default to 20.
563    #[serde(skip_serializing_if = "Option::is_none")]
564    pub send_partial_signatures_inflight_limit: Option<usize>,
565
566    /// Maximum proportion of total peer weight to ignore in case of byzantine behavior.
567    ///
568    /// If unspecified, this will default to 0.2.
569    #[serde(skip_serializing_if = "Option::is_none")]
570    pub max_ignored_peer_weight_factor: Option<f64>,
571}
572
573impl RandomnessConfig {
574    pub fn max_partial_sigs_rounds_ahead(&self) -> u64 {
575        const MAX_PARTIAL_SIGS_ROUNDS_AHEAD: u64 = 50;
576
577        self.max_partial_sigs_rounds_ahead
578            .unwrap_or(MAX_PARTIAL_SIGS_ROUNDS_AHEAD)
579    }
580
581    pub fn max_partial_sigs_concurrent_sends(&self) -> usize {
582        const MAX_PARTIAL_SIGS_CONCURRENT_SENDS: usize = 20;
583
584        self.max_partial_sigs_concurrent_sends
585            .unwrap_or(MAX_PARTIAL_SIGS_CONCURRENT_SENDS)
586    }
587    pub fn partial_signature_retry_interval(&self) -> Duration {
588        const PARTIAL_SIGNATURE_RETRY_INTERVAL: u64 = 5_000; // 5 seconds
589
590        Duration::from_millis(
591            self.partial_signature_retry_interval_ms
592                .unwrap_or(PARTIAL_SIGNATURE_RETRY_INTERVAL),
593        )
594    }
595
596    pub fn mailbox_capacity(&self) -> usize {
597        const MAILBOX_CAPACITY: usize = 1_000_000;
598
599        self.mailbox_capacity.unwrap_or(MAILBOX_CAPACITY)
600    }
601
602    pub fn send_partial_signatures_inflight_limit(&self) -> usize {
603        const SEND_PARTIAL_SIGNATURES_INFLIGHT_LIMIT: usize = 20;
604
605        self.send_partial_signatures_inflight_limit
606            .unwrap_or(SEND_PARTIAL_SIGNATURES_INFLIGHT_LIMIT)
607    }
608
609    pub fn max_ignored_peer_weight_factor(&self) -> f64 {
610        const MAX_IGNORED_PEER_WEIGHT_FACTOR: f64 = 0.2;
611
612        self.max_ignored_peer_weight_factor
613            .unwrap_or(MAX_IGNORED_PEER_WEIGHT_FACTOR)
614    }
615}