Skip to main content

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 interval to export neighbours metrics.
38    ///
39    /// Default: 5 seconds.
40    #[serde(with = "serde_helpers::humantime")]
41    pub update_metrics_interval: Duration,
42
43    /// The maximum number of neighbours to keep.
44    ///
45    /// Default: 5.
46    pub keep: usize,
47
48    /// The maximum number of ping tasks to run concurrently.
49    ///
50    /// Default: 5.
51    pub max_ping_tasks: usize,
52
53    /// The default roundtrip time to use when a neighbour is added.
54    ///
55    /// Default: 300 ms.
56    #[serde(with = "serde_helpers::humantime")]
57    pub default_roundtrip: Duration,
58
59    /// Send timeout (unidirectional).
60    ///
61    /// Default: 500ms.
62    #[serde(with = "serde_helpers::humantime")]
63    pub send_timeout: Duration,
64
65    /// Query timeout (bidirectional).
66    ///
67    /// Default: 1s.
68    #[serde(with = "serde_helpers::humantime")]
69    pub query_timeout: Duration,
70
71    /// Whether to enable `Neighbours` metrics.
72    ///
73    /// Default: `true`.
74    pub enable_metrics: bool,
75}
76
77impl Default for NeighborsConfig {
78    fn default() -> Self {
79        Self {
80            update_interval: Duration::from_secs(2 * 60),
81            ping_interval: Duration::from_secs(30),
82            apply_score_interval: Duration::from_secs(10),
83            update_metrics_interval: Duration::from_secs(5),
84            keep: 5,
85            max_ping_tasks: 5,
86            default_roundtrip: Duration::from_millis(300),
87            send_timeout: Duration::from_millis(500),
88            query_timeout: Duration::from_secs(1),
89            enable_metrics: true,
90        }
91    }
92}
93
94#[derive(Debug, Clone, Serialize, Deserialize)]
95#[serde(default)]
96pub struct ValidatorsConfig {
97    /// The interval at which target validators are pinged.
98    ///
99    /// Default: 60 seconds.
100    #[serde(with = "serde_helpers::humantime")]
101    pub ping_interval: Duration,
102
103    /// The timeout for a ping.
104    ///
105    /// Default: 1 seconds.
106    #[serde(with = "serde_helpers::humantime")]
107    pub ping_timeout: Duration,
108
109    /// The maximum number of validators to keep.
110    ///
111    /// Default: 5.
112    pub keep: usize,
113
114    /// The maximum number of ping tasks to run concurrently.
115    ///
116    /// Default: 5.
117    pub max_ping_tasks: usize,
118
119    /// Send timeout (unidirectional).
120    ///
121    /// Default: 500ms.
122    #[serde(with = "serde_helpers::humantime")]
123    pub send_timeout: Duration,
124}
125
126impl Default for ValidatorsConfig {
127    fn default() -> Self {
128        Self {
129            ping_interval: Duration::from_secs(60),
130            ping_timeout: Duration::from_secs(1),
131            keep: 5,
132            max_ping_tasks: 5,
133            send_timeout: Duration::from_millis(500),
134        }
135    }
136}