@@ -4,7 +4,6 @@ use crate::{
4
4
util:: ApiUrl ,
5
5
Address , BigNum , ChainOf , ValidatorId ,
6
6
} ;
7
- use duration:: { milliseconds_to_std_duration, std_duration_to_milliseconds} ;
8
7
use once_cell:: sync:: Lazy ;
9
8
use serde:: { Deserialize , Serialize } ;
10
9
use std:: { collections:: HashMap , num:: NonZeroU8 , time:: Duration } ;
@@ -78,10 +77,7 @@ pub struct Config {
78
77
/// finish before running a new tick in the Validator Worker.
79
78
///
80
79
/// In milliseconds
81
- #[ serde(
82
- deserialize_with = "milliseconds_to_std_duration" ,
83
- serialize_with = "std_duration_to_milliseconds"
84
- ) ]
80
+ #[ serde( with = "std_duration_millis" ) ]
85
81
pub wait_time : Duration ,
86
82
/// The maximum allowed limit of [`ValidatorMessage`](crate::sentry::ValidatorMessage)s per page
87
83
/// returned by Sentry's GET `/v5/channel/0xXXX.../validator-messages` route.
@@ -112,18 +108,12 @@ pub struct Config {
112
108
/// - GET `/v5/analytics/for-admin`
113
109
///
114
110
/// In milliseconds
115
- #[ serde(
116
- deserialize_with = "milliseconds_to_std_duration" ,
117
- serialize_with = "std_duration_to_milliseconds"
118
- ) ]
111
+ #[ serde( with = "std_duration_millis" ) ]
119
112
pub analytics_maxtime : Duration ,
120
113
/// The amount of time that should have passed before sending a new heartbeat.
121
114
///
122
115
/// In milliseconds
123
- #[ serde(
124
- deserialize_with = "milliseconds_to_std_duration" ,
125
- serialize_with = "std_duration_to_milliseconds"
126
- ) ]
116
+ #[ serde( with = "std_duration_millis" ) ]
127
117
pub heartbeat_time : Duration ,
128
118
/// The pro miles below which the [`ApproveState`](crate::validator::ApproveState)
129
119
/// becomes **unhealthy** in the [`Channel`](crate::Channel)'s Follower.
@@ -142,10 +132,7 @@ pub struct Config {
142
132
/// to a validator.
143
133
///
144
134
/// In milliseconds
145
- #[ serde(
146
- deserialize_with = "milliseconds_to_std_duration" ,
147
- serialize_with = "std_duration_to_milliseconds"
148
- ) ]
135
+ #[ serde( with = "std_duration_millis" ) ]
149
136
pub propagation_timeout : Duration ,
150
137
/// The Client timeout for `SentryApi`.
151
138
///
@@ -155,29 +142,20 @@ pub struct Config {
155
142
/// [`Config.propagation_timeout`](Config::propagation_timeout).
156
143
///
157
144
/// In milliseconds
158
- #[ serde(
159
- deserialize_with = "milliseconds_to_std_duration" ,
160
- serialize_with = "std_duration_to_milliseconds"
161
- ) ]
145
+ #[ serde( with = "std_duration_millis" ) ]
162
146
pub fetch_timeout : Duration ,
163
147
/// The Client timeout for `SentryApi` when collecting all channels
164
148
/// and Validators using the `/campaign/list` route.
165
149
///
166
150
/// In milliseconds
167
- #[ serde(
168
- deserialize_with = "milliseconds_to_std_duration" ,
169
- serialize_with = "std_duration_to_milliseconds"
170
- ) ]
151
+ #[ serde( with = "std_duration_millis" ) ]
171
152
pub all_campaigns_timeout : Duration ,
172
153
/// The timeout for a single tick of a [`Channel`](crate::Channel) in
173
154
/// the Validator Worker.
174
155
/// This timeout is applied to both the leader and follower ticks.
175
156
///
176
157
/// In milliseconds
177
- #[ serde(
178
- deserialize_with = "milliseconds_to_std_duration" ,
179
- serialize_with = "std_duration_to_milliseconds"
180
- ) ]
158
+ #[ serde( with = "std_duration_millis" ) ]
181
159
pub channel_tick_timeout : Duration ,
182
160
/// The default IP rate limit that will be imposed if
183
161
/// [`Campaign.event_submission`](crate::Campaign::event_submission) is [`None`].
@@ -236,10 +214,7 @@ impl Config {
236
214
#[ derive( Serialize , Deserialize , Debug , Clone ) ]
237
215
pub struct PlatformConfig {
238
216
pub url : ApiUrl ,
239
- #[ serde(
240
- deserialize_with = "milliseconds_to_std_duration" ,
241
- serialize_with = "std_duration_to_milliseconds"
242
- ) ]
217
+ #[ serde( with = "std_duration_millis" ) ]
243
218
pub keep_alive_interval : Duration ,
244
219
}
245
220
@@ -277,11 +252,13 @@ pub struct Limits {
277
252
pub units_for_slot : limits:: UnitsForSlot ,
278
253
}
279
254
280
- pub mod duration {
255
+ /// Module for [`Config`] (de)serialization of [`std::time::Duration`] from
256
+ /// and to milliseconds.
257
+ pub mod std_duration_millis {
281
258
use serde:: { Deserialize , Deserializer , Serializer } ;
282
259
use std:: time:: Duration ;
283
260
284
- pub fn milliseconds_to_std_duration < ' de , D > ( deserializer : D ) -> Result < Duration , D :: Error >
261
+ pub fn deserialize < ' de , D > ( deserializer : D ) -> Result < Duration , D :: Error >
285
262
where
286
263
D : Deserializer < ' de > ,
287
264
{
@@ -298,10 +275,7 @@ pub mod duration {
298
275
Ok ( Duration :: from_millis ( milliseconds) )
299
276
}
300
277
301
- pub fn std_duration_to_milliseconds < S > (
302
- duration : & Duration ,
303
- serializer : S ,
304
- ) -> Result < S :: Ok , S :: Error >
278
+ pub fn serialize < S > ( duration : & Duration , serializer : S ) -> Result < S :: Ok , S :: Error >
305
279
where
306
280
S : Serializer ,
307
281
{
0 commit comments