sui_config/
node.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3use crate::Config;
4use crate::certificate_deny_config::CertificateDenyConfig;
5use crate::genesis;
6use crate::object_storage_config::ObjectStoreConfig;
7use crate::p2p::P2pConfig;
8use crate::transaction_deny_config::TransactionDenyConfig;
9use crate::validator_client_monitor_config::ValidatorClientMonitorConfig;
10use crate::verifier_signing_config::VerifierSigningConfig;
11use anyhow::Result;
12use consensus_config::Parameters as ConsensusParameters;
13use mysten_common::fatal;
14use nonzero_ext::nonzero;
15use once_cell::sync::OnceCell;
16use rand::rngs::OsRng;
17use serde::{Deserialize, Serialize};
18use serde_with::serde_as;
19use std::collections::{BTreeMap, BTreeSet};
20use std::net::SocketAddr;
21use std::num::{NonZeroU32, NonZeroUsize};
22use std::path::{Path, PathBuf};
23use std::sync::Arc;
24use std::time::Duration;
25use sui_keys::keypair_file::{read_authority_keypair_from_file, read_keypair_from_file};
26use sui_types::base_types::{ObjectID, SuiAddress};
27use sui_types::committee::EpochId;
28use sui_types::crypto::AuthorityPublicKeyBytes;
29use sui_types::crypto::KeypairTraits;
30use sui_types::crypto::NetworkKeyPair;
31use sui_types::crypto::SuiKeyPair;
32use sui_types::messages_checkpoint::CheckpointSequenceNumber;
33use sui_types::supported_protocol_versions::{Chain, SupportedProtocolVersions};
34use sui_types::traffic_control::{PolicyConfig, RemoteFirewallConfig};
35
36use sui_types::crypto::{AccountKeyPair, AuthorityKeyPair, get_key_pair_from_rng};
37use sui_types::multiaddr::Multiaddr;
38use tracing::info;
39
40// Default max number of concurrent requests served
41pub const DEFAULT_GRPC_CONCURRENCY_LIMIT: usize = 20000000000;
42
43/// Default gas price of 100 Mist
44pub const DEFAULT_VALIDATOR_GAS_PRICE: u64 = sui_types::transaction::DEFAULT_VALIDATOR_GAS_PRICE;
45
46/// Default commission rate of 2%
47pub const DEFAULT_COMMISSION_RATE: u64 = 200;
48
49#[serde_as]
50#[derive(Clone, Debug, Deserialize, Serialize)]
51#[serde(rename_all = "kebab-case")]
52pub struct NodeConfig {
53    #[serde(default = "default_authority_key_pair")]
54    pub protocol_key_pair: AuthorityKeyPairWithPath,
55    #[serde(default = "default_key_pair")]
56    pub worker_key_pair: KeyPairWithPath,
57    #[serde(default = "default_key_pair")]
58    pub account_key_pair: KeyPairWithPath,
59    #[serde(default = "default_key_pair")]
60    pub network_key_pair: KeyPairWithPath,
61
62    pub db_path: PathBuf,
63    #[serde(default = "default_grpc_address")]
64    pub network_address: Multiaddr,
65    #[serde(default = "default_json_rpc_address")]
66    pub json_rpc_address: SocketAddr,
67
68    #[serde(skip_serializing_if = "Option::is_none")]
69    pub rpc: Option<crate::RpcConfig>,
70
71    #[serde(default = "default_metrics_address")]
72    pub metrics_address: SocketAddr,
73    #[serde(default = "default_admin_interface_port")]
74    pub admin_interface_port: u16,
75
76    #[serde(skip_serializing_if = "Option::is_none")]
77    pub consensus_config: Option<ConsensusConfig>,
78
79    #[serde(default = "default_enable_index_processing")]
80    pub enable_index_processing: bool,
81
82    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
83    pub remove_deprecated_tables: bool,
84
85    #[serde(default)]
86    /// Determines the jsonrpc server type as either:
87    /// - 'websocket' for a websocket based service (deprecated)
88    /// - 'http' for an http based service
89    /// - 'both' for both a websocket and http based service (deprecated)
90    pub jsonrpc_server_type: Option<ServerType>,
91
92    #[serde(default)]
93    pub grpc_load_shed: Option<bool>,
94
95    #[serde(default = "default_concurrency_limit")]
96    pub grpc_concurrency_limit: Option<usize>,
97
98    #[serde(default)]
99    pub p2p_config: P2pConfig,
100
101    pub genesis: Genesis,
102
103    #[serde(default = "default_authority_store_pruning_config")]
104    pub authority_store_pruning_config: AuthorityStorePruningConfig,
105
106    /// Size of the broadcast channel used for notifying other systems of end of epoch.
107    ///
108    /// If unspecified, this will default to `128`.
109    #[serde(default = "default_end_of_epoch_broadcast_channel_capacity")]
110    pub end_of_epoch_broadcast_channel_capacity: usize,
111
112    #[serde(default)]
113    pub checkpoint_executor_config: CheckpointExecutorConfig,
114
115    #[serde(skip_serializing_if = "Option::is_none")]
116    pub metrics: Option<MetricsConfig>,
117
118    /// In a `sui-node` binary, this is set to SupportedProtocolVersions::SYSTEM_DEFAULT
119    /// in sui-node/src/main.rs. It is present in the config so that it can be changed by tests in
120    /// order to test protocol upgrades.
121    #[serde(skip)]
122    pub supported_protocol_versions: Option<SupportedProtocolVersions>,
123
124    #[serde(default)]
125    pub db_checkpoint_config: DBCheckpointConfig,
126
127    #[serde(default)]
128    pub expensive_safety_check_config: ExpensiveSafetyCheckConfig,
129
130    #[serde(skip_serializing_if = "Option::is_none")]
131    pub name_service_package_address: Option<SuiAddress>,
132
133    #[serde(skip_serializing_if = "Option::is_none")]
134    pub name_service_registry_id: Option<ObjectID>,
135
136    #[serde(skip_serializing_if = "Option::is_none")]
137    pub name_service_reverse_registry_id: Option<ObjectID>,
138
139    #[serde(default)]
140    pub transaction_deny_config: TransactionDenyConfig,
141
142    #[serde(default)]
143    pub certificate_deny_config: CertificateDenyConfig,
144
145    #[serde(default)]
146    pub state_debug_dump_config: StateDebugDumpConfig,
147
148    #[serde(default)]
149    pub state_archive_read_config: Vec<StateArchiveConfig>,
150
151    #[serde(default)]
152    pub state_snapshot_write_config: StateSnapshotConfig,
153
154    #[serde(default)]
155    pub indexer_max_subscriptions: Option<usize>,
156
157    #[serde(default = "default_transaction_kv_store_config")]
158    pub transaction_kv_store_read_config: TransactionKeyValueStoreReadConfig,
159
160    #[serde(skip_serializing_if = "Option::is_none")]
161    pub transaction_kv_store_write_config: Option<TransactionKeyValueStoreWriteConfig>,
162
163    #[serde(default = "default_jwk_fetch_interval_seconds")]
164    pub jwk_fetch_interval_seconds: u64,
165
166    #[serde(default = "default_zklogin_oauth_providers")]
167    pub zklogin_oauth_providers: BTreeMap<Chain, BTreeSet<String>>,
168
169    #[serde(default = "default_authority_overload_config")]
170    pub authority_overload_config: AuthorityOverloadConfig,
171
172    #[serde(skip_serializing_if = "Option::is_none")]
173    pub run_with_range: Option<RunWithRange>,
174
175    // For killswitch use None
176    #[serde(
177        skip_serializing_if = "Option::is_none",
178        default = "default_traffic_controller_policy_config"
179    )]
180    pub policy_config: Option<PolicyConfig>,
181
182    #[serde(skip_serializing_if = "Option::is_none")]
183    pub firewall_config: Option<RemoteFirewallConfig>,
184
185    #[serde(default)]
186    pub execution_cache: ExecutionCacheConfig,
187
188    // step 1 in removing the old state accumulator
189    #[serde(skip)]
190    #[serde(default = "bool_true")]
191    pub state_accumulator_v2: bool,
192
193    #[serde(default = "bool_true")]
194    pub enable_soft_bundle: bool,
195
196    #[serde(default)]
197    pub verifier_signing_config: VerifierSigningConfig,
198
199    /// If a value is set, it determines if writes to DB can stall, which can halt the whole process.
200    /// By default, write stall is enabled on validators but not on fullnodes.
201    #[serde(skip_serializing_if = "Option::is_none")]
202    pub enable_db_write_stall: Option<bool>,
203
204    #[serde(skip_serializing_if = "Option::is_none")]
205    pub execution_time_observer_config: Option<ExecutionTimeObserverConfig>,
206
207    /// Allow overriding the chain for testing purposes. For instance, it allows you to
208    /// create a test network that believes it is mainnet or testnet. Attempting to
209    /// override this value on production networks will result in an error.
210    #[serde(skip_serializing_if = "Option::is_none")]
211    pub chain_override_for_testing: Option<Chain>,
212
213    /// Configuration for validator client monitoring from the client perspective.
214    /// When enabled, tracks client-observed performance metrics for validators.
215    #[serde(skip_serializing_if = "Option::is_none")]
216    pub validator_client_monitor_config: Option<ValidatorClientMonitorConfig>,
217
218    /// Fork recovery configuration for handling validator equivocation after forks
219    #[serde(skip_serializing_if = "Option::is_none")]
220    pub fork_recovery: Option<ForkRecoveryConfig>,
221
222    /// Configuration for the transaction driver.
223    #[serde(skip_serializing_if = "Option::is_none")]
224    pub transaction_driver_config: Option<TransactionDriverConfig>,
225}
226
227#[derive(Clone, Debug, Deserialize, Serialize)]
228#[serde(rename_all = "kebab-case")]
229pub struct TransactionDriverConfig {
230    /// The list of validators that are allowed to submit MFP transactions to (via the transaction driver).
231    /// Each entry is a validator display name.
232    #[serde(default, skip_serializing_if = "Vec::is_empty")]
233    pub allowed_submission_validators: Vec<String>,
234
235    /// The list of validators that are blocked from submitting block transactions to (via the transaction driver).
236    /// Each entry is a validator display name.
237    #[serde(default, skip_serializing_if = "Vec::is_empty")]
238    pub blocked_submission_validators: Vec<String>,
239
240    /// Enable early transaction validation before submission to consensus.
241    /// This checks for non-retriable errors (like old object versions) and rejects
242    /// transactions early to provide fast feedback to clients.
243    /// Note: Currently used in TransactionOrchestrator, but may be moved to TransactionDriver in future.
244    #[serde(default = "bool_true")]
245    pub enable_early_validation: bool,
246}
247
248impl Default for TransactionDriverConfig {
249    fn default() -> Self {
250        Self {
251            allowed_submission_validators: vec![],
252            blocked_submission_validators: vec![],
253            enable_early_validation: true,
254        }
255    }
256}
257
258#[derive(Debug, Clone, Copy, Default, Deserialize, Serialize, PartialEq, Eq)]
259#[serde(rename_all = "kebab-case")]
260pub enum ForkCrashBehavior {
261    #[serde(rename = "await-fork-recovery")]
262    #[default]
263    AwaitForkRecovery,
264    /// Return an error instead of blocking forever. This is primarily for testing.
265    #[serde(rename = "return-error")]
266    ReturnError,
267}
268
269#[derive(Clone, Debug, Default, Deserialize, Serialize)]
270#[serde(rename_all = "kebab-case")]
271pub struct ForkRecoveryConfig {
272    /// Map of transaction digest to effects digest overrides
273    /// Used to repoint transactions to correct effects after a fork
274    #[serde(default)]
275    pub transaction_overrides: BTreeMap<String, String>,
276
277    /// Map of checkpoint sequence number to checkpoint digest overrides
278    /// On node start, if we have a locally computed checkpoint with a
279    /// digest mismatch with this table, we will clear any associated local state.
280    #[serde(default)]
281    pub checkpoint_overrides: BTreeMap<u64, String>,
282
283    /// Behavior when a fork is detected after recovery attempts
284    #[serde(default)]
285    pub fork_crash_behavior: ForkCrashBehavior,
286}
287
288#[derive(Clone, Debug, Default, Deserialize, Serialize)]
289#[serde(rename_all = "kebab-case")]
290pub struct ExecutionTimeObserverConfig {
291    /// Size of the channel used for buffering local execution time observations.
292    ///
293    /// If unspecified, this will default to `1_024`.
294    pub observation_channel_capacity: Option<NonZeroUsize>,
295
296    /// Size of the LRU cache used for storing local execution time observations.
297    ///
298    /// If unspecified, this will default to `10_000`.
299    pub observation_cache_size: Option<NonZeroUsize>,
300
301    /// Size of the channel used for buffering object debt updates from consensus handler.
302    ///
303    /// If unspecified, this will default to `128`.
304    pub object_debt_channel_capacity: Option<NonZeroUsize>,
305
306    /// Size of the LRU cache used for tracking object utilization.
307    ///
308    /// If unspecified, this will default to `50_000`.
309    pub object_utilization_cache_size: Option<NonZeroUsize>,
310
311    /// If true, the execution time observer will report per-object utilization metrics
312    /// with full object IDs. When set, the metric can have a high cardinality, so this
313    /// should not be used except in controlled tests where there are a small number of
314    /// objects.
315    ///
316    /// If false, object utilization is reported using hash(object_id) % 32 as the key,
317    /// which still allows observation of utilization when there are small numbers of
318    /// over-utilized objects.
319    ///
320    /// If unspecified, this will default to `false`.
321    pub report_object_utilization_metric_with_full_id: Option<bool>,
322
323    /// Unless target object utilization is exceeded by at least this amount, no observation
324    /// will be shared with consensus.
325    ///
326    /// If unspecified, this will default to `500` milliseconds.
327    pub observation_sharing_object_utilization_threshold: Option<Duration>,
328
329    /// Unless the current local observation differs from the last one we shared by at least this
330    /// percentage, no observation will be shared with consensus.
331    ///
332    /// If unspecified, this will default to `0.1`.
333    pub observation_sharing_diff_threshold: Option<f64>,
334
335    /// Minimum interval between sharing multiple observations of the same key.
336    ///
337    /// If unspecified, this will default to `5` seconds.
338    pub observation_sharing_min_interval: Option<Duration>,
339
340    /// Global per-second rate limit for sharing observations. This is a safety valve and
341    /// should not trigger during normal operation.
342    ///
343    /// If unspecified, this will default to `10` observations per second.
344    pub observation_sharing_rate_limit: Option<NonZeroU32>,
345
346    /// Global burst limit for sharing observations.
347    ///
348    /// If unspecified, this will default to `100` observations.
349    pub observation_sharing_burst_limit: Option<NonZeroU32>,
350
351    /// Whether to use gas price weighting in execution time estimates.
352    /// When enabled, samples with higher gas prices have more influence on the
353    /// execution time estimates, providing protection against volume-based
354    /// manipulation attacks.
355    ///
356    /// If unspecified, this will default to `false`.
357    pub enable_gas_price_weighting: Option<bool>,
358
359    /// Size of the weighted moving average window for execution time observations.
360    /// This determines how many recent observations are kept in the weighted moving average
361    /// calculation for each execution time observation key.
362    /// Note that this is independent of the window size for the simple moving average.
363    ///
364    /// If unspecified, this will default to `20`.
365    pub weighted_moving_average_window_size: Option<usize>,
366
367    /// Whether to inject synthetic execution time for testing in simtest.
368    /// When enabled, synthetic timings will be generated for execution time observations
369    /// to enable deterministic testing of congestion control features.
370    ///
371    /// If unspecified, this will default to `false`.
372    #[cfg(msim)]
373    pub inject_synthetic_execution_time: Option<bool>,
374}
375
376impl ExecutionTimeObserverConfig {
377    pub fn observation_channel_capacity(&self) -> NonZeroUsize {
378        self.observation_channel_capacity
379            .unwrap_or(nonzero!(1_024usize))
380    }
381
382    pub fn observation_cache_size(&self) -> NonZeroUsize {
383        self.observation_cache_size.unwrap_or(nonzero!(10_000usize))
384    }
385
386    pub fn object_debt_channel_capacity(&self) -> NonZeroUsize {
387        self.object_debt_channel_capacity
388            .unwrap_or(nonzero!(128usize))
389    }
390
391    pub fn object_utilization_cache_size(&self) -> NonZeroUsize {
392        self.object_utilization_cache_size
393            .unwrap_or(nonzero!(50_000usize))
394    }
395
396    pub fn report_object_utilization_metric_with_full_id(&self) -> bool {
397        self.report_object_utilization_metric_with_full_id
398            .unwrap_or(false)
399    }
400
401    pub fn observation_sharing_object_utilization_threshold(&self) -> Duration {
402        self.observation_sharing_object_utilization_threshold
403            .unwrap_or(Duration::from_millis(500))
404    }
405
406    pub fn observation_sharing_diff_threshold(&self) -> f64 {
407        self.observation_sharing_diff_threshold.unwrap_or(0.1)
408    }
409
410    pub fn observation_sharing_min_interval(&self) -> Duration {
411        self.observation_sharing_min_interval
412            .unwrap_or(Duration::from_secs(5))
413    }
414
415    pub fn observation_sharing_rate_limit(&self) -> NonZeroU32 {
416        self.observation_sharing_rate_limit
417            .unwrap_or(nonzero!(10u32))
418    }
419
420    pub fn observation_sharing_burst_limit(&self) -> NonZeroU32 {
421        self.observation_sharing_burst_limit
422            .unwrap_or(nonzero!(100u32))
423    }
424
425    pub fn enable_gas_price_weighting(&self) -> bool {
426        self.enable_gas_price_weighting.unwrap_or(false)
427    }
428
429    pub fn weighted_moving_average_window_size(&self) -> usize {
430        self.weighted_moving_average_window_size.unwrap_or(20)
431    }
432
433    #[cfg(msim)]
434    pub fn inject_synthetic_execution_time(&self) -> bool {
435        self.inject_synthetic_execution_time.unwrap_or(false)
436    }
437}
438
439#[allow(clippy::large_enum_variant)]
440#[derive(Clone, Debug, Deserialize, Serialize)]
441#[serde(rename_all = "kebab-case")]
442pub enum ExecutionCacheConfig {
443    PassthroughCache,
444    WritebackCache {
445        /// Maximum number of entries in each cache. (There are several different caches).
446        /// If None, the default of 10000 is used.
447        max_cache_size: Option<u64>,
448
449        package_cache_size: Option<u64>, // defaults to 1000
450
451        object_cache_size: Option<u64>, // defaults to max_cache_size
452        marker_cache_size: Option<u64>, // defaults to object_cache_size
453        object_by_id_cache_size: Option<u64>, // defaults to object_cache_size
454
455        transaction_cache_size: Option<u64>, // defaults to max_cache_size
456        executed_effect_cache_size: Option<u64>, // defaults to transaction_cache_size
457        effect_cache_size: Option<u64>,      // defaults to executed_effect_cache_size
458
459        events_cache_size: Option<u64>, // defaults to transaction_cache_size
460
461        transaction_objects_cache_size: Option<u64>, // defaults to 1000
462
463        /// Number of uncommitted transactions at which to pause consensus handler.
464        backpressure_threshold: Option<u64>,
465
466        /// Number of uncommitted transactions at which to refuse new transaction
467        /// submissions. Defaults to backpressure_threshold if unset.
468        backpressure_threshold_for_rpc: Option<u64>,
469
470        fastpath_transaction_outputs_cache_size: Option<u64>,
471    },
472}
473
474impl Default for ExecutionCacheConfig {
475    fn default() -> Self {
476        ExecutionCacheConfig::WritebackCache {
477            max_cache_size: None,
478            backpressure_threshold: None,
479            backpressure_threshold_for_rpc: None,
480            package_cache_size: None,
481            object_cache_size: None,
482            marker_cache_size: None,
483            object_by_id_cache_size: None,
484            transaction_cache_size: None,
485            executed_effect_cache_size: None,
486            effect_cache_size: None,
487            events_cache_size: None,
488            transaction_objects_cache_size: None,
489            fastpath_transaction_outputs_cache_size: None,
490        }
491    }
492}
493
494impl ExecutionCacheConfig {
495    pub fn max_cache_size(&self) -> u64 {
496        std::env::var("SUI_MAX_CACHE_SIZE")
497            .ok()
498            .and_then(|s| s.parse().ok())
499            .unwrap_or_else(|| match self {
500                ExecutionCacheConfig::PassthroughCache => fatal!("invalid cache config"),
501                ExecutionCacheConfig::WritebackCache { max_cache_size, .. } => {
502                    max_cache_size.unwrap_or(100000)
503                }
504            })
505    }
506
507    pub fn package_cache_size(&self) -> u64 {
508        std::env::var("SUI_PACKAGE_CACHE_SIZE")
509            .ok()
510            .and_then(|s| s.parse().ok())
511            .unwrap_or_else(|| match self {
512                ExecutionCacheConfig::PassthroughCache => fatal!("invalid cache config"),
513                ExecutionCacheConfig::WritebackCache {
514                    package_cache_size, ..
515                } => package_cache_size.unwrap_or(1000),
516            })
517    }
518
519    pub fn object_cache_size(&self) -> u64 {
520        std::env::var("SUI_OBJECT_CACHE_SIZE")
521            .ok()
522            .and_then(|s| s.parse().ok())
523            .unwrap_or_else(|| match self {
524                ExecutionCacheConfig::PassthroughCache => fatal!("invalid cache config"),
525                ExecutionCacheConfig::WritebackCache {
526                    object_cache_size, ..
527                } => object_cache_size.unwrap_or(self.max_cache_size()),
528            })
529    }
530
531    pub fn marker_cache_size(&self) -> u64 {
532        std::env::var("SUI_MARKER_CACHE_SIZE")
533            .ok()
534            .and_then(|s| s.parse().ok())
535            .unwrap_or_else(|| match self {
536                ExecutionCacheConfig::PassthroughCache => fatal!("invalid cache config"),
537                ExecutionCacheConfig::WritebackCache {
538                    marker_cache_size, ..
539                } => marker_cache_size.unwrap_or(self.object_cache_size()),
540            })
541    }
542
543    pub fn object_by_id_cache_size(&self) -> u64 {
544        std::env::var("SUI_OBJECT_BY_ID_CACHE_SIZE")
545            .ok()
546            .and_then(|s| s.parse().ok())
547            .unwrap_or_else(|| match self {
548                ExecutionCacheConfig::PassthroughCache => fatal!("invalid cache config"),
549                ExecutionCacheConfig::WritebackCache {
550                    object_by_id_cache_size,
551                    ..
552                } => object_by_id_cache_size.unwrap_or(self.object_cache_size()),
553            })
554    }
555
556    pub fn transaction_cache_size(&self) -> u64 {
557        std::env::var("SUI_TRANSACTION_CACHE_SIZE")
558            .ok()
559            .and_then(|s| s.parse().ok())
560            .unwrap_or_else(|| match self {
561                ExecutionCacheConfig::PassthroughCache => fatal!("invalid cache config"),
562                ExecutionCacheConfig::WritebackCache {
563                    transaction_cache_size,
564                    ..
565                } => transaction_cache_size.unwrap_or(self.max_cache_size()),
566            })
567    }
568
569    pub fn executed_effect_cache_size(&self) -> u64 {
570        std::env::var("SUI_EXECUTED_EFFECT_CACHE_SIZE")
571            .ok()
572            .and_then(|s| s.parse().ok())
573            .unwrap_or_else(|| match self {
574                ExecutionCacheConfig::PassthroughCache => fatal!("invalid cache config"),
575                ExecutionCacheConfig::WritebackCache {
576                    executed_effect_cache_size,
577                    ..
578                } => executed_effect_cache_size.unwrap_or(self.transaction_cache_size()),
579            })
580    }
581
582    pub fn effect_cache_size(&self) -> u64 {
583        std::env::var("SUI_EFFECT_CACHE_SIZE")
584            .ok()
585            .and_then(|s| s.parse().ok())
586            .unwrap_or_else(|| match self {
587                ExecutionCacheConfig::PassthroughCache => fatal!("invalid cache config"),
588                ExecutionCacheConfig::WritebackCache {
589                    effect_cache_size, ..
590                } => effect_cache_size.unwrap_or(self.executed_effect_cache_size()),
591            })
592    }
593
594    pub fn events_cache_size(&self) -> u64 {
595        std::env::var("SUI_EVENTS_CACHE_SIZE")
596            .ok()
597            .and_then(|s| s.parse().ok())
598            .unwrap_or_else(|| match self {
599                ExecutionCacheConfig::PassthroughCache => fatal!("invalid cache config"),
600                ExecutionCacheConfig::WritebackCache {
601                    events_cache_size, ..
602                } => events_cache_size.unwrap_or(self.transaction_cache_size()),
603            })
604    }
605
606    pub fn transaction_objects_cache_size(&self) -> u64 {
607        std::env::var("SUI_TRANSACTION_OBJECTS_CACHE_SIZE")
608            .ok()
609            .and_then(|s| s.parse().ok())
610            .unwrap_or_else(|| match self {
611                ExecutionCacheConfig::PassthroughCache => fatal!("invalid cache config"),
612                ExecutionCacheConfig::WritebackCache {
613                    transaction_objects_cache_size,
614                    ..
615                } => transaction_objects_cache_size.unwrap_or(1000),
616            })
617    }
618
619    pub fn backpressure_threshold(&self) -> u64 {
620        std::env::var("SUI_BACKPRESSURE_THRESHOLD")
621            .ok()
622            .and_then(|s| s.parse().ok())
623            .unwrap_or_else(|| match self {
624                ExecutionCacheConfig::PassthroughCache => fatal!("invalid cache config"),
625                ExecutionCacheConfig::WritebackCache {
626                    backpressure_threshold,
627                    ..
628                } => backpressure_threshold.unwrap_or(100_000),
629            })
630    }
631
632    pub fn backpressure_threshold_for_rpc(&self) -> u64 {
633        std::env::var("SUI_BACKPRESSURE_THRESHOLD_FOR_RPC")
634            .ok()
635            .and_then(|s| s.parse().ok())
636            .unwrap_or_else(|| match self {
637                ExecutionCacheConfig::PassthroughCache => fatal!("invalid cache config"),
638                ExecutionCacheConfig::WritebackCache {
639                    backpressure_threshold_for_rpc,
640                    ..
641                } => backpressure_threshold_for_rpc.unwrap_or(self.backpressure_threshold()),
642            })
643    }
644
645    pub fn fastpath_transaction_outputs_cache_size(&self) -> u64 {
646        std::env::var("SUI_FASTPATH_TRANSACTION_OUTPUTS_CACHE_SIZE")
647            .ok()
648            .and_then(|s| s.parse().ok())
649            .unwrap_or_else(|| match self {
650                ExecutionCacheConfig::PassthroughCache => fatal!("invalid cache config"),
651                ExecutionCacheConfig::WritebackCache {
652                    fastpath_transaction_outputs_cache_size,
653                    ..
654                } => fastpath_transaction_outputs_cache_size.unwrap_or(10_000),
655            })
656    }
657}
658
659#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
660#[serde(rename_all = "lowercase")]
661pub enum ServerType {
662    WebSocket,
663    Http,
664    Both,
665}
666
667#[derive(Clone, Debug, Deserialize, Serialize)]
668#[serde(rename_all = "kebab-case")]
669pub struct TransactionKeyValueStoreReadConfig {
670    #[serde(default = "default_base_url")]
671    pub base_url: String,
672
673    #[serde(default = "default_cache_size")]
674    pub cache_size: u64,
675}
676
677impl Default for TransactionKeyValueStoreReadConfig {
678    fn default() -> Self {
679        Self {
680            base_url: default_base_url(),
681            cache_size: default_cache_size(),
682        }
683    }
684}
685
686fn default_base_url() -> String {
687    "https://transactions.sui.io/".to_string()
688}
689
690fn default_cache_size() -> u64 {
691    100_000
692}
693
694fn default_jwk_fetch_interval_seconds() -> u64 {
695    3600
696}
697
698pub fn default_zklogin_oauth_providers() -> BTreeMap<Chain, BTreeSet<String>> {
699    let mut map = BTreeMap::new();
700
701    // providers that are available on devnet only.
702    let experimental_providers = BTreeSet::from([
703        "Google".to_string(),
704        "Facebook".to_string(),
705        "Twitch".to_string(),
706        "Kakao".to_string(),
707        "Apple".to_string(),
708        "Slack".to_string(),
709        "TestIssuer".to_string(),
710        "Microsoft".to_string(),
711        "KarrierOne".to_string(),
712        "Credenza3".to_string(),
713        "Playtron".to_string(),
714        "Threedos".to_string(),
715        "Onefc".to_string(),
716        "FanTV".to_string(),
717        "AwsTenant-region:us-east-1-tenant_id:us-east-1_qPsZxYqd8".to_string(), // Ambrus, external partner
718        "Arden".to_string(),                                                    // Arden partner
719        "AwsTenant-region:eu-west-3-tenant_id:eu-west-3_gGVCx53Es".to_string(), // Trace, external partner
720        "EveFrontier".to_string(),
721        "TestEveFrontier".to_string(),
722        "AwsTenant-region:ap-southeast-1-tenant_id:ap-southeast-1_2QQPyQXDz".to_string(), // Decot, external partner
723    ]);
724
725    // providers that are available for mainnet and testnet.
726    let providers = BTreeSet::from([
727        "Google".to_string(),
728        "Facebook".to_string(),
729        "Twitch".to_string(),
730        "Apple".to_string(),
731        "AwsTenant-region:us-east-1-tenant_id:us-east-1_qPsZxYqd8".to_string(), // Ambrus, external partner
732        "KarrierOne".to_string(),
733        "Credenza3".to_string(),
734        "Playtron".to_string(),
735        "Onefc".to_string(),
736        "Threedos".to_string(),
737        "AwsTenant-region:eu-west-3-tenant_id:eu-west-3_gGVCx53Es".to_string(), // Trace, external partner
738        "Arden".to_string(),
739        "FanTV".to_string(),
740        "EveFrontier".to_string(),
741        "TestEveFrontier".to_string(),
742        "AwsTenant-region:ap-southeast-1-tenant_id:ap-southeast-1_2QQPyQXDz".to_string(), // Decot, external partner
743    ]);
744    map.insert(Chain::Mainnet, providers.clone());
745    map.insert(Chain::Testnet, providers);
746    map.insert(Chain::Unknown, experimental_providers);
747    map
748}
749
750fn default_transaction_kv_store_config() -> TransactionKeyValueStoreReadConfig {
751    TransactionKeyValueStoreReadConfig::default()
752}
753
754fn default_authority_store_pruning_config() -> AuthorityStorePruningConfig {
755    AuthorityStorePruningConfig::default()
756}
757
758pub fn default_enable_index_processing() -> bool {
759    true
760}
761
762fn default_grpc_address() -> Multiaddr {
763    "/ip4/0.0.0.0/tcp/8080".parse().unwrap()
764}
765fn default_authority_key_pair() -> AuthorityKeyPairWithPath {
766    AuthorityKeyPairWithPath::new(get_key_pair_from_rng::<AuthorityKeyPair, _>(&mut OsRng).1)
767}
768
769fn default_key_pair() -> KeyPairWithPath {
770    KeyPairWithPath::new(
771        get_key_pair_from_rng::<AccountKeyPair, _>(&mut OsRng)
772            .1
773            .into(),
774    )
775}
776
777fn default_metrics_address() -> SocketAddr {
778    use std::net::{IpAddr, Ipv4Addr};
779    SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 9184)
780}
781
782pub fn default_admin_interface_port() -> u16 {
783    1337
784}
785
786pub fn default_json_rpc_address() -> SocketAddr {
787    use std::net::{IpAddr, Ipv4Addr};
788    SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 9000)
789}
790
791pub fn default_concurrency_limit() -> Option<usize> {
792    Some(DEFAULT_GRPC_CONCURRENCY_LIMIT)
793}
794
795pub fn default_end_of_epoch_broadcast_channel_capacity() -> usize {
796    128
797}
798
799pub fn bool_true() -> bool {
800    true
801}
802
803fn is_true(value: &bool) -> bool {
804    *value
805}
806
807impl Config for NodeConfig {}
808
809impl NodeConfig {
810    pub fn protocol_key_pair(&self) -> &AuthorityKeyPair {
811        self.protocol_key_pair.authority_keypair()
812    }
813
814    pub fn worker_key_pair(&self) -> &NetworkKeyPair {
815        match self.worker_key_pair.keypair() {
816            SuiKeyPair::Ed25519(kp) => kp,
817            other => panic!(
818                "Invalid keypair type: {:?}, only Ed25519 is allowed for worker key",
819                other
820            ),
821        }
822    }
823
824    pub fn network_key_pair(&self) -> &NetworkKeyPair {
825        match self.network_key_pair.keypair() {
826            SuiKeyPair::Ed25519(kp) => kp,
827            other => panic!(
828                "Invalid keypair type: {:?}, only Ed25519 is allowed for network key",
829                other
830            ),
831        }
832    }
833
834    pub fn protocol_public_key(&self) -> AuthorityPublicKeyBytes {
835        self.protocol_key_pair().public().into()
836    }
837
838    pub fn db_path(&self) -> PathBuf {
839        self.db_path.join("live")
840    }
841
842    pub fn db_checkpoint_path(&self) -> PathBuf {
843        self.db_path.join("db_checkpoints")
844    }
845
846    pub fn archive_path(&self) -> PathBuf {
847        self.db_path.join("archive")
848    }
849
850    pub fn snapshot_path(&self) -> PathBuf {
851        self.db_path.join("snapshot")
852    }
853
854    pub fn network_address(&self) -> &Multiaddr {
855        &self.network_address
856    }
857
858    pub fn consensus_config(&self) -> Option<&ConsensusConfig> {
859        self.consensus_config.as_ref()
860    }
861
862    pub fn genesis(&self) -> Result<&genesis::Genesis> {
863        self.genesis.genesis()
864    }
865
866    pub fn sui_address(&self) -> SuiAddress {
867        (&self.account_key_pair.keypair().public()).into()
868    }
869
870    pub fn archive_reader_config(&self) -> Option<ArchiveReaderConfig> {
871        self.state_archive_read_config
872            .first()
873            .map(|config| ArchiveReaderConfig {
874                ingestion_url: config.ingestion_url.clone(),
875                remote_store_options: config.remote_store_options.clone(),
876                download_concurrency: NonZeroUsize::new(config.concurrency)
877                    .unwrap_or(NonZeroUsize::new(5).unwrap()),
878                remote_store_config: ObjectStoreConfig::default(),
879            })
880    }
881
882    pub fn jsonrpc_server_type(&self) -> ServerType {
883        self.jsonrpc_server_type.unwrap_or(ServerType::Http)
884    }
885
886    pub fn rpc(&self) -> Option<&crate::RpcConfig> {
887        self.rpc.as_ref()
888    }
889}
890
891#[derive(Debug, Clone, Deserialize, Serialize)]
892pub enum ConsensusProtocol {
893    #[serde(rename = "narwhal")]
894    Narwhal,
895    #[serde(rename = "mysticeti")]
896    Mysticeti,
897}
898
899#[derive(Debug, Clone, Deserialize, Serialize)]
900#[serde(rename_all = "kebab-case")]
901pub struct ConsensusConfig {
902    // Base consensus DB path for all epochs.
903    pub db_path: PathBuf,
904
905    // The number of epochs for which to retain the consensus DBs. Setting it to 0 will make a consensus DB getting
906    // dropped as soon as system is switched to a new epoch.
907    pub db_retention_epochs: Option<u64>,
908
909    // Pruner will run on every epoch change but it will also check periodically on every `db_pruner_period_secs`
910    // seconds to see if there are any epoch DBs to remove.
911    pub db_pruner_period_secs: Option<u64>,
912
913    /// Maximum number of pending transactions to submit to consensus, including those
914    /// in submission wait.
915    /// Default to 20_000 inflight limit, assuming 20_000 txn tps * 1 sec consensus latency.
916    pub max_pending_transactions: Option<usize>,
917
918    /// When defined caps the calculated submission position to the max_submit_position. Even if the
919    /// is elected to submit from a higher position than this, it will "reset" to the max_submit_position.
920    pub max_submit_position: Option<usize>,
921
922    /// The submit delay step to consensus defined in milliseconds. When provided it will
923    /// override the current back off logic otherwise the default backoff logic will be applied based
924    /// on consensus latency estimates.
925    pub submit_delay_step_override_millis: Option<u64>,
926
927    pub parameters: Option<ConsensusParameters>,
928}
929
930impl ConsensusConfig {
931    pub fn db_path(&self) -> &Path {
932        &self.db_path
933    }
934
935    pub fn max_pending_transactions(&self) -> usize {
936        self.max_pending_transactions.unwrap_or(20_000)
937    }
938
939    pub fn submit_delay_step_override(&self) -> Option<Duration> {
940        self.submit_delay_step_override_millis
941            .map(Duration::from_millis)
942    }
943
944    pub fn db_retention_epochs(&self) -> u64 {
945        self.db_retention_epochs.unwrap_or(0)
946    }
947
948    pub fn db_pruner_period(&self) -> Duration {
949        // Default to 1 hour
950        self.db_pruner_period_secs
951            .map(Duration::from_secs)
952            .unwrap_or(Duration::from_secs(3_600))
953    }
954}
955
956#[derive(Clone, Debug, Deserialize, Serialize)]
957#[serde(rename_all = "kebab-case")]
958pub struct CheckpointExecutorConfig {
959    /// Upper bound on the number of checkpoints that can be concurrently executed
960    ///
961    /// If unspecified, this will default to `200`
962    #[serde(default = "default_checkpoint_execution_max_concurrency")]
963    pub checkpoint_execution_max_concurrency: usize,
964
965    /// Number of seconds to wait for effects of a batch of transactions
966    /// before logging a warning. Note that we will continue to retry
967    /// indefinitely
968    ///
969    /// If unspecified, this will default to `10`.
970    #[serde(default = "default_local_execution_timeout_sec")]
971    pub local_execution_timeout_sec: u64,
972
973    /// Optional directory used for data ingestion pipeline
974    /// When specified, each executed checkpoint will be saved in a local directory for post processing
975    #[serde(default, skip_serializing_if = "Option::is_none")]
976    pub data_ingestion_dir: Option<PathBuf>,
977}
978
979#[derive(Clone, Debug, Default, Deserialize, Serialize)]
980#[serde(rename_all = "kebab-case")]
981pub struct ExpensiveSafetyCheckConfig {
982    /// If enabled, at epoch boundary, we will check that the storage
983    /// fund balance is always identical to the sum of the storage
984    /// rebate of all live objects, and that the total SUI in the network remains
985    /// the same.
986    #[serde(default)]
987    enable_epoch_sui_conservation_check: bool,
988
989    /// If enabled, we will check that the total SUI in all input objects of a tx
990    /// (both the Move part and the storage rebate) matches the total SUI in all
991    /// output objects of the tx + gas fees
992    #[serde(default)]
993    enable_deep_per_tx_sui_conservation_check: bool,
994
995    /// Disable epoch SUI conservation check even when we are running in debug mode.
996    #[serde(default)]
997    force_disable_epoch_sui_conservation_check: bool,
998
999    /// If enabled, at epoch boundary, we will check that the accumulated
1000    /// live object state matches the end of epoch root state digest.
1001    #[serde(default)]
1002    enable_state_consistency_check: bool,
1003
1004    /// Disable state consistency check even when we are running in debug mode.
1005    #[serde(default)]
1006    force_disable_state_consistency_check: bool,
1007
1008    #[serde(default)]
1009    enable_secondary_index_checks: bool,
1010    // TODO: Add more expensive checks here
1011}
1012
1013impl ExpensiveSafetyCheckConfig {
1014    pub fn new_enable_all() -> Self {
1015        Self {
1016            enable_epoch_sui_conservation_check: true,
1017            enable_deep_per_tx_sui_conservation_check: true,
1018            force_disable_epoch_sui_conservation_check: false,
1019            enable_state_consistency_check: true,
1020            force_disable_state_consistency_check: false,
1021            enable_secondary_index_checks: false, // Disable by default for now
1022        }
1023    }
1024
1025    pub fn new_disable_all() -> Self {
1026        Self {
1027            enable_epoch_sui_conservation_check: false,
1028            enable_deep_per_tx_sui_conservation_check: false,
1029            force_disable_epoch_sui_conservation_check: true,
1030            enable_state_consistency_check: false,
1031            force_disable_state_consistency_check: true,
1032            enable_secondary_index_checks: false,
1033        }
1034    }
1035
1036    pub fn force_disable_epoch_sui_conservation_check(&mut self) {
1037        self.force_disable_epoch_sui_conservation_check = true;
1038    }
1039
1040    pub fn enable_epoch_sui_conservation_check(&self) -> bool {
1041        (self.enable_epoch_sui_conservation_check || cfg!(debug_assertions))
1042            && !self.force_disable_epoch_sui_conservation_check
1043    }
1044
1045    pub fn force_disable_state_consistency_check(&mut self) {
1046        self.force_disable_state_consistency_check = true;
1047    }
1048
1049    pub fn enable_state_consistency_check(&self) -> bool {
1050        (self.enable_state_consistency_check || cfg!(debug_assertions))
1051            && !self.force_disable_state_consistency_check
1052    }
1053
1054    pub fn enable_deep_per_tx_sui_conservation_check(&self) -> bool {
1055        self.enable_deep_per_tx_sui_conservation_check || cfg!(debug_assertions)
1056    }
1057
1058    pub fn enable_secondary_index_checks(&self) -> bool {
1059        self.enable_secondary_index_checks
1060    }
1061}
1062
1063fn default_checkpoint_execution_max_concurrency() -> usize {
1064    4
1065}
1066
1067fn default_local_execution_timeout_sec() -> u64 {
1068    30
1069}
1070
1071impl Default for CheckpointExecutorConfig {
1072    fn default() -> Self {
1073        Self {
1074            checkpoint_execution_max_concurrency: default_checkpoint_execution_max_concurrency(),
1075            local_execution_timeout_sec: default_local_execution_timeout_sec(),
1076            data_ingestion_dir: None,
1077        }
1078    }
1079}
1080
1081#[derive(Debug, Clone, Deserialize, Serialize)]
1082#[serde(rename_all = "kebab-case")]
1083pub struct AuthorityStorePruningConfig {
1084    /// number of the latest epoch dbs to retain
1085    #[serde(default = "default_num_latest_epoch_dbs_to_retain")]
1086    pub num_latest_epoch_dbs_to_retain: usize,
1087    /// time interval used by the pruner to determine whether there are any epoch DBs to remove
1088    #[serde(default = "default_epoch_db_pruning_period_secs")]
1089    pub epoch_db_pruning_period_secs: u64,
1090    /// number of epochs to keep the latest version of objects for.
1091    /// Note that a zero value corresponds to an aggressive pruner.
1092    /// This mode is experimental and needs to be used with caution.
1093    /// Use `u64::MAX` to disable the pruner for the objects.
1094    #[serde(default)]
1095    pub num_epochs_to_retain: u64,
1096    /// pruner's runtime interval used for aggressive mode
1097    #[serde(skip_serializing_if = "Option::is_none")]
1098    pub pruning_run_delay_seconds: Option<u64>,
1099    /// maximum number of checkpoints in the pruning batch. Can be adjusted to increase performance
1100    #[serde(default = "default_max_checkpoints_in_batch")]
1101    pub max_checkpoints_in_batch: usize,
1102    /// maximum number of transaction in the pruning batch
1103    #[serde(default = "default_max_transactions_in_batch")]
1104    pub max_transactions_in_batch: usize,
1105    /// enables periodic background compaction for old SST files whose last modified time is
1106    /// older than `periodic_compaction_threshold_days` days.
1107    /// That ensures that all sst files eventually go through the compaction process
1108    #[serde(
1109        default = "default_periodic_compaction_threshold_days",
1110        skip_serializing_if = "Option::is_none"
1111    )]
1112    pub periodic_compaction_threshold_days: Option<usize>,
1113    /// number of epochs to keep the latest version of transactions and effects for
1114    #[serde(skip_serializing_if = "Option::is_none")]
1115    pub num_epochs_to_retain_for_checkpoints: Option<u64>,
1116    /// disables object tombstone pruning. We don't serialize it if it is the default value, false.
1117    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
1118    pub killswitch_tombstone_pruning: bool,
1119    #[serde(default = "default_smoothing", skip_serializing_if = "is_true")]
1120    pub smooth: bool,
1121    /// Enables the compaction filter for pruning the objects table.
1122    /// If disabled, a range deletion approach is used instead.
1123    /// While it is generally safe to switch between the two modes,
1124    /// switching from the compaction filter approach back to range deletion
1125    /// may result in some old versions that will never be pruned.
1126    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
1127    pub enable_compaction_filter: bool,
1128    #[serde(skip_serializing_if = "Option::is_none")]
1129    pub num_epochs_to_retain_for_indexes: Option<u64>,
1130}
1131
1132fn default_num_latest_epoch_dbs_to_retain() -> usize {
1133    3
1134}
1135
1136fn default_epoch_db_pruning_period_secs() -> u64 {
1137    3600
1138}
1139
1140fn default_max_transactions_in_batch() -> usize {
1141    1000
1142}
1143
1144fn default_max_checkpoints_in_batch() -> usize {
1145    10
1146}
1147
1148fn default_smoothing() -> bool {
1149    cfg!(not(test))
1150}
1151
1152fn default_periodic_compaction_threshold_days() -> Option<usize> {
1153    Some(1)
1154}
1155
1156impl Default for AuthorityStorePruningConfig {
1157    fn default() -> Self {
1158        Self {
1159            num_latest_epoch_dbs_to_retain: default_num_latest_epoch_dbs_to_retain(),
1160            epoch_db_pruning_period_secs: default_epoch_db_pruning_period_secs(),
1161            num_epochs_to_retain: 0,
1162            pruning_run_delay_seconds: if cfg!(msim) { Some(2) } else { None },
1163            max_checkpoints_in_batch: default_max_checkpoints_in_batch(),
1164            max_transactions_in_batch: default_max_transactions_in_batch(),
1165            periodic_compaction_threshold_days: None,
1166            num_epochs_to_retain_for_checkpoints: if cfg!(msim) { Some(2) } else { None },
1167            killswitch_tombstone_pruning: false,
1168            smooth: true,
1169            enable_compaction_filter: cfg!(test) || cfg!(msim),
1170            num_epochs_to_retain_for_indexes: None,
1171        }
1172    }
1173}
1174
1175impl AuthorityStorePruningConfig {
1176    pub fn set_num_epochs_to_retain(&mut self, num_epochs_to_retain: u64) {
1177        self.num_epochs_to_retain = num_epochs_to_retain;
1178    }
1179
1180    pub fn set_num_epochs_to_retain_for_checkpoints(&mut self, num_epochs_to_retain: Option<u64>) {
1181        self.num_epochs_to_retain_for_checkpoints = num_epochs_to_retain;
1182    }
1183
1184    pub fn num_epochs_to_retain_for_checkpoints(&self) -> Option<u64> {
1185        self.num_epochs_to_retain_for_checkpoints
1186            // if n less than 2, coerce to 2 and log
1187            .map(|n| {
1188                if n < 2 {
1189                    info!("num_epochs_to_retain_for_checkpoints must be at least 2, rounding up from {}", n);
1190                    2
1191                } else {
1192                    n
1193                }
1194            })
1195    }
1196
1197    pub fn set_killswitch_tombstone_pruning(&mut self, killswitch_tombstone_pruning: bool) {
1198        self.killswitch_tombstone_pruning = killswitch_tombstone_pruning;
1199    }
1200}
1201
1202#[derive(Debug, Clone, Deserialize, Serialize)]
1203#[serde(rename_all = "kebab-case")]
1204pub struct MetricsConfig {
1205    #[serde(skip_serializing_if = "Option::is_none")]
1206    pub push_interval_seconds: Option<u64>,
1207    #[serde(skip_serializing_if = "Option::is_none")]
1208    pub push_url: Option<String>,
1209}
1210
1211#[derive(Default, Debug, Clone, Deserialize, Serialize)]
1212#[serde(rename_all = "kebab-case")]
1213pub struct DBCheckpointConfig {
1214    #[serde(default)]
1215    pub perform_db_checkpoints_at_epoch_end: bool,
1216    #[serde(skip_serializing_if = "Option::is_none")]
1217    pub checkpoint_path: Option<PathBuf>,
1218    #[serde(skip_serializing_if = "Option::is_none")]
1219    pub object_store_config: Option<ObjectStoreConfig>,
1220    #[serde(skip_serializing_if = "Option::is_none")]
1221    pub perform_index_db_checkpoints_at_epoch_end: Option<bool>,
1222    #[serde(skip_serializing_if = "Option::is_none")]
1223    pub prune_and_compact_before_upload: Option<bool>,
1224}
1225
1226#[derive(Debug, Clone)]
1227pub struct ArchiveReaderConfig {
1228    pub remote_store_config: ObjectStoreConfig,
1229    pub download_concurrency: NonZeroUsize,
1230    pub ingestion_url: Option<String>,
1231    pub remote_store_options: Vec<(String, String)>,
1232}
1233
1234#[derive(Default, Debug, Clone, Deserialize, Serialize)]
1235#[serde(rename_all = "kebab-case")]
1236pub struct StateArchiveConfig {
1237    #[serde(skip_serializing_if = "Option::is_none")]
1238    pub object_store_config: Option<ObjectStoreConfig>,
1239    pub concurrency: usize,
1240    #[serde(skip_serializing_if = "Option::is_none")]
1241    pub ingestion_url: Option<String>,
1242    #[serde(
1243        skip_serializing_if = "Vec::is_empty",
1244        default,
1245        deserialize_with = "deserialize_remote_store_options"
1246    )]
1247    pub remote_store_options: Vec<(String, String)>,
1248}
1249
1250#[derive(Default, Debug, Clone, Deserialize, Serialize)]
1251#[serde(rename_all = "kebab-case")]
1252pub struct StateSnapshotConfig {
1253    #[serde(skip_serializing_if = "Option::is_none")]
1254    pub object_store_config: Option<ObjectStoreConfig>,
1255    pub concurrency: usize,
1256    /// Archive snapshots every N epochs. If set to 0, archival is disabled.
1257    /// Archived snapshots are copied to `archive/epoch_<N>/` in the same bucket
1258    /// and are intended to be kept indefinitely.
1259    #[serde(default)]
1260    pub archive_interval_epochs: u64,
1261}
1262
1263#[derive(Default, Debug, Clone, Deserialize, Serialize)]
1264#[serde(rename_all = "kebab-case")]
1265pub struct TransactionKeyValueStoreWriteConfig {
1266    pub aws_access_key_id: String,
1267    pub aws_secret_access_key: String,
1268    pub aws_region: String,
1269    pub table_name: String,
1270    pub bucket_name: String,
1271    pub concurrency: usize,
1272}
1273
1274/// Configuration for the threshold(s) at which we consider the system
1275/// to be overloaded. When one of the threshold is passed, the node may
1276/// stop processing new transactions and/or certificates until the congestion
1277/// resolves.
1278#[derive(Clone, Debug, Deserialize, Serialize)]
1279#[serde(rename_all = "kebab-case")]
1280pub struct AuthorityOverloadConfig {
1281    #[serde(default = "default_max_txn_age_in_queue")]
1282    pub max_txn_age_in_queue: Duration,
1283
1284    // The interval of checking overload signal.
1285    #[serde(default = "default_overload_monitor_interval")]
1286    pub overload_monitor_interval: Duration,
1287
1288    // The execution queueing latency when entering load shedding mode.
1289    #[serde(default = "default_execution_queue_latency_soft_limit")]
1290    pub execution_queue_latency_soft_limit: Duration,
1291
1292    // The execution queueing latency when entering aggressive load shedding mode.
1293    #[serde(default = "default_execution_queue_latency_hard_limit")]
1294    pub execution_queue_latency_hard_limit: Duration,
1295
1296    // The maximum percentage of transactions to shed in load shedding mode.
1297    #[serde(default = "default_max_load_shedding_percentage")]
1298    pub max_load_shedding_percentage: u32,
1299
1300    // When in aggressive load shedding mode, the minimum percentage of
1301    // transactions to shed.
1302    #[serde(default = "default_min_load_shedding_percentage_above_hard_limit")]
1303    pub min_load_shedding_percentage_above_hard_limit: u32,
1304
1305    // If transaction ready rate is below this rate, we consider the validator
1306    // is well under used, and will not enter load shedding mode.
1307    #[serde(default = "default_safe_transaction_ready_rate")]
1308    pub safe_transaction_ready_rate: u32,
1309
1310    // When set to true, transaction signing may be rejected when the validator
1311    // is overloaded.
1312    #[serde(default = "default_check_system_overload_at_signing")]
1313    pub check_system_overload_at_signing: bool,
1314
1315    // When set to true, transaction execution may be rejected when the validator
1316    // is overloaded.
1317    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
1318    pub check_system_overload_at_execution: bool,
1319
1320    // Reject a transaction if transaction manager queue length is above this threshold.
1321    // 100_000 = 10k TPS * 5s resident time in transaction manager (pending + executing) * 2.
1322    #[serde(default = "default_max_transaction_manager_queue_length")]
1323    pub max_transaction_manager_queue_length: usize,
1324
1325    // Reject a transaction if the number of pending transactions depending on the object
1326    // is above the threshold.
1327    #[serde(default = "default_max_transaction_manager_per_object_queue_length")]
1328    pub max_transaction_manager_per_object_queue_length: usize,
1329}
1330
1331fn default_max_txn_age_in_queue() -> Duration {
1332    Duration::from_millis(1000)
1333}
1334
1335fn default_overload_monitor_interval() -> Duration {
1336    Duration::from_secs(10)
1337}
1338
1339fn default_execution_queue_latency_soft_limit() -> Duration {
1340    Duration::from_secs(1)
1341}
1342
1343fn default_execution_queue_latency_hard_limit() -> Duration {
1344    Duration::from_secs(10)
1345}
1346
1347fn default_max_load_shedding_percentage() -> u32 {
1348    95
1349}
1350
1351fn default_min_load_shedding_percentage_above_hard_limit() -> u32 {
1352    50
1353}
1354
1355fn default_safe_transaction_ready_rate() -> u32 {
1356    100
1357}
1358
1359fn default_check_system_overload_at_signing() -> bool {
1360    true
1361}
1362
1363fn default_max_transaction_manager_queue_length() -> usize {
1364    100_000
1365}
1366
1367fn default_max_transaction_manager_per_object_queue_length() -> usize {
1368    2000
1369}
1370
1371impl Default for AuthorityOverloadConfig {
1372    fn default() -> Self {
1373        Self {
1374            max_txn_age_in_queue: default_max_txn_age_in_queue(),
1375            overload_monitor_interval: default_overload_monitor_interval(),
1376            execution_queue_latency_soft_limit: default_execution_queue_latency_soft_limit(),
1377            execution_queue_latency_hard_limit: default_execution_queue_latency_hard_limit(),
1378            max_load_shedding_percentage: default_max_load_shedding_percentage(),
1379            min_load_shedding_percentage_above_hard_limit:
1380                default_min_load_shedding_percentage_above_hard_limit(),
1381            safe_transaction_ready_rate: default_safe_transaction_ready_rate(),
1382            check_system_overload_at_signing: true,
1383            check_system_overload_at_execution: false,
1384            max_transaction_manager_queue_length: default_max_transaction_manager_queue_length(),
1385            max_transaction_manager_per_object_queue_length:
1386                default_max_transaction_manager_per_object_queue_length(),
1387        }
1388    }
1389}
1390
1391fn default_authority_overload_config() -> AuthorityOverloadConfig {
1392    AuthorityOverloadConfig::default()
1393}
1394
1395fn default_traffic_controller_policy_config() -> Option<PolicyConfig> {
1396    Some(PolicyConfig::default_dos_protection_policy())
1397}
1398
1399#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Eq)]
1400pub struct Genesis {
1401    #[serde(flatten)]
1402    location: GenesisLocation,
1403
1404    #[serde(skip)]
1405    genesis: once_cell::sync::OnceCell<genesis::Genesis>,
1406}
1407
1408impl Genesis {
1409    pub fn new(genesis: genesis::Genesis) -> Self {
1410        Self {
1411            location: GenesisLocation::InPlace { genesis },
1412            genesis: Default::default(),
1413        }
1414    }
1415
1416    pub fn new_from_file<P: Into<PathBuf>>(path: P) -> Self {
1417        Self {
1418            location: GenesisLocation::File {
1419                genesis_file_location: path.into(),
1420            },
1421            genesis: Default::default(),
1422        }
1423    }
1424
1425    pub fn genesis(&self) -> Result<&genesis::Genesis> {
1426        match &self.location {
1427            GenesisLocation::InPlace { genesis } => Ok(genesis),
1428            GenesisLocation::File {
1429                genesis_file_location,
1430            } => self
1431                .genesis
1432                .get_or_try_init(|| genesis::Genesis::load(genesis_file_location)),
1433        }
1434    }
1435}
1436
1437#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Eq)]
1438#[serde(untagged)]
1439#[allow(clippy::large_enum_variant)]
1440enum GenesisLocation {
1441    InPlace {
1442        genesis: genesis::Genesis,
1443    },
1444    File {
1445        #[serde(rename = "genesis-file-location")]
1446        genesis_file_location: PathBuf,
1447    },
1448}
1449
1450/// Wrapper struct for SuiKeyPair that can be deserialized from a file path. Used by network, worker, and account keypair.
1451#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
1452pub struct KeyPairWithPath {
1453    #[serde(flatten)]
1454    location: KeyPairLocation,
1455
1456    #[serde(skip)]
1457    keypair: OnceCell<Arc<SuiKeyPair>>,
1458}
1459
1460#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Eq)]
1461#[serde_as]
1462#[serde(untagged)]
1463enum KeyPairLocation {
1464    InPlace {
1465        #[serde_as(as = "Arc<KeyPairBase64>")]
1466        value: Arc<SuiKeyPair>,
1467    },
1468    File {
1469        #[serde(rename = "path")]
1470        path: PathBuf,
1471    },
1472}
1473
1474impl KeyPairWithPath {
1475    pub fn new(kp: SuiKeyPair) -> Self {
1476        let cell: OnceCell<Arc<SuiKeyPair>> = OnceCell::new();
1477        let arc_kp = Arc::new(kp);
1478        // OK to unwrap panic because authority should not start without all keypairs loaded.
1479        cell.set(arc_kp.clone()).expect("Failed to set keypair");
1480        Self {
1481            location: KeyPairLocation::InPlace { value: arc_kp },
1482            keypair: cell,
1483        }
1484    }
1485
1486    pub fn new_from_path(path: PathBuf) -> Self {
1487        let cell: OnceCell<Arc<SuiKeyPair>> = OnceCell::new();
1488        // OK to unwrap panic because authority should not start without all keypairs loaded.
1489        cell.set(Arc::new(read_keypair_from_file(&path).unwrap_or_else(
1490            |e| panic!("Invalid keypair file at path {:?}: {e}", &path),
1491        )))
1492        .expect("Failed to set keypair");
1493        Self {
1494            location: KeyPairLocation::File { path },
1495            keypair: cell,
1496        }
1497    }
1498
1499    pub fn keypair(&self) -> &SuiKeyPair {
1500        self.keypair
1501            .get_or_init(|| match &self.location {
1502                KeyPairLocation::InPlace { value } => value.clone(),
1503                KeyPairLocation::File { path } => {
1504                    // OK to unwrap panic because authority should not start without all keypairs loaded.
1505                    Arc::new(
1506                        read_keypair_from_file(path).unwrap_or_else(|e| {
1507                            panic!("Invalid keypair file at path {:?}: {e}", path)
1508                        }),
1509                    )
1510                }
1511            })
1512            .as_ref()
1513    }
1514}
1515
1516/// Wrapper struct for AuthorityKeyPair that can be deserialized from a file path.
1517#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
1518pub struct AuthorityKeyPairWithPath {
1519    #[serde(flatten)]
1520    location: AuthorityKeyPairLocation,
1521
1522    #[serde(skip)]
1523    keypair: OnceCell<Arc<AuthorityKeyPair>>,
1524}
1525
1526#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Eq)]
1527#[serde_as]
1528#[serde(untagged)]
1529enum AuthorityKeyPairLocation {
1530    InPlace { value: Arc<AuthorityKeyPair> },
1531    File { path: PathBuf },
1532}
1533
1534impl AuthorityKeyPairWithPath {
1535    pub fn new(kp: AuthorityKeyPair) -> Self {
1536        let cell: OnceCell<Arc<AuthorityKeyPair>> = OnceCell::new();
1537        let arc_kp = Arc::new(kp);
1538        // OK to unwrap panic because authority should not start without all keypairs loaded.
1539        cell.set(arc_kp.clone())
1540            .expect("Failed to set authority keypair");
1541        Self {
1542            location: AuthorityKeyPairLocation::InPlace { value: arc_kp },
1543            keypair: cell,
1544        }
1545    }
1546
1547    pub fn new_from_path(path: PathBuf) -> Self {
1548        let cell: OnceCell<Arc<AuthorityKeyPair>> = OnceCell::new();
1549        // OK to unwrap panic because authority should not start without all keypairs loaded.
1550        cell.set(Arc::new(
1551            read_authority_keypair_from_file(&path)
1552                .unwrap_or_else(|_| panic!("Invalid authority keypair file at path {:?}", &path)),
1553        ))
1554        .expect("Failed to set authority keypair");
1555        Self {
1556            location: AuthorityKeyPairLocation::File { path },
1557            keypair: cell,
1558        }
1559    }
1560
1561    pub fn authority_keypair(&self) -> &AuthorityKeyPair {
1562        self.keypair
1563            .get_or_init(|| match &self.location {
1564                AuthorityKeyPairLocation::InPlace { value } => value.clone(),
1565                AuthorityKeyPairLocation::File { path } => {
1566                    // OK to unwrap panic because authority should not start without all keypairs loaded.
1567                    Arc::new(
1568                        read_authority_keypair_from_file(path).unwrap_or_else(|_| {
1569                            panic!("Invalid authority keypair file {:?}", &path)
1570                        }),
1571                    )
1572                }
1573            })
1574            .as_ref()
1575    }
1576}
1577
1578/// Configurations which determine how we dump state debug info.
1579/// Debug info is dumped when a node forks.
1580#[derive(Clone, Debug, Deserialize, Serialize, Default)]
1581#[serde(rename_all = "kebab-case")]
1582pub struct StateDebugDumpConfig {
1583    #[serde(skip_serializing_if = "Option::is_none")]
1584    pub dump_file_directory: Option<PathBuf>,
1585}
1586
1587fn read_credential_from_path_or_literal(value: &str) -> Result<String, std::io::Error> {
1588    let path = Path::new(value);
1589    if path.exists() && path.is_file() {
1590        std::fs::read_to_string(path).map(|content| content.trim().to_string())
1591    } else {
1592        Ok(value.to_string())
1593    }
1594}
1595
1596// Custom deserializer for remote store options that supports file paths or literal values
1597fn deserialize_remote_store_options<'de, D>(
1598    deserializer: D,
1599) -> Result<Vec<(String, String)>, D::Error>
1600where
1601    D: serde::Deserializer<'de>,
1602{
1603    use serde::de::Error;
1604
1605    let raw_options: Vec<(String, String)> = Vec::deserialize(deserializer)?;
1606    let mut processed_options = Vec::new();
1607
1608    for (key, value) in raw_options {
1609        // GCS service_account keys expect a file path, not the file content
1610        // All other keys (AWS credentials, service_account_key) should read file content
1611        let is_service_account_path = matches!(
1612            key.as_str(),
1613            "google_service_account"
1614                | "service_account"
1615                | "google_service_account_path"
1616                | "service_account_path"
1617        );
1618
1619        let processed_value = if is_service_account_path {
1620            value
1621        } else {
1622            match read_credential_from_path_or_literal(&value) {
1623                Ok(processed) => processed,
1624                Err(e) => {
1625                    return Err(D::Error::custom(format!(
1626                        "Failed to read credential for key '{}': {}",
1627                        key, e
1628                    )));
1629                }
1630            }
1631        };
1632
1633        processed_options.push((key, processed_value));
1634    }
1635
1636    Ok(processed_options)
1637}
1638
1639#[cfg(test)]
1640mod tests {
1641    use std::path::PathBuf;
1642
1643    use fastcrypto::traits::KeyPair;
1644    use rand::{SeedableRng, rngs::StdRng};
1645    use sui_keys::keypair_file::{write_authority_keypair_to_file, write_keypair_to_file};
1646    use sui_types::crypto::{AuthorityKeyPair, NetworkKeyPair, SuiKeyPair, get_key_pair_from_rng};
1647
1648    use super::{Genesis, StateArchiveConfig};
1649    use crate::NodeConfig;
1650
1651    #[test]
1652    fn serialize_genesis_from_file() {
1653        let g = Genesis::new_from_file("path/to/file");
1654
1655        let s = serde_yaml::to_string(&g).unwrap();
1656        assert_eq!("---\ngenesis-file-location: path/to/file\n", s);
1657        let loaded_genesis: Genesis = serde_yaml::from_str(&s).unwrap();
1658        assert_eq!(g, loaded_genesis);
1659    }
1660
1661    #[test]
1662    fn fullnode_template() {
1663        const TEMPLATE: &str = include_str!("../data/fullnode-template.yaml");
1664
1665        let _template: NodeConfig = serde_yaml::from_str(TEMPLATE).unwrap();
1666    }
1667
1668    /// Tests that a legacy validator config (captured on 12/06/2024) can be parsed.
1669    #[test]
1670    fn legacy_validator_config() {
1671        const FILE: &str = include_str!("../data/sui-node-legacy.yaml");
1672
1673        let _template: NodeConfig = serde_yaml::from_str(FILE).unwrap();
1674    }
1675
1676    #[test]
1677    fn load_key_pairs_to_node_config() {
1678        let protocol_key_pair: AuthorityKeyPair =
1679            get_key_pair_from_rng(&mut StdRng::from_seed([0; 32])).1;
1680        let worker_key_pair: NetworkKeyPair =
1681            get_key_pair_from_rng(&mut StdRng::from_seed([0; 32])).1;
1682        let network_key_pair: NetworkKeyPair =
1683            get_key_pair_from_rng(&mut StdRng::from_seed([0; 32])).1;
1684
1685        write_authority_keypair_to_file(&protocol_key_pair, PathBuf::from("protocol.key")).unwrap();
1686        write_keypair_to_file(
1687            &SuiKeyPair::Ed25519(worker_key_pair.copy()),
1688            PathBuf::from("worker.key"),
1689        )
1690        .unwrap();
1691        write_keypair_to_file(
1692            &SuiKeyPair::Ed25519(network_key_pair.copy()),
1693            PathBuf::from("network.key"),
1694        )
1695        .unwrap();
1696
1697        const TEMPLATE: &str = include_str!("../data/fullnode-template-with-path.yaml");
1698        let template: NodeConfig = serde_yaml::from_str(TEMPLATE).unwrap();
1699        assert_eq!(
1700            template.protocol_key_pair().public(),
1701            protocol_key_pair.public()
1702        );
1703        assert_eq!(
1704            template.network_key_pair().public(),
1705            network_key_pair.public()
1706        );
1707        assert_eq!(
1708            template.worker_key_pair().public(),
1709            worker_key_pair.public()
1710        );
1711    }
1712
1713    #[test]
1714    fn test_remote_store_options_file_path_support() {
1715        // Create temporary credential files
1716        let temp_dir = std::env::temp_dir();
1717        let access_key_file = temp_dir.join("test_access_key");
1718        let secret_key_file = temp_dir.join("test_secret_key");
1719
1720        std::fs::write(&access_key_file, "test_access_key_value").unwrap();
1721        std::fs::write(&secret_key_file, "test_secret_key_value\n").unwrap();
1722
1723        let yaml_config = format!(
1724            r#"
1725object-store-config: null
1726concurrency: 5
1727ingestion-url: "https://example.com"
1728remote-store-options:
1729  - ["aws_access_key_id", "{}"]
1730  - ["aws_secret_access_key", "{}"]
1731  - ["literal_key", "literal_value"]
1732"#,
1733            access_key_file.to_string_lossy(),
1734            secret_key_file.to_string_lossy()
1735        );
1736
1737        let config: StateArchiveConfig = serde_yaml::from_str(&yaml_config).unwrap();
1738
1739        // Verify that file paths were resolved and literal values preserved
1740        assert_eq!(config.remote_store_options.len(), 3);
1741
1742        let access_key_option = config
1743            .remote_store_options
1744            .iter()
1745            .find(|(key, _)| key == "aws_access_key_id")
1746            .unwrap();
1747        assert_eq!(access_key_option.1, "test_access_key_value");
1748
1749        let secret_key_option = config
1750            .remote_store_options
1751            .iter()
1752            .find(|(key, _)| key == "aws_secret_access_key")
1753            .unwrap();
1754        assert_eq!(secret_key_option.1, "test_secret_key_value");
1755
1756        let literal_option = config
1757            .remote_store_options
1758            .iter()
1759            .find(|(key, _)| key == "literal_key")
1760            .unwrap();
1761        assert_eq!(literal_option.1, "literal_value");
1762
1763        // Clean up
1764        std::fs::remove_file(&access_key_file).ok();
1765        std::fs::remove_file(&secret_key_file).ok();
1766    }
1767
1768    #[test]
1769    fn test_remote_store_options_literal_values_only() {
1770        let yaml_config = r#"
1771object-store-config: null
1772concurrency: 5
1773ingestion-url: "https://example.com"
1774remote-store-options:
1775  - ["aws_access_key_id", "literal_access_key"]
1776  - ["aws_secret_access_key", "literal_secret_key"]
1777"#;
1778
1779        let config: StateArchiveConfig = serde_yaml::from_str(yaml_config).unwrap();
1780
1781        assert_eq!(config.remote_store_options.len(), 2);
1782        assert_eq!(config.remote_store_options[0].1, "literal_access_key");
1783        assert_eq!(config.remote_store_options[1].1, "literal_secret_key");
1784    }
1785
1786    #[test]
1787    fn test_remote_store_options_gcs_service_account_path_preserved() {
1788        let temp_dir = std::env::temp_dir();
1789        let service_account_file = temp_dir.join("test_service_account.json");
1790        let aws_key_file = temp_dir.join("test_aws_key");
1791
1792        std::fs::write(&service_account_file, r#"{"type": "service_account"}"#).unwrap();
1793        std::fs::write(&aws_key_file, "aws_key_value").unwrap();
1794
1795        let yaml_config = format!(
1796            r#"
1797object-store-config: null
1798concurrency: 5
1799ingestion-url: "gs://my-bucket"
1800remote-store-options:
1801  - ["service_account", "{}"]
1802  - ["google_service_account_path", "{}"]
1803  - ["aws_access_key_id", "{}"]
1804"#,
1805            service_account_file.to_string_lossy(),
1806            service_account_file.to_string_lossy(),
1807            aws_key_file.to_string_lossy()
1808        );
1809
1810        let config: StateArchiveConfig = serde_yaml::from_str(&yaml_config).unwrap();
1811
1812        assert_eq!(config.remote_store_options.len(), 3);
1813
1814        // service_account should preserve the file path, not read the content
1815        let service_account_option = config
1816            .remote_store_options
1817            .iter()
1818            .find(|(key, _)| key == "service_account")
1819            .unwrap();
1820        assert_eq!(
1821            service_account_option.1,
1822            service_account_file.to_string_lossy()
1823        );
1824
1825        // google_service_account_path should also preserve the file path
1826        let gcs_path_option = config
1827            .remote_store_options
1828            .iter()
1829            .find(|(key, _)| key == "google_service_account_path")
1830            .unwrap();
1831        assert_eq!(gcs_path_option.1, service_account_file.to_string_lossy());
1832
1833        // AWS key should read the file content
1834        let aws_option = config
1835            .remote_store_options
1836            .iter()
1837            .find(|(key, _)| key == "aws_access_key_id")
1838            .unwrap();
1839        assert_eq!(aws_option.1, "aws_key_value");
1840
1841        // Clean up
1842        std::fs::remove_file(&service_account_file).ok();
1843        std::fs::remove_file(&aws_key_file).ok();
1844    }
1845}
1846
1847// RunWithRange is used to specify the ending epoch/checkpoint to process.
1848// this is intended for use with disaster recovery debugging and verification workflows, never in normal operations
1849#[derive(Clone, Copy, PartialEq, Debug, Serialize, Deserialize)]
1850pub enum RunWithRange {
1851    Epoch(EpochId),
1852    Checkpoint(CheckpointSequenceNumber),
1853}
1854
1855impl RunWithRange {
1856    // is epoch_id > RunWithRange::Epoch
1857    pub fn is_epoch_gt(&self, epoch_id: EpochId) -> bool {
1858        matches!(self, RunWithRange::Epoch(e) if epoch_id > *e)
1859    }
1860
1861    pub fn matches_checkpoint(&self, seq_num: CheckpointSequenceNumber) -> bool {
1862        matches!(self, RunWithRange::Checkpoint(seq) if *seq == seq_num)
1863    }
1864
1865    pub fn into_checkpoint_bound(self) -> Option<CheckpointSequenceNumber> {
1866        match self {
1867            RunWithRange::Epoch(_) => None,
1868            RunWithRange::Checkpoint(seq) => Some(seq),
1869        }
1870    }
1871}