1use 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
40pub const DEFAULT_GRPC_CONCURRENCY_LIMIT: usize = 20000000000;
42
43pub const DEFAULT_VALIDATOR_GAS_PRICE: u64 = sui_types::transaction::DEFAULT_VALIDATOR_GAS_PRICE;
45
46pub const DEFAULT_COMMISSION_RATE: u64 = 200;
48
49#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
51pub enum FundsWithdrawSchedulerType {
52 Naive,
53 #[default]
54 Eager,
55}
56
57#[serde_as]
58#[derive(Clone, Debug, Deserialize, Serialize)]
59#[serde(rename_all = "kebab-case")]
60pub struct NodeConfig {
61 #[serde(default = "default_authority_key_pair")]
62 pub protocol_key_pair: AuthorityKeyPairWithPath,
63 #[serde(default = "default_key_pair")]
64 pub worker_key_pair: KeyPairWithPath,
65 #[serde(default = "default_key_pair")]
66 pub account_key_pair: KeyPairWithPath,
67 #[serde(default = "default_key_pair")]
68 pub network_key_pair: KeyPairWithPath,
69
70 pub db_path: PathBuf,
71 #[serde(default = "default_grpc_address")]
72 pub network_address: Multiaddr,
73 #[serde(default = "default_json_rpc_address")]
74 pub json_rpc_address: SocketAddr,
75
76 #[serde(skip_serializing_if = "Option::is_none")]
77 pub rpc: Option<crate::RpcConfig>,
78
79 #[serde(default = "default_metrics_address")]
80 pub metrics_address: SocketAddr,
81 #[serde(default = "default_admin_interface_port")]
82 pub admin_interface_port: u16,
83
84 #[serde(skip_serializing_if = "Option::is_none")]
85 pub consensus_config: Option<ConsensusConfig>,
86
87 #[serde(default = "default_enable_index_processing")]
88 pub enable_index_processing: bool,
89
90 #[serde(default)]
95 pub sync_post_process_one_tx: bool,
96
97 #[serde(default, skip_serializing_if = "std::ops::Not::not")]
98 pub remove_deprecated_tables: bool,
99
100 #[serde(default)]
101 pub jsonrpc_server_type: Option<ServerType>,
106
107 #[serde(default)]
108 pub grpc_load_shed: Option<bool>,
109
110 #[serde(default = "default_concurrency_limit")]
111 pub grpc_concurrency_limit: Option<usize>,
112
113 #[serde(default)]
114 pub p2p_config: P2pConfig,
115
116 pub genesis: Genesis,
117
118 #[serde(default = "default_authority_store_pruning_config")]
119 pub authority_store_pruning_config: AuthorityStorePruningConfig,
120
121 #[serde(default = "default_end_of_epoch_broadcast_channel_capacity")]
125 pub end_of_epoch_broadcast_channel_capacity: usize,
126
127 #[serde(default)]
128 pub checkpoint_executor_config: CheckpointExecutorConfig,
129
130 #[serde(skip_serializing_if = "Option::is_none")]
131 pub metrics: Option<MetricsConfig>,
132
133 #[serde(skip)]
137 pub supported_protocol_versions: Option<SupportedProtocolVersions>,
138
139 #[serde(default)]
140 pub db_checkpoint_config: DBCheckpointConfig,
141
142 #[serde(default)]
143 pub expensive_safety_check_config: ExpensiveSafetyCheckConfig,
144
145 #[serde(skip_serializing_if = "Option::is_none")]
146 pub name_service_package_address: Option<SuiAddress>,
147
148 #[serde(skip_serializing_if = "Option::is_none")]
149 pub name_service_registry_id: Option<ObjectID>,
150
151 #[serde(skip_serializing_if = "Option::is_none")]
152 pub name_service_reverse_registry_id: Option<ObjectID>,
153
154 #[serde(default)]
155 pub transaction_deny_config: TransactionDenyConfig,
156
157 #[serde(default)]
159 pub dev_inspect_disabled: bool,
160
161 #[serde(default)]
162 pub certificate_deny_config: CertificateDenyConfig,
163
164 #[serde(default)]
165 pub state_debug_dump_config: StateDebugDumpConfig,
166
167 #[serde(default)]
168 pub state_archive_read_config: Vec<StateArchiveConfig>,
169
170 #[serde(default)]
171 pub state_snapshot_write_config: StateSnapshotConfig,
172
173 #[serde(default)]
174 pub indexer_max_subscriptions: Option<usize>,
175
176 #[serde(default = "default_transaction_kv_store_config")]
177 pub transaction_kv_store_read_config: TransactionKeyValueStoreReadConfig,
178
179 #[serde(skip_serializing_if = "Option::is_none")]
180 pub transaction_kv_store_write_config: Option<TransactionKeyValueStoreWriteConfig>,
181
182 #[serde(default = "default_jwk_fetch_interval_seconds")]
183 pub jwk_fetch_interval_seconds: u64,
184
185 #[serde(default = "default_zklogin_oauth_providers")]
186 pub zklogin_oauth_providers: BTreeMap<Chain, BTreeSet<String>>,
187
188 #[serde(default = "default_authority_overload_config")]
189 pub authority_overload_config: AuthorityOverloadConfig,
190
191 #[serde(skip_serializing_if = "Option::is_none")]
192 pub run_with_range: Option<RunWithRange>,
193
194 #[serde(
196 skip_serializing_if = "Option::is_none",
197 default = "default_traffic_controller_policy_config"
198 )]
199 pub policy_config: Option<PolicyConfig>,
200
201 #[serde(skip_serializing_if = "Option::is_none")]
202 pub firewall_config: Option<RemoteFirewallConfig>,
203
204 #[serde(default)]
205 pub execution_cache: ExecutionCacheConfig,
206
207 #[serde(skip)]
209 #[serde(default = "bool_true")]
210 pub state_accumulator_v2: bool,
211
212 #[serde(skip)]
215 #[serde(default)]
216 pub funds_withdraw_scheduler_type: FundsWithdrawSchedulerType,
217
218 #[serde(default = "bool_true")]
219 pub enable_soft_bundle: bool,
220
221 #[serde(default)]
222 pub verifier_signing_config: VerifierSigningConfig,
223
224 #[serde(skip_serializing_if = "Option::is_none")]
227 pub enable_db_write_stall: Option<bool>,
228
229 #[serde(skip_serializing_if = "Option::is_none")]
233 pub enable_db_sync_to_disk: Option<bool>,
234
235 #[serde(skip_serializing_if = "Option::is_none")]
236 pub execution_time_observer_config: Option<ExecutionTimeObserverConfig>,
237
238 #[serde(skip_serializing_if = "Option::is_none")]
242 pub chain_override_for_testing: Option<Chain>,
243
244 #[serde(skip_serializing_if = "Option::is_none")]
247 pub validator_client_monitor_config: Option<ValidatorClientMonitorConfig>,
248
249 #[serde(skip_serializing_if = "Option::is_none")]
251 pub fork_recovery: Option<ForkRecoveryConfig>,
252
253 #[serde(skip_serializing_if = "Option::is_none")]
255 pub transaction_driver_config: Option<TransactionDriverConfig>,
256
257 #[serde(skip_serializing_if = "Option::is_none")]
260 pub congestion_log: Option<CongestionLogConfig>,
261}
262
263#[derive(Clone, Debug, Deserialize, Serialize)]
264#[serde(rename_all = "kebab-case")]
265pub struct TransactionDriverConfig {
266 #[serde(default, skip_serializing_if = "Vec::is_empty")]
269 pub allowed_submission_validators: Vec<String>,
270
271 #[serde(default, skip_serializing_if = "Vec::is_empty")]
274 pub blocked_submission_validators: Vec<String>,
275
276 #[serde(default = "bool_true")]
281 pub enable_early_validation: bool,
282}
283
284impl Default for TransactionDriverConfig {
285 fn default() -> Self {
286 Self {
287 allowed_submission_validators: vec![],
288 blocked_submission_validators: vec![],
289 enable_early_validation: true,
290 }
291 }
292}
293
294#[derive(Clone, Debug, Deserialize, Serialize)]
295#[serde(rename_all = "kebab-case")]
296pub struct CongestionLogConfig {
297 pub path: PathBuf,
298 #[serde(default = "default_congestion_log_max_file_size")]
299 pub max_file_size: u64,
300 #[serde(default = "default_congestion_log_max_files")]
301 pub max_files: u32,
302}
303
304fn default_congestion_log_max_file_size() -> u64 {
305 100 * 1024 * 1024 }
307
308fn default_congestion_log_max_files() -> u32 {
309 10
310}
311
312#[derive(Debug, Clone, Copy, Default, Deserialize, Serialize, PartialEq, Eq)]
313#[serde(rename_all = "kebab-case")]
314pub enum ForkCrashBehavior {
315 #[serde(rename = "await-fork-recovery")]
316 #[default]
317 AwaitForkRecovery,
318 #[serde(rename = "return-error")]
320 ReturnError,
321}
322
323#[derive(Clone, Debug, Default, Deserialize, Serialize)]
324#[serde(rename_all = "kebab-case")]
325pub struct ForkRecoveryConfig {
326 #[serde(default)]
329 pub transaction_overrides: BTreeMap<String, String>,
330
331 #[serde(default)]
335 pub checkpoint_overrides: BTreeMap<u64, String>,
336
337 #[serde(default)]
339 pub fork_crash_behavior: ForkCrashBehavior,
340}
341
342#[derive(Clone, Debug, Default, Deserialize, Serialize)]
343#[serde(rename_all = "kebab-case")]
344pub struct ExecutionTimeObserverConfig {
345 pub observation_channel_capacity: Option<NonZeroUsize>,
349
350 pub observation_cache_size: Option<NonZeroUsize>,
354
355 pub object_debt_channel_capacity: Option<NonZeroUsize>,
359
360 pub object_utilization_cache_size: Option<NonZeroUsize>,
364
365 pub report_object_utilization_metric_with_full_id: Option<bool>,
376
377 pub observation_sharing_object_utilization_threshold: Option<Duration>,
382
383 pub observation_sharing_diff_threshold: Option<f64>,
388
389 pub observation_sharing_min_interval: Option<Duration>,
393
394 pub observation_sharing_rate_limit: Option<NonZeroU32>,
399
400 pub observation_sharing_burst_limit: Option<NonZeroU32>,
404
405 pub enable_gas_price_weighting: Option<bool>,
412
413 pub weighted_moving_average_window_size: Option<usize>,
420
421 #[cfg(msim)]
427 pub inject_synthetic_execution_time: Option<bool>,
428}
429
430impl ExecutionTimeObserverConfig {
431 pub fn observation_channel_capacity(&self) -> NonZeroUsize {
432 self.observation_channel_capacity
433 .unwrap_or(nonzero!(1_024usize))
434 }
435
436 pub fn observation_cache_size(&self) -> NonZeroUsize {
437 self.observation_cache_size.unwrap_or(nonzero!(10_000usize))
438 }
439
440 pub fn object_debt_channel_capacity(&self) -> NonZeroUsize {
441 self.object_debt_channel_capacity
442 .unwrap_or(nonzero!(128usize))
443 }
444
445 pub fn object_utilization_cache_size(&self) -> NonZeroUsize {
446 self.object_utilization_cache_size
447 .unwrap_or(nonzero!(50_000usize))
448 }
449
450 pub fn report_object_utilization_metric_with_full_id(&self) -> bool {
451 self.report_object_utilization_metric_with_full_id
452 .unwrap_or(false)
453 }
454
455 pub fn observation_sharing_object_utilization_threshold(&self) -> Duration {
456 self.observation_sharing_object_utilization_threshold
457 .unwrap_or(Duration::from_millis(500))
458 }
459
460 pub fn observation_sharing_diff_threshold(&self) -> f64 {
461 self.observation_sharing_diff_threshold.unwrap_or(0.1)
462 }
463
464 pub fn observation_sharing_min_interval(&self) -> Duration {
465 self.observation_sharing_min_interval
466 .unwrap_or(Duration::from_secs(5))
467 }
468
469 pub fn observation_sharing_rate_limit(&self) -> NonZeroU32 {
470 self.observation_sharing_rate_limit
471 .unwrap_or(nonzero!(10u32))
472 }
473
474 pub fn observation_sharing_burst_limit(&self) -> NonZeroU32 {
475 self.observation_sharing_burst_limit
476 .unwrap_or(nonzero!(100u32))
477 }
478
479 pub fn enable_gas_price_weighting(&self) -> bool {
480 self.enable_gas_price_weighting.unwrap_or(false)
481 }
482
483 pub fn weighted_moving_average_window_size(&self) -> usize {
484 self.weighted_moving_average_window_size.unwrap_or(20)
485 }
486
487 #[cfg(msim)]
488 pub fn inject_synthetic_execution_time(&self) -> bool {
489 self.inject_synthetic_execution_time.unwrap_or(false)
490 }
491}
492
493#[allow(clippy::large_enum_variant)]
494#[derive(Clone, Debug, Deserialize, Serialize)]
495#[serde(rename_all = "kebab-case")]
496pub enum ExecutionCacheConfig {
497 PassthroughCache,
498 WritebackCache {
499 max_cache_size: Option<u64>,
502
503 package_cache_size: Option<u64>, object_cache_size: Option<u64>, marker_cache_size: Option<u64>, object_by_id_cache_size: Option<u64>, transaction_cache_size: Option<u64>, executed_effect_cache_size: Option<u64>, effect_cache_size: Option<u64>, events_cache_size: Option<u64>, transaction_objects_cache_size: Option<u64>, backpressure_threshold: Option<u64>,
519
520 backpressure_threshold_for_rpc: Option<u64>,
523 },
524}
525
526impl Default for ExecutionCacheConfig {
527 fn default() -> Self {
528 ExecutionCacheConfig::WritebackCache {
529 max_cache_size: None,
530 backpressure_threshold: None,
531 backpressure_threshold_for_rpc: None,
532 package_cache_size: None,
533 object_cache_size: None,
534 marker_cache_size: None,
535 object_by_id_cache_size: None,
536 transaction_cache_size: None,
537 executed_effect_cache_size: None,
538 effect_cache_size: None,
539 events_cache_size: None,
540 transaction_objects_cache_size: None,
541 }
542 }
543}
544
545impl ExecutionCacheConfig {
546 pub fn max_cache_size(&self) -> u64 {
547 std::env::var("SUI_MAX_CACHE_SIZE")
548 .ok()
549 .and_then(|s| s.parse().ok())
550 .unwrap_or_else(|| match self {
551 ExecutionCacheConfig::PassthroughCache => fatal!("invalid cache config"),
552 ExecutionCacheConfig::WritebackCache { max_cache_size, .. } => {
553 max_cache_size.unwrap_or(100000)
554 }
555 })
556 }
557
558 pub fn package_cache_size(&self) -> u64 {
559 std::env::var("SUI_PACKAGE_CACHE_SIZE")
560 .ok()
561 .and_then(|s| s.parse().ok())
562 .unwrap_or_else(|| match self {
563 ExecutionCacheConfig::PassthroughCache => fatal!("invalid cache config"),
564 ExecutionCacheConfig::WritebackCache {
565 package_cache_size, ..
566 } => package_cache_size.unwrap_or(1000),
567 })
568 }
569
570 pub fn object_cache_size(&self) -> u64 {
571 std::env::var("SUI_OBJECT_CACHE_SIZE")
572 .ok()
573 .and_then(|s| s.parse().ok())
574 .unwrap_or_else(|| match self {
575 ExecutionCacheConfig::PassthroughCache => fatal!("invalid cache config"),
576 ExecutionCacheConfig::WritebackCache {
577 object_cache_size, ..
578 } => object_cache_size.unwrap_or(self.max_cache_size()),
579 })
580 }
581
582 pub fn marker_cache_size(&self) -> u64 {
583 std::env::var("SUI_MARKER_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 marker_cache_size, ..
590 } => marker_cache_size.unwrap_or(self.object_cache_size()),
591 })
592 }
593
594 pub fn object_by_id_cache_size(&self) -> u64 {
595 std::env::var("SUI_OBJECT_BY_ID_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 object_by_id_cache_size,
602 ..
603 } => object_by_id_cache_size.unwrap_or(self.object_cache_size()),
604 })
605 }
606
607 pub fn transaction_cache_size(&self) -> u64 {
608 std::env::var("SUI_TRANSACTION_CACHE_SIZE")
609 .ok()
610 .and_then(|s| s.parse().ok())
611 .unwrap_or_else(|| match self {
612 ExecutionCacheConfig::PassthroughCache => fatal!("invalid cache config"),
613 ExecutionCacheConfig::WritebackCache {
614 transaction_cache_size,
615 ..
616 } => transaction_cache_size.unwrap_or(self.max_cache_size()),
617 })
618 }
619
620 pub fn executed_effect_cache_size(&self) -> u64 {
621 std::env::var("SUI_EXECUTED_EFFECT_CACHE_SIZE")
622 .ok()
623 .and_then(|s| s.parse().ok())
624 .unwrap_or_else(|| match self {
625 ExecutionCacheConfig::PassthroughCache => fatal!("invalid cache config"),
626 ExecutionCacheConfig::WritebackCache {
627 executed_effect_cache_size,
628 ..
629 } => executed_effect_cache_size.unwrap_or(self.transaction_cache_size()),
630 })
631 }
632
633 pub fn effect_cache_size(&self) -> u64 {
634 std::env::var("SUI_EFFECT_CACHE_SIZE")
635 .ok()
636 .and_then(|s| s.parse().ok())
637 .unwrap_or_else(|| match self {
638 ExecutionCacheConfig::PassthroughCache => fatal!("invalid cache config"),
639 ExecutionCacheConfig::WritebackCache {
640 effect_cache_size, ..
641 } => effect_cache_size.unwrap_or(self.executed_effect_cache_size()),
642 })
643 }
644
645 pub fn events_cache_size(&self) -> u64 {
646 std::env::var("SUI_EVENTS_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 events_cache_size, ..
653 } => events_cache_size.unwrap_or(self.transaction_cache_size()),
654 })
655 }
656
657 pub fn transaction_objects_cache_size(&self) -> u64 {
658 std::env::var("SUI_TRANSACTION_OBJECTS_CACHE_SIZE")
659 .ok()
660 .and_then(|s| s.parse().ok())
661 .unwrap_or_else(|| match self {
662 ExecutionCacheConfig::PassthroughCache => fatal!("invalid cache config"),
663 ExecutionCacheConfig::WritebackCache {
664 transaction_objects_cache_size,
665 ..
666 } => transaction_objects_cache_size.unwrap_or(1000),
667 })
668 }
669
670 pub fn backpressure_threshold(&self) -> u64 {
671 std::env::var("SUI_BACKPRESSURE_THRESHOLD")
672 .ok()
673 .and_then(|s| s.parse().ok())
674 .unwrap_or_else(|| match self {
675 ExecutionCacheConfig::PassthroughCache => fatal!("invalid cache config"),
676 ExecutionCacheConfig::WritebackCache {
677 backpressure_threshold,
678 ..
679 } => backpressure_threshold.unwrap_or(100_000),
680 })
681 }
682
683 pub fn backpressure_threshold_for_rpc(&self) -> u64 {
684 std::env::var("SUI_BACKPRESSURE_THRESHOLD_FOR_RPC")
685 .ok()
686 .and_then(|s| s.parse().ok())
687 .unwrap_or_else(|| match self {
688 ExecutionCacheConfig::PassthroughCache => fatal!("invalid cache config"),
689 ExecutionCacheConfig::WritebackCache {
690 backpressure_threshold_for_rpc,
691 ..
692 } => backpressure_threshold_for_rpc.unwrap_or(self.backpressure_threshold()),
693 })
694 }
695}
696
697#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
698#[serde(rename_all = "lowercase")]
699pub enum ServerType {
700 WebSocket,
701 Http,
702 Both,
703}
704
705#[derive(Clone, Debug, Deserialize, Serialize)]
706#[serde(rename_all = "kebab-case")]
707pub struct TransactionKeyValueStoreReadConfig {
708 #[serde(default = "default_base_url")]
709 pub base_url: String,
710
711 #[serde(default = "default_cache_size")]
712 pub cache_size: u64,
713}
714
715impl Default for TransactionKeyValueStoreReadConfig {
716 fn default() -> Self {
717 Self {
718 base_url: default_base_url(),
719 cache_size: default_cache_size(),
720 }
721 }
722}
723
724fn default_base_url() -> String {
725 "https://transactions.sui.io/".to_string()
726}
727
728fn default_cache_size() -> u64 {
729 100_000
730}
731
732fn default_jwk_fetch_interval_seconds() -> u64 {
733 3600
734}
735
736pub fn default_zklogin_oauth_providers() -> BTreeMap<Chain, BTreeSet<String>> {
737 let mut map = BTreeMap::new();
738
739 let experimental_providers = BTreeSet::from([
741 "Google".to_string(),
742 "Facebook".to_string(),
743 "Twitch".to_string(),
744 "Kakao".to_string(),
745 "Apple".to_string(),
746 "Slack".to_string(),
747 "TestIssuer".to_string(),
748 "Microsoft".to_string(),
749 "KarrierOne".to_string(),
750 "Credenza3".to_string(),
751 "Playtron".to_string(),
752 "Threedos".to_string(),
753 "Onefc".to_string(),
754 "FanTV".to_string(),
755 "Arden".to_string(), "AwsTenant-region:eu-west-3-tenant_id:eu-west-3_gGVCx53Es".to_string(), "EveFrontier".to_string(),
758 "TestEveFrontier".to_string(),
759 "AwsTenant-region:ap-southeast-1-tenant_id:ap-southeast-1_2QQPyQXDz".to_string(), "AwsTenant-region:eu-north-1-tenant_id:eu-north-1_Bpct2JyBg".to_string(), "AwsTenant-region:eu-north-1-tenant_id:eu-north-1_4HdQTpt3E".to_string(), ]);
763
764 let providers = BTreeSet::from([
766 "Google".to_string(),
767 "Facebook".to_string(),
768 "Twitch".to_string(),
769 "Apple".to_string(),
770 "KarrierOne".to_string(),
771 "Credenza3".to_string(),
772 "Playtron".to_string(),
773 "Onefc".to_string(),
774 "Threedos".to_string(),
775 "AwsTenant-region:eu-west-3-tenant_id:eu-west-3_gGVCx53Es".to_string(), "Arden".to_string(),
777 "FanTV".to_string(),
778 "EveFrontier".to_string(),
779 "TestEveFrontier".to_string(),
780 "AwsTenant-region:ap-southeast-1-tenant_id:ap-southeast-1_2QQPyQXDz".to_string(), "AwsTenant-region:eu-north-1-tenant_id:eu-north-1_Bpct2JyBg".to_string(), "AwsTenant-region:eu-north-1-tenant_id:eu-north-1_4HdQTpt3E".to_string(), ]);
784 map.insert(Chain::Mainnet, providers.clone());
785 map.insert(Chain::Testnet, providers);
786 map.insert(Chain::Unknown, experimental_providers);
787 map
788}
789
790fn default_transaction_kv_store_config() -> TransactionKeyValueStoreReadConfig {
791 TransactionKeyValueStoreReadConfig::default()
792}
793
794fn default_authority_store_pruning_config() -> AuthorityStorePruningConfig {
795 AuthorityStorePruningConfig::default()
796}
797
798pub fn default_enable_index_processing() -> bool {
799 true
800}
801
802fn default_grpc_address() -> Multiaddr {
803 "/ip4/0.0.0.0/tcp/8080".parse().unwrap()
804}
805fn default_authority_key_pair() -> AuthorityKeyPairWithPath {
806 AuthorityKeyPairWithPath::new(get_key_pair_from_rng::<AuthorityKeyPair, _>(&mut OsRng).1)
807}
808
809fn default_key_pair() -> KeyPairWithPath {
810 KeyPairWithPath::new(
811 get_key_pair_from_rng::<AccountKeyPair, _>(&mut OsRng)
812 .1
813 .into(),
814 )
815}
816
817fn default_metrics_address() -> SocketAddr {
818 use std::net::{IpAddr, Ipv4Addr};
819 SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 9184)
820}
821
822pub fn default_admin_interface_port() -> u16 {
823 1337
824}
825
826pub fn default_json_rpc_address() -> SocketAddr {
827 use std::net::{IpAddr, Ipv4Addr};
828 SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 9000)
829}
830
831pub fn default_concurrency_limit() -> Option<usize> {
832 Some(DEFAULT_GRPC_CONCURRENCY_LIMIT)
833}
834
835pub fn default_end_of_epoch_broadcast_channel_capacity() -> usize {
836 128
837}
838
839pub fn bool_true() -> bool {
840 true
841}
842
843fn is_true(value: &bool) -> bool {
844 *value
845}
846
847impl Config for NodeConfig {}
848
849impl NodeConfig {
850 pub fn protocol_key_pair(&self) -> &AuthorityKeyPair {
851 self.protocol_key_pair.authority_keypair()
852 }
853
854 pub fn worker_key_pair(&self) -> &NetworkKeyPair {
855 match self.worker_key_pair.keypair() {
856 SuiKeyPair::Ed25519(kp) => kp,
857 other => panic!(
858 "Invalid keypair type: {:?}, only Ed25519 is allowed for worker key",
859 other
860 ),
861 }
862 }
863
864 pub fn network_key_pair(&self) -> &NetworkKeyPair {
865 match self.network_key_pair.keypair() {
866 SuiKeyPair::Ed25519(kp) => kp,
867 other => panic!(
868 "Invalid keypair type: {:?}, only Ed25519 is allowed for network key",
869 other
870 ),
871 }
872 }
873
874 pub fn protocol_public_key(&self) -> AuthorityPublicKeyBytes {
875 self.protocol_key_pair().public().into()
876 }
877
878 pub fn db_path(&self) -> PathBuf {
879 self.db_path.join("live")
880 }
881
882 pub fn db_checkpoint_path(&self) -> PathBuf {
883 self.db_path.join("db_checkpoints")
884 }
885
886 pub fn archive_path(&self) -> PathBuf {
887 self.db_path.join("archive")
888 }
889
890 pub fn snapshot_path(&self) -> PathBuf {
891 self.db_path.join("snapshot")
892 }
893
894 pub fn network_address(&self) -> &Multiaddr {
895 &self.network_address
896 }
897
898 pub fn consensus_config(&self) -> Option<&ConsensusConfig> {
899 self.consensus_config.as_ref()
900 }
901
902 pub fn genesis(&self) -> Result<&genesis::Genesis> {
903 self.genesis.genesis()
904 }
905
906 pub fn sui_address(&self) -> SuiAddress {
907 (&self.account_key_pair.keypair().public()).into()
908 }
909
910 pub fn archive_reader_config(&self) -> Option<ArchiveReaderConfig> {
911 self.state_archive_read_config
912 .first()
913 .map(|config| ArchiveReaderConfig {
914 ingestion_url: config.ingestion_url.clone(),
915 remote_store_options: config.remote_store_options.clone(),
916 download_concurrency: NonZeroUsize::new(config.concurrency)
917 .unwrap_or(NonZeroUsize::new(5).unwrap()),
918 remote_store_config: ObjectStoreConfig::default(),
919 })
920 }
921
922 pub fn jsonrpc_server_type(&self) -> ServerType {
923 self.jsonrpc_server_type.unwrap_or(ServerType::Http)
924 }
925
926 pub fn rpc(&self) -> Option<&crate::RpcConfig> {
927 self.rpc.as_ref()
928 }
929}
930
931#[derive(Debug, Clone, Deserialize, Serialize)]
932pub enum ConsensusProtocol {
933 #[serde(rename = "narwhal")]
934 Narwhal,
935 #[serde(rename = "mysticeti")]
936 Mysticeti,
937}
938
939#[derive(Debug, Clone, Deserialize, Serialize)]
940#[serde(rename_all = "kebab-case")]
941pub struct ConsensusConfig {
942 pub db_path: PathBuf,
944
945 pub db_retention_epochs: Option<u64>,
948
949 pub db_pruner_period_secs: Option<u64>,
952
953 pub max_pending_transactions: Option<usize>,
957
958 pub parameters: Option<ConsensusParameters>,
959
960 #[serde(skip_serializing_if = "Option::is_none")]
964 pub listen_address: Option<Multiaddr>,
965
966 #[serde(skip_serializing_if = "Option::is_none")]
971 pub external_address: Option<Multiaddr>,
972}
973
974impl ConsensusConfig {
975 pub fn db_path(&self) -> &Path {
976 &self.db_path
977 }
978
979 pub fn max_pending_transactions(&self) -> usize {
980 self.max_pending_transactions.unwrap_or(20_000)
981 }
982
983 pub fn db_retention_epochs(&self) -> u64 {
984 self.db_retention_epochs.unwrap_or(0)
985 }
986
987 pub fn db_pruner_period(&self) -> Duration {
988 self.db_pruner_period_secs
990 .map(Duration::from_secs)
991 .unwrap_or(Duration::from_secs(3_600))
992 }
993}
994
995#[derive(Clone, Debug, Deserialize, Serialize)]
996#[serde(rename_all = "kebab-case")]
997pub struct CheckpointExecutorConfig {
998 #[serde(default = "default_checkpoint_execution_max_concurrency")]
1002 pub checkpoint_execution_max_concurrency: usize,
1003
1004 #[serde(default = "default_local_execution_timeout_sec")]
1010 pub local_execution_timeout_sec: u64,
1011
1012 #[serde(default, skip_serializing_if = "Option::is_none")]
1015 pub data_ingestion_dir: Option<PathBuf>,
1016}
1017
1018#[derive(Clone, Debug, Default, Deserialize, Serialize)]
1019#[serde(rename_all = "kebab-case")]
1020pub struct ExpensiveSafetyCheckConfig {
1021 #[serde(default)]
1026 enable_epoch_sui_conservation_check: bool,
1027
1028 #[serde(default)]
1032 enable_deep_per_tx_sui_conservation_check: bool,
1033
1034 #[serde(default)]
1036 force_disable_epoch_sui_conservation_check: bool,
1037
1038 #[serde(default)]
1041 enable_state_consistency_check: bool,
1042
1043 #[serde(default)]
1045 force_disable_state_consistency_check: bool,
1046
1047 #[serde(default)]
1048 enable_secondary_index_checks: bool,
1049 }
1051
1052impl ExpensiveSafetyCheckConfig {
1053 pub fn new_enable_all() -> Self {
1054 Self {
1055 enable_epoch_sui_conservation_check: true,
1056 enable_deep_per_tx_sui_conservation_check: true,
1057 force_disable_epoch_sui_conservation_check: false,
1058 enable_state_consistency_check: true,
1059 force_disable_state_consistency_check: false,
1060 enable_secondary_index_checks: false, }
1062 }
1063
1064 pub fn new_enable_all_with_secondary_index_checks() -> Self {
1065 Self {
1066 enable_secondary_index_checks: true,
1067 ..Self::new_enable_all()
1068 }
1069 }
1070
1071 pub fn new_disable_all() -> Self {
1072 Self {
1073 enable_epoch_sui_conservation_check: false,
1074 enable_deep_per_tx_sui_conservation_check: false,
1075 force_disable_epoch_sui_conservation_check: true,
1076 enable_state_consistency_check: false,
1077 force_disable_state_consistency_check: true,
1078 enable_secondary_index_checks: false,
1079 }
1080 }
1081
1082 pub fn force_disable_epoch_sui_conservation_check(&mut self) {
1083 self.force_disable_epoch_sui_conservation_check = true;
1084 }
1085
1086 pub fn enable_epoch_sui_conservation_check(&self) -> bool {
1087 (self.enable_epoch_sui_conservation_check || cfg!(debug_assertions))
1088 && !self.force_disable_epoch_sui_conservation_check
1089 }
1090
1091 pub fn force_disable_state_consistency_check(&mut self) {
1092 self.force_disable_state_consistency_check = true;
1093 }
1094
1095 pub fn enable_state_consistency_check(&self) -> bool {
1096 (self.enable_state_consistency_check || cfg!(debug_assertions))
1097 && !self.force_disable_state_consistency_check
1098 }
1099
1100 pub fn enable_deep_per_tx_sui_conservation_check(&self) -> bool {
1101 self.enable_deep_per_tx_sui_conservation_check || cfg!(debug_assertions)
1102 }
1103
1104 pub fn enable_secondary_index_checks(&self) -> bool {
1105 self.enable_secondary_index_checks
1106 }
1107}
1108
1109fn default_checkpoint_execution_max_concurrency() -> usize {
1110 4
1111}
1112
1113fn default_local_execution_timeout_sec() -> u64 {
1114 30
1115}
1116
1117impl Default for CheckpointExecutorConfig {
1118 fn default() -> Self {
1119 Self {
1120 checkpoint_execution_max_concurrency: default_checkpoint_execution_max_concurrency(),
1121 local_execution_timeout_sec: default_local_execution_timeout_sec(),
1122 data_ingestion_dir: None,
1123 }
1124 }
1125}
1126
1127#[derive(Debug, Clone, Deserialize, Serialize)]
1128#[serde(rename_all = "kebab-case")]
1129pub struct AuthorityStorePruningConfig {
1130 #[serde(default = "default_num_latest_epoch_dbs_to_retain")]
1132 pub num_latest_epoch_dbs_to_retain: usize,
1133 #[serde(default = "default_epoch_db_pruning_period_secs")]
1135 pub epoch_db_pruning_period_secs: u64,
1136 #[serde(default)]
1141 pub num_epochs_to_retain: u64,
1142 #[serde(skip_serializing_if = "Option::is_none")]
1144 pub pruning_run_delay_seconds: Option<u64>,
1145 #[serde(default = "default_max_checkpoints_in_batch")]
1147 pub max_checkpoints_in_batch: usize,
1148 #[serde(default = "default_max_transactions_in_batch")]
1150 pub max_transactions_in_batch: usize,
1151 #[serde(
1155 default = "default_periodic_compaction_threshold_days",
1156 skip_serializing_if = "Option::is_none"
1157 )]
1158 pub periodic_compaction_threshold_days: Option<usize>,
1159 #[serde(skip_serializing_if = "Option::is_none")]
1161 pub num_epochs_to_retain_for_checkpoints: Option<u64>,
1162 #[serde(default, skip_serializing_if = "std::ops::Not::not")]
1164 pub killswitch_tombstone_pruning: bool,
1165 #[serde(default = "default_smoothing", skip_serializing_if = "is_true")]
1166 pub smooth: bool,
1167 #[serde(skip_serializing_if = "Option::is_none")]
1168 pub num_epochs_to_retain_for_indexes: Option<u64>,
1169}
1170
1171fn default_num_latest_epoch_dbs_to_retain() -> usize {
1172 3
1173}
1174
1175fn default_epoch_db_pruning_period_secs() -> u64 {
1176 3600
1177}
1178
1179fn default_max_transactions_in_batch() -> usize {
1180 1000
1181}
1182
1183fn default_max_checkpoints_in_batch() -> usize {
1184 10
1185}
1186
1187fn default_smoothing() -> bool {
1188 cfg!(not(test))
1189}
1190
1191fn default_periodic_compaction_threshold_days() -> Option<usize> {
1192 Some(1)
1193}
1194
1195impl Default for AuthorityStorePruningConfig {
1196 fn default() -> Self {
1197 Self {
1198 num_latest_epoch_dbs_to_retain: default_num_latest_epoch_dbs_to_retain(),
1199 epoch_db_pruning_period_secs: default_epoch_db_pruning_period_secs(),
1200 num_epochs_to_retain: 0,
1201 pruning_run_delay_seconds: if cfg!(msim) { Some(2) } else { None },
1202 max_checkpoints_in_batch: default_max_checkpoints_in_batch(),
1203 max_transactions_in_batch: default_max_transactions_in_batch(),
1204 periodic_compaction_threshold_days: None,
1205 num_epochs_to_retain_for_checkpoints: if cfg!(msim) { Some(2) } else { None },
1206 killswitch_tombstone_pruning: false,
1207 smooth: true,
1208 num_epochs_to_retain_for_indexes: None,
1209 }
1210 }
1211}
1212
1213impl AuthorityStorePruningConfig {
1214 pub fn set_num_epochs_to_retain(&mut self, num_epochs_to_retain: u64) {
1215 self.num_epochs_to_retain = num_epochs_to_retain;
1216 }
1217
1218 pub fn set_num_epochs_to_retain_for_checkpoints(&mut self, num_epochs_to_retain: Option<u64>) {
1219 self.num_epochs_to_retain_for_checkpoints = num_epochs_to_retain;
1220 }
1221
1222 pub fn num_epochs_to_retain_for_checkpoints(&self) -> Option<u64> {
1223 self.num_epochs_to_retain_for_checkpoints
1224 .map(|n| {
1226 if n < 2 {
1227 info!("num_epochs_to_retain_for_checkpoints must be at least 2, rounding up from {}", n);
1228 2
1229 } else {
1230 n
1231 }
1232 })
1233 }
1234
1235 pub fn set_killswitch_tombstone_pruning(&mut self, killswitch_tombstone_pruning: bool) {
1236 self.killswitch_tombstone_pruning = killswitch_tombstone_pruning;
1237 }
1238}
1239
1240#[derive(Debug, Clone, Deserialize, Serialize)]
1241#[serde(rename_all = "kebab-case")]
1242pub struct MetricsConfig {
1243 #[serde(skip_serializing_if = "Option::is_none")]
1244 pub push_interval_seconds: Option<u64>,
1245 #[serde(skip_serializing_if = "Option::is_none")]
1246 pub push_url: Option<String>,
1247}
1248
1249#[derive(Default, Debug, Clone, Deserialize, Serialize)]
1250#[serde(rename_all = "kebab-case")]
1251pub struct DBCheckpointConfig {
1252 #[serde(default)]
1253 pub perform_db_checkpoints_at_epoch_end: bool,
1254 #[serde(skip_serializing_if = "Option::is_none")]
1255 pub checkpoint_path: Option<PathBuf>,
1256 #[serde(skip_serializing_if = "Option::is_none")]
1257 pub object_store_config: Option<ObjectStoreConfig>,
1258 #[serde(skip_serializing_if = "Option::is_none")]
1259 pub perform_index_db_checkpoints_at_epoch_end: Option<bool>,
1260 #[serde(skip_serializing_if = "Option::is_none")]
1261 pub prune_and_compact_before_upload: Option<bool>,
1262}
1263
1264#[derive(Debug, Clone)]
1265pub struct ArchiveReaderConfig {
1266 pub remote_store_config: ObjectStoreConfig,
1267 pub download_concurrency: NonZeroUsize,
1268 pub ingestion_url: Option<String>,
1269 pub remote_store_options: Vec<(String, String)>,
1270}
1271
1272#[derive(Default, Debug, Clone, Deserialize, Serialize)]
1273#[serde(rename_all = "kebab-case")]
1274pub struct StateArchiveConfig {
1275 #[serde(skip_serializing_if = "Option::is_none")]
1276 pub object_store_config: Option<ObjectStoreConfig>,
1277 pub concurrency: usize,
1278 #[serde(skip_serializing_if = "Option::is_none")]
1279 pub ingestion_url: Option<String>,
1280 #[serde(
1281 skip_serializing_if = "Vec::is_empty",
1282 default,
1283 deserialize_with = "deserialize_remote_store_options"
1284 )]
1285 pub remote_store_options: Vec<(String, String)>,
1286}
1287
1288#[derive(Default, Debug, Clone, Deserialize, Serialize)]
1289#[serde(rename_all = "kebab-case")]
1290pub struct StateSnapshotConfig {
1291 #[serde(skip_serializing_if = "Option::is_none")]
1292 pub object_store_config: Option<ObjectStoreConfig>,
1293 pub concurrency: usize,
1294 #[serde(default)]
1298 pub archive_interval_epochs: u64,
1299}
1300
1301#[derive(Default, Debug, Clone, Deserialize, Serialize)]
1302#[serde(rename_all = "kebab-case")]
1303pub struct TransactionKeyValueStoreWriteConfig {
1304 pub aws_access_key_id: String,
1305 pub aws_secret_access_key: String,
1306 pub aws_region: String,
1307 pub table_name: String,
1308 pub bucket_name: String,
1309 pub concurrency: usize,
1310}
1311
1312#[derive(Clone, Debug, Deserialize, Serialize)]
1317#[serde(rename_all = "kebab-case")]
1318pub struct AuthorityOverloadConfig {
1319 #[serde(default = "default_max_txn_age_in_queue")]
1320 pub max_txn_age_in_queue: Duration,
1321
1322 #[serde(default = "default_overload_monitor_interval")]
1324 pub overload_monitor_interval: Duration,
1325
1326 #[serde(default = "default_execution_queue_latency_soft_limit")]
1328 pub execution_queue_latency_soft_limit: Duration,
1329
1330 #[serde(default = "default_execution_queue_latency_hard_limit")]
1332 pub execution_queue_latency_hard_limit: Duration,
1333
1334 #[serde(default = "default_max_load_shedding_percentage")]
1336 pub max_load_shedding_percentage: u32,
1337
1338 #[serde(default = "default_min_load_shedding_percentage_above_hard_limit")]
1341 pub min_load_shedding_percentage_above_hard_limit: u32,
1342
1343 #[serde(default = "default_safe_transaction_ready_rate")]
1346 pub safe_transaction_ready_rate: u32,
1347
1348 #[serde(default = "default_check_system_overload_at_signing")]
1351 pub check_system_overload_at_signing: bool,
1352
1353 #[serde(default, skip_serializing_if = "std::ops::Not::not")]
1356 pub check_system_overload_at_execution: bool,
1357
1358 #[serde(default = "default_max_transaction_manager_queue_length")]
1361 pub max_transaction_manager_queue_length: usize,
1362
1363 #[serde(default = "default_max_transaction_manager_per_object_queue_length")]
1366 pub max_transaction_manager_per_object_queue_length: usize,
1367
1368 #[serde(default = "default_admission_queue_capacity_fraction")]
1372 pub admission_queue_capacity_fraction: f64,
1373
1374 #[serde(default = "default_admission_queue_bypass_fraction")]
1378 pub admission_queue_bypass_fraction: f64,
1379
1380 #[serde(default = "default_admission_queue_enabled")]
1384 pub admission_queue_enabled: bool,
1385
1386 #[serde(default = "default_admission_queue_failover_timeout")]
1391 pub admission_queue_failover_timeout: Duration,
1392}
1393
1394fn default_max_txn_age_in_queue() -> Duration {
1395 Duration::from_millis(1000)
1396}
1397
1398fn default_overload_monitor_interval() -> Duration {
1399 Duration::from_secs(10)
1400}
1401
1402fn default_execution_queue_latency_soft_limit() -> Duration {
1403 Duration::from_secs(1)
1404}
1405
1406fn default_execution_queue_latency_hard_limit() -> Duration {
1407 Duration::from_secs(10)
1408}
1409
1410fn default_max_load_shedding_percentage() -> u32 {
1411 95
1412}
1413
1414fn default_min_load_shedding_percentage_above_hard_limit() -> u32 {
1415 50
1416}
1417
1418fn default_safe_transaction_ready_rate() -> u32 {
1419 100
1420}
1421
1422fn default_check_system_overload_at_signing() -> bool {
1423 true
1424}
1425
1426fn default_max_transaction_manager_queue_length() -> usize {
1427 100_000
1428}
1429
1430fn default_max_transaction_manager_per_object_queue_length() -> usize {
1431 2000
1432}
1433
1434fn default_admission_queue_capacity_fraction() -> f64 {
1435 0.5
1436}
1437
1438fn default_admission_queue_bypass_fraction() -> f64 {
1439 0.9
1440}
1441
1442fn default_admission_queue_enabled() -> bool {
1443 false
1444}
1445
1446fn default_admission_queue_failover_timeout() -> Duration {
1447 Duration::from_secs(30)
1448}
1449
1450impl Default for AuthorityOverloadConfig {
1451 fn default() -> Self {
1452 Self {
1453 max_txn_age_in_queue: default_max_txn_age_in_queue(),
1454 overload_monitor_interval: default_overload_monitor_interval(),
1455 execution_queue_latency_soft_limit: default_execution_queue_latency_soft_limit(),
1456 execution_queue_latency_hard_limit: default_execution_queue_latency_hard_limit(),
1457 max_load_shedding_percentage: default_max_load_shedding_percentage(),
1458 min_load_shedding_percentage_above_hard_limit:
1459 default_min_load_shedding_percentage_above_hard_limit(),
1460 safe_transaction_ready_rate: default_safe_transaction_ready_rate(),
1461 check_system_overload_at_signing: true,
1462 check_system_overload_at_execution: false,
1463 max_transaction_manager_queue_length: default_max_transaction_manager_queue_length(),
1464 max_transaction_manager_per_object_queue_length:
1465 default_max_transaction_manager_per_object_queue_length(),
1466 admission_queue_capacity_fraction: default_admission_queue_capacity_fraction(),
1467 admission_queue_bypass_fraction: default_admission_queue_bypass_fraction(),
1468 admission_queue_enabled: default_admission_queue_enabled(),
1469 admission_queue_failover_timeout: default_admission_queue_failover_timeout(),
1470 }
1471 }
1472}
1473
1474fn default_authority_overload_config() -> AuthorityOverloadConfig {
1475 AuthorityOverloadConfig::default()
1476}
1477
1478fn default_traffic_controller_policy_config() -> Option<PolicyConfig> {
1479 Some(PolicyConfig::default_dos_protection_policy())
1480}
1481
1482#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Eq)]
1483pub struct Genesis {
1484 #[serde(flatten)]
1485 location: GenesisLocation,
1486
1487 #[serde(skip)]
1488 genesis: once_cell::sync::OnceCell<genesis::Genesis>,
1489}
1490
1491impl Genesis {
1492 pub fn new(genesis: genesis::Genesis) -> Self {
1493 Self {
1494 location: GenesisLocation::InPlace { genesis },
1495 genesis: Default::default(),
1496 }
1497 }
1498
1499 pub fn new_from_file<P: Into<PathBuf>>(path: P) -> Self {
1500 Self {
1501 location: GenesisLocation::File {
1502 genesis_file_location: path.into(),
1503 },
1504 genesis: Default::default(),
1505 }
1506 }
1507
1508 pub fn genesis(&self) -> Result<&genesis::Genesis> {
1509 match &self.location {
1510 GenesisLocation::InPlace { genesis } => Ok(genesis),
1511 GenesisLocation::File {
1512 genesis_file_location,
1513 } => self
1514 .genesis
1515 .get_or_try_init(|| genesis::Genesis::load(genesis_file_location)),
1516 }
1517 }
1518}
1519
1520#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Eq)]
1521#[serde(untagged)]
1522#[allow(clippy::large_enum_variant)]
1523enum GenesisLocation {
1524 InPlace {
1525 genesis: genesis::Genesis,
1526 },
1527 File {
1528 #[serde(rename = "genesis-file-location")]
1529 genesis_file_location: PathBuf,
1530 },
1531}
1532
1533#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
1535pub struct KeyPairWithPath {
1536 #[serde(flatten)]
1537 location: KeyPairLocation,
1538
1539 #[serde(skip)]
1540 keypair: OnceCell<Arc<SuiKeyPair>>,
1541}
1542
1543#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Eq)]
1544#[serde_as]
1545#[serde(untagged)]
1546enum KeyPairLocation {
1547 InPlace {
1548 #[serde_as(as = "Arc<KeyPairBase64>")]
1549 value: Arc<SuiKeyPair>,
1550 },
1551 File {
1552 #[serde(rename = "path")]
1553 path: PathBuf,
1554 },
1555}
1556
1557impl KeyPairWithPath {
1558 pub fn new(kp: SuiKeyPair) -> Self {
1559 let cell: OnceCell<Arc<SuiKeyPair>> = OnceCell::new();
1560 let arc_kp = Arc::new(kp);
1561 cell.set(arc_kp.clone()).expect("Failed to set keypair");
1563 Self {
1564 location: KeyPairLocation::InPlace { value: arc_kp },
1565 keypair: cell,
1566 }
1567 }
1568
1569 pub fn new_from_path(path: PathBuf) -> Self {
1570 let cell: OnceCell<Arc<SuiKeyPair>> = OnceCell::new();
1571 cell.set(Arc::new(read_keypair_from_file(&path).unwrap_or_else(
1573 |e| panic!("Invalid keypair file at path {:?}: {e}", &path),
1574 )))
1575 .expect("Failed to set keypair");
1576 Self {
1577 location: KeyPairLocation::File { path },
1578 keypair: cell,
1579 }
1580 }
1581
1582 pub fn keypair(&self) -> &SuiKeyPair {
1583 self.keypair
1584 .get_or_init(|| match &self.location {
1585 KeyPairLocation::InPlace { value } => value.clone(),
1586 KeyPairLocation::File { path } => {
1587 Arc::new(
1589 read_keypair_from_file(path).unwrap_or_else(|e| {
1590 panic!("Invalid keypair file at path {:?}: {e}", path)
1591 }),
1592 )
1593 }
1594 })
1595 .as_ref()
1596 }
1597}
1598
1599#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
1601pub struct AuthorityKeyPairWithPath {
1602 #[serde(flatten)]
1603 location: AuthorityKeyPairLocation,
1604
1605 #[serde(skip)]
1606 keypair: OnceCell<Arc<AuthorityKeyPair>>,
1607}
1608
1609#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Eq)]
1610#[serde_as]
1611#[serde(untagged)]
1612enum AuthorityKeyPairLocation {
1613 InPlace { value: Arc<AuthorityKeyPair> },
1614 File { path: PathBuf },
1615}
1616
1617impl AuthorityKeyPairWithPath {
1618 pub fn new(kp: AuthorityKeyPair) -> Self {
1619 let cell: OnceCell<Arc<AuthorityKeyPair>> = OnceCell::new();
1620 let arc_kp = Arc::new(kp);
1621 cell.set(arc_kp.clone())
1623 .expect("Failed to set authority keypair");
1624 Self {
1625 location: AuthorityKeyPairLocation::InPlace { value: arc_kp },
1626 keypair: cell,
1627 }
1628 }
1629
1630 pub fn new_from_path(path: PathBuf) -> Self {
1631 let cell: OnceCell<Arc<AuthorityKeyPair>> = OnceCell::new();
1632 cell.set(Arc::new(
1634 read_authority_keypair_from_file(&path)
1635 .unwrap_or_else(|_| panic!("Invalid authority keypair file at path {:?}", &path)),
1636 ))
1637 .expect("Failed to set authority keypair");
1638 Self {
1639 location: AuthorityKeyPairLocation::File { path },
1640 keypair: cell,
1641 }
1642 }
1643
1644 pub fn authority_keypair(&self) -> &AuthorityKeyPair {
1645 self.keypair
1646 .get_or_init(|| match &self.location {
1647 AuthorityKeyPairLocation::InPlace { value } => value.clone(),
1648 AuthorityKeyPairLocation::File { path } => {
1649 Arc::new(
1651 read_authority_keypair_from_file(path).unwrap_or_else(|_| {
1652 panic!("Invalid authority keypair file {:?}", &path)
1653 }),
1654 )
1655 }
1656 })
1657 .as_ref()
1658 }
1659}
1660
1661#[derive(Clone, Debug, Deserialize, Serialize, Default)]
1664#[serde(rename_all = "kebab-case")]
1665pub struct StateDebugDumpConfig {
1666 #[serde(skip_serializing_if = "Option::is_none")]
1667 pub dump_file_directory: Option<PathBuf>,
1668}
1669
1670fn read_credential_from_path_or_literal(value: &str) -> Result<String, std::io::Error> {
1671 let path = Path::new(value);
1672 if path.exists() && path.is_file() {
1673 std::fs::read_to_string(path).map(|content| content.trim().to_string())
1674 } else {
1675 Ok(value.to_string())
1676 }
1677}
1678
1679fn deserialize_remote_store_options<'de, D>(
1681 deserializer: D,
1682) -> Result<Vec<(String, String)>, D::Error>
1683where
1684 D: serde::Deserializer<'de>,
1685{
1686 use serde::de::Error;
1687
1688 let raw_options: Vec<(String, String)> = Vec::deserialize(deserializer)?;
1689 let mut processed_options = Vec::new();
1690
1691 for (key, value) in raw_options {
1692 let is_service_account_path = matches!(
1695 key.as_str(),
1696 "google_service_account"
1697 | "service_account"
1698 | "google_service_account_path"
1699 | "service_account_path"
1700 );
1701
1702 let processed_value = if is_service_account_path {
1703 value
1704 } else {
1705 match read_credential_from_path_or_literal(&value) {
1706 Ok(processed) => processed,
1707 Err(e) => {
1708 return Err(D::Error::custom(format!(
1709 "Failed to read credential for key '{}': {}",
1710 key, e
1711 )));
1712 }
1713 }
1714 };
1715
1716 processed_options.push((key, processed_value));
1717 }
1718
1719 Ok(processed_options)
1720}
1721
1722#[cfg(test)]
1723mod tests {
1724 use std::path::PathBuf;
1725
1726 use fastcrypto::traits::KeyPair;
1727 use rand::{SeedableRng, rngs::StdRng};
1728 use sui_keys::keypair_file::{write_authority_keypair_to_file, write_keypair_to_file};
1729 use sui_types::crypto::{AuthorityKeyPair, NetworkKeyPair, SuiKeyPair, get_key_pair_from_rng};
1730
1731 use super::{Genesis, StateArchiveConfig};
1732 use crate::NodeConfig;
1733
1734 #[test]
1735 fn serialize_genesis_from_file() {
1736 let g = Genesis::new_from_file("path/to/file");
1737
1738 let s = serde_yaml::to_string(&g).unwrap();
1739 assert_eq!("---\ngenesis-file-location: path/to/file\n", s);
1740 let loaded_genesis: Genesis = serde_yaml::from_str(&s).unwrap();
1741 assert_eq!(g, loaded_genesis);
1742 }
1743
1744 #[test]
1745 fn fullnode_template() {
1746 const TEMPLATE: &str = include_str!("../data/fullnode-template.yaml");
1747
1748 let _template: NodeConfig = serde_yaml::from_str(TEMPLATE).unwrap();
1749 }
1750
1751 #[test]
1753 fn legacy_validator_config() {
1754 const FILE: &str = include_str!("../data/sui-node-legacy.yaml");
1755
1756 let _template: NodeConfig = serde_yaml::from_str(FILE).unwrap();
1757 }
1758
1759 #[test]
1760 fn load_key_pairs_to_node_config() {
1761 let protocol_key_pair: AuthorityKeyPair =
1762 get_key_pair_from_rng(&mut StdRng::from_seed([0; 32])).1;
1763 let worker_key_pair: NetworkKeyPair =
1764 get_key_pair_from_rng(&mut StdRng::from_seed([0; 32])).1;
1765 let network_key_pair: NetworkKeyPair =
1766 get_key_pair_from_rng(&mut StdRng::from_seed([0; 32])).1;
1767
1768 write_authority_keypair_to_file(&protocol_key_pair, PathBuf::from("protocol.key")).unwrap();
1769 write_keypair_to_file(
1770 &SuiKeyPair::Ed25519(worker_key_pair.copy()),
1771 PathBuf::from("worker.key"),
1772 )
1773 .unwrap();
1774 write_keypair_to_file(
1775 &SuiKeyPair::Ed25519(network_key_pair.copy()),
1776 PathBuf::from("network.key"),
1777 )
1778 .unwrap();
1779
1780 const TEMPLATE: &str = include_str!("../data/fullnode-template-with-path.yaml");
1781 let template: NodeConfig = serde_yaml::from_str(TEMPLATE).unwrap();
1782 assert_eq!(
1783 template.protocol_key_pair().public(),
1784 protocol_key_pair.public()
1785 );
1786 assert_eq!(
1787 template.network_key_pair().public(),
1788 network_key_pair.public()
1789 );
1790 assert_eq!(
1791 template.worker_key_pair().public(),
1792 worker_key_pair.public()
1793 );
1794 }
1795
1796 #[test]
1797 fn test_remote_store_options_file_path_support() {
1798 let temp_dir = std::env::temp_dir();
1800 let access_key_file = temp_dir.join("test_access_key");
1801 let secret_key_file = temp_dir.join("test_secret_key");
1802
1803 std::fs::write(&access_key_file, "test_access_key_value").unwrap();
1804 std::fs::write(&secret_key_file, "test_secret_key_value\n").unwrap();
1805
1806 let yaml_config = format!(
1807 r#"
1808object-store-config: null
1809concurrency: 5
1810ingestion-url: "https://example.com"
1811remote-store-options:
1812 - ["aws_access_key_id", "{}"]
1813 - ["aws_secret_access_key", "{}"]
1814 - ["literal_key", "literal_value"]
1815"#,
1816 access_key_file.to_string_lossy(),
1817 secret_key_file.to_string_lossy()
1818 );
1819
1820 let config: StateArchiveConfig = serde_yaml::from_str(&yaml_config).unwrap();
1821
1822 assert_eq!(config.remote_store_options.len(), 3);
1824
1825 let access_key_option = config
1826 .remote_store_options
1827 .iter()
1828 .find(|(key, _)| key == "aws_access_key_id")
1829 .unwrap();
1830 assert_eq!(access_key_option.1, "test_access_key_value");
1831
1832 let secret_key_option = config
1833 .remote_store_options
1834 .iter()
1835 .find(|(key, _)| key == "aws_secret_access_key")
1836 .unwrap();
1837 assert_eq!(secret_key_option.1, "test_secret_key_value");
1838
1839 let literal_option = config
1840 .remote_store_options
1841 .iter()
1842 .find(|(key, _)| key == "literal_key")
1843 .unwrap();
1844 assert_eq!(literal_option.1, "literal_value");
1845
1846 std::fs::remove_file(&access_key_file).ok();
1848 std::fs::remove_file(&secret_key_file).ok();
1849 }
1850
1851 #[test]
1852 fn test_remote_store_options_literal_values_only() {
1853 let yaml_config = r#"
1854object-store-config: null
1855concurrency: 5
1856ingestion-url: "https://example.com"
1857remote-store-options:
1858 - ["aws_access_key_id", "literal_access_key"]
1859 - ["aws_secret_access_key", "literal_secret_key"]
1860"#;
1861
1862 let config: StateArchiveConfig = serde_yaml::from_str(yaml_config).unwrap();
1863
1864 assert_eq!(config.remote_store_options.len(), 2);
1865 assert_eq!(config.remote_store_options[0].1, "literal_access_key");
1866 assert_eq!(config.remote_store_options[1].1, "literal_secret_key");
1867 }
1868
1869 #[test]
1870 fn test_remote_store_options_gcs_service_account_path_preserved() {
1871 let temp_dir = std::env::temp_dir();
1872 let service_account_file = temp_dir.join("test_service_account.json");
1873 let aws_key_file = temp_dir.join("test_aws_key");
1874
1875 std::fs::write(&service_account_file, r#"{"type": "service_account"}"#).unwrap();
1876 std::fs::write(&aws_key_file, "aws_key_value").unwrap();
1877
1878 let yaml_config = format!(
1879 r#"
1880object-store-config: null
1881concurrency: 5
1882ingestion-url: "gs://my-bucket"
1883remote-store-options:
1884 - ["service_account", "{}"]
1885 - ["google_service_account_path", "{}"]
1886 - ["aws_access_key_id", "{}"]
1887"#,
1888 service_account_file.to_string_lossy(),
1889 service_account_file.to_string_lossy(),
1890 aws_key_file.to_string_lossy()
1891 );
1892
1893 let config: StateArchiveConfig = serde_yaml::from_str(&yaml_config).unwrap();
1894
1895 assert_eq!(config.remote_store_options.len(), 3);
1896
1897 let service_account_option = config
1899 .remote_store_options
1900 .iter()
1901 .find(|(key, _)| key == "service_account")
1902 .unwrap();
1903 assert_eq!(
1904 service_account_option.1,
1905 service_account_file.to_string_lossy()
1906 );
1907
1908 let gcs_path_option = config
1910 .remote_store_options
1911 .iter()
1912 .find(|(key, _)| key == "google_service_account_path")
1913 .unwrap();
1914 assert_eq!(gcs_path_option.1, service_account_file.to_string_lossy());
1915
1916 let aws_option = config
1918 .remote_store_options
1919 .iter()
1920 .find(|(key, _)| key == "aws_access_key_id")
1921 .unwrap();
1922 assert_eq!(aws_option.1, "aws_key_value");
1923
1924 std::fs::remove_file(&service_account_file).ok();
1926 std::fs::remove_file(&aws_key_file).ok();
1927 }
1928}
1929
1930#[derive(Clone, Copy, PartialEq, Debug, Serialize, Deserialize)]
1933pub enum RunWithRange {
1934 Epoch(EpochId),
1935 Checkpoint(CheckpointSequenceNumber),
1936}
1937
1938impl RunWithRange {
1939 pub fn is_epoch_gt(&self, epoch_id: EpochId) -> bool {
1941 matches!(self, RunWithRange::Epoch(e) if epoch_id > *e)
1942 }
1943
1944 pub fn matches_checkpoint(&self, seq_num: CheckpointSequenceNumber) -> bool {
1945 matches!(self, RunWithRange::Checkpoint(seq) if *seq == seq_num)
1946 }
1947
1948 pub fn into_checkpoint_bound(self) -> Option<CheckpointSequenceNumber> {
1949 match self {
1950 RunWithRange::Epoch(_) => None,
1951 RunWithRange::Checkpoint(seq) => Some(seq),
1952 }
1953 }
1954}