tycho_core/overlay_client/
config.rs

1use std::time::Duration;
2
3use serde::{Deserialize, Serialize};
4use tycho_util::serde_helpers;
5
6#[derive(Default, Debug, Clone, Serialize, Deserialize)]
7#[serde(default)]
8#[non_exhaustive]
9pub struct PublicOverlayClientConfig {
10    /// Ordinary peers used to download blocks and other stuff.
11    pub neighbors: NeighborsConfig,
12    /// Validators as broadcast targets.
13    pub validators: ValidatorsConfig,
14}
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
17#[serde(default)]
18pub struct NeighborsConfig {
19    /// The interval at which neighbours list is updated.
20    ///
21    /// Default: 2 minutes.
22    #[serde(with = "serde_helpers::humantime")]
23    pub update_interval: Duration,
24
25    /// The interval at which current neighbours are pinged.
26    ///
27    /// Default: 30 seconds.
28    #[serde(with = "serde_helpers::humantime")]
29    pub ping_interval: Duration,
30
31    /// The interval at which neighbours score is applied to selection index.
32    ///
33    /// Default: 10 seconds.
34    #[serde(with = "serde_helpers::humantime")]
35    pub apply_score_interval: Duration,
36
37    /// The maximum number of neighbours to keep.
38    ///
39    /// Default: 5.
40    pub keep: usize,
41
42    /// The maximum number of ping tasks to run concurrently.
43    ///
44    /// Default: 5.
45    pub max_ping_tasks: usize,
46
47    /// The default roundtrip time to use when a neighbour is added.
48    ///
49    /// Default: 300 ms.
50    #[serde(with = "serde_helpers::humantime")]
51    pub default_roundtrip: Duration,
52
53    /// Send timeout (unidirectional).
54    ///
55    /// Default: 500ms.
56    #[serde(with = "serde_helpers::humantime")]
57    pub send_timeout: Duration,
58
59    /// Query timeout (bidirectional).
60    ///
61    /// Default: 1s.
62    #[serde(with = "serde_helpers::humantime")]
63    pub query_timeout: Duration,
64}
65
66impl Default for NeighborsConfig {
67    fn default() -> Self {
68        Self {
69            update_interval: Duration::from_secs(2 * 60),
70            ping_interval: Duration::from_secs(30),
71            apply_score_interval: Duration::from_secs(10),
72            keep: 5,
73            max_ping_tasks: 5,
74            default_roundtrip: Duration::from_millis(300),
75            send_timeout: Duration::from_millis(500),
76            query_timeout: Duration::from_secs(1),
77        }
78    }
79}
80
81#[derive(Debug, Clone, Serialize, Deserialize)]
82#[serde(default)]
83pub struct ValidatorsConfig {
84    /// The interval at which target validators are pinged.
85    ///
86    /// Default: 60 seconds.
87    #[serde(with = "serde_helpers::humantime")]
88    pub ping_interval: Duration,
89
90    /// The timeout for a ping.
91    ///
92    /// Default: 1 seconds.
93    #[serde(with = "serde_helpers::humantime")]
94    pub ping_timeout: Duration,
95
96    /// The maximum number of validators to keep.
97    ///
98    /// Default: 5.
99    pub keep: usize,
100
101    /// The maximum number of ping tasks to run concurrently.
102    ///
103    /// Default: 5.
104    pub max_ping_tasks: usize,
105
106    /// Send timeout (unidirectional).
107    ///
108    /// Default: 500ms.
109    #[serde(with = "serde_helpers::humantime")]
110    pub send_timeout: Duration,
111}
112
113impl Default for ValidatorsConfig {
114    fn default() -> Self {
115        Self {
116            ping_interval: Duration::from_secs(60),
117            ping_timeout: Duration::from_secs(1),
118            keep: 5,
119            max_ping_tasks: 5,
120            send_timeout: Duration::from_millis(500),
121        }
122    }
123}