@@ -10,13 +10,14 @@ use crate::Config;
10
10
use anyhow:: Result ;
11
11
use consensus_config:: Parameters as ConsensusParameters ;
12
12
use mysten_common:: fatal;
13
+ use nonzero_ext:: nonzero;
13
14
use once_cell:: sync:: OnceCell ;
14
15
use rand:: rngs:: OsRng ;
15
16
use serde:: { Deserialize , Serialize } ;
16
17
use serde_with:: serde_as;
17
18
use std:: collections:: { BTreeMap , BTreeSet } ;
18
19
use std:: net:: SocketAddr ;
19
- use std:: num:: NonZeroUsize ;
20
+ use std:: num:: { NonZeroU32 , NonZeroUsize } ;
20
21
use std:: path:: { Path , PathBuf } ;
21
22
use std:: sync:: Arc ;
22
23
use std:: time:: Duration ;
@@ -33,7 +34,7 @@ use sui_types::traffic_control::{PolicyConfig, RemoteFirewallConfig};
33
34
34
35
use sui_types:: crypto:: { get_key_pair_from_rng, AccountKeyPair , AuthorityKeyPair } ;
35
36
use sui_types:: multiaddr:: Multiaddr ;
36
- use tracing:: { error , info} ;
37
+ use tracing:: info;
37
38
38
39
// Default max number of concurrent requests served
39
40
pub const DEFAULT_GRPC_CONCURRENCY_LIMIT : usize = 20000000000 ;
@@ -202,17 +203,95 @@ pub struct NodeConfig {
202
203
#[ serde( skip_serializing_if = "Option::is_none" ) ]
203
204
pub enable_db_write_stall : Option < bool > ,
204
205
206
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
207
+ pub execution_time_observer_config : Option < ExecutionTimeObserverConfig > ,
208
+ }
209
+
210
+ #[ derive( Clone , Debug , Default , Deserialize , Serialize ) ]
211
+ #[ serde( rename_all = "kebab-case" ) ]
212
+ pub struct ExecutionTimeObserverConfig {
205
213
/// Size of the channel used for buffering local execution time observations.
206
214
///
207
215
/// If unspecified, this will default to `128`.
208
- #[ serde( default = "default_local_execution_time_channel_capacity" ) ]
209
- pub local_execution_time_channel_capacity : usize ,
216
+ pub observation_channel_capacity : Option < NonZeroUsize > ,
210
217
211
218
/// Size of the LRU cache used for storing local execution time observations.
212
219
///
213
- /// If unspecified, this will default to `10000`.
214
- #[ serde( default = "default_local_execution_time_cache_size" ) ]
215
- pub local_execution_time_cache_size : usize ,
220
+ /// If unspecified, this will default to `10_000`.
221
+ pub observation_cache_size : Option < NonZeroUsize > ,
222
+
223
+ /// Size of the LRU cache used for tracking object utilization.
224
+ ///
225
+ /// If unspecified, this will default to `50_000`.
226
+ pub object_utilization_cache_size : Option < NonZeroUsize > ,
227
+
228
+ /// Unless target object utilization is exceeded by at least this amount, no observation
229
+ /// will be shared with consensus.
230
+ ///
231
+ /// If unspecified, this will default to `100` milliseconds.
232
+ pub observation_sharing_object_utilization_threshold : Option < Duration > ,
233
+
234
+ /// Unless the current local observation differs from the last one we shared by at least this
235
+ /// percentage, no observation will be shared with consensus.
236
+ ///
237
+ /// If unspecified, this will default to `0.05`.
238
+ pub observation_sharing_diff_threshold : Option < f64 > ,
239
+
240
+ /// Minimum interval between sharing multiple observations of the same key.
241
+ ///
242
+ /// If unspecified, this will default to `5` seconds.
243
+ pub observation_sharing_min_interval : Option < Duration > ,
244
+
245
+ /// Global per-second rate limit for sharing observations. This is a safety valve and
246
+ /// should not trigger during normal operation.
247
+ ///
248
+ /// If unspecified, this will default to `10` observations per second.
249
+ pub observation_sharing_rate_limit : Option < NonZeroU32 > ,
250
+
251
+ /// Global burst limit for sharing observations.
252
+ ///
253
+ /// If unspecified, this will default to `100` observations.
254
+ pub observation_sharing_burst_limit : Option < NonZeroU32 > ,
255
+ }
256
+
257
+ impl ExecutionTimeObserverConfig {
258
+ pub fn observation_channel_capacity ( & self ) -> NonZeroUsize {
259
+ self . observation_channel_capacity
260
+ . unwrap_or ( nonzero ! ( 128usize ) )
261
+ }
262
+
263
+ pub fn observation_cache_size ( & self ) -> NonZeroUsize {
264
+ self . observation_cache_size . unwrap_or ( nonzero ! ( 10_000usize ) )
265
+ }
266
+
267
+ pub fn object_utilization_cache_size ( & self ) -> NonZeroUsize {
268
+ self . object_utilization_cache_size
269
+ . unwrap_or ( nonzero ! ( 50_000usize ) )
270
+ }
271
+
272
+ pub fn observation_sharing_object_utilization_threshold ( & self ) -> Duration {
273
+ self . observation_sharing_object_utilization_threshold
274
+ . unwrap_or ( Duration :: from_millis ( 100 ) )
275
+ }
276
+
277
+ pub fn observation_sharing_diff_threshold ( & self ) -> f64 {
278
+ self . observation_sharing_diff_threshold . unwrap_or ( 0.05 )
279
+ }
280
+
281
+ pub fn observation_sharing_min_interval ( & self ) -> Duration {
282
+ self . observation_sharing_min_interval
283
+ . unwrap_or ( Duration :: from_secs ( 5 ) )
284
+ }
285
+
286
+ pub fn observation_sharing_rate_limit ( & self ) -> NonZeroU32 {
287
+ self . observation_sharing_rate_limit
288
+ . unwrap_or ( nonzero ! ( 10u32 ) )
289
+ }
290
+
291
+ pub fn observation_sharing_burst_limit ( & self ) -> NonZeroU32 {
292
+ self . observation_sharing_burst_limit
293
+ . unwrap_or ( nonzero ! ( 100u32 ) )
294
+ }
216
295
}
217
296
218
297
#[ derive( Clone , Debug , Deserialize , Serialize ) ]
@@ -552,14 +631,6 @@ pub fn default_end_of_epoch_broadcast_channel_capacity() -> usize {
552
631
128
553
632
}
554
633
555
- pub fn default_local_execution_time_channel_capacity ( ) -> usize {
556
- 128
557
- }
558
-
559
- pub fn default_local_execution_time_cache_size ( ) -> usize {
560
- 10000
561
- }
562
-
563
634
pub fn bool_true ( ) -> bool {
564
635
true
565
636
}
@@ -655,13 +726,6 @@ impl NodeConfig {
655
726
pub fn rpc ( & self ) -> Option < & sui_rpc_api:: Config > {
656
727
self . rpc . as_ref ( )
657
728
}
658
-
659
- pub fn local_execution_time_cache_size ( & self ) -> NonZeroUsize {
660
- NonZeroUsize :: new ( self . local_execution_time_cache_size ) . unwrap_or_else ( || {
661
- error ! ( "local_execution_time_cache_size must be non-zero - defaulting to 10000" ) ;
662
- NonZeroUsize :: new ( 10000 ) . unwrap ( )
663
- } )
664
- }
665
729
}
666
730
667
731
#[ derive( Debug , Clone , Deserialize , Serialize ) ]
0 commit comments