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#[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 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 #[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 #[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 #[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 #[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 = "bool_true")]
197 pub enable_validator_tx_finalizer: bool,
198
199 #[serde(default)]
200 pub verifier_signing_config: VerifierSigningConfig,
201
202 #[serde(skip_serializing_if = "Option::is_none")]
205 pub enable_db_write_stall: Option<bool>,
206
207 #[serde(skip_serializing_if = "Option::is_none")]
208 pub execution_time_observer_config: Option<ExecutionTimeObserverConfig>,
209
210 #[serde(skip_serializing_if = "Option::is_none")]
214 pub chain_override_for_testing: Option<Chain>,
215
216 #[serde(skip_serializing_if = "Option::is_none")]
219 pub validator_client_monitor_config: Option<ValidatorClientMonitorConfig>,
220
221 #[serde(skip_serializing_if = "Option::is_none")]
223 pub fork_recovery: Option<ForkRecoveryConfig>,
224
225 #[serde(skip_serializing_if = "Option::is_none")]
227 pub transaction_driver_config: Option<TransactionDriverConfig>,
228}
229
230#[derive(Clone, Debug, Deserialize, Serialize)]
231#[serde(rename_all = "kebab-case")]
232pub struct TransactionDriverConfig {
233 #[serde(default, skip_serializing_if = "Vec::is_empty")]
236 pub allowed_submission_validators: Vec<String>,
237
238 #[serde(default, skip_serializing_if = "Vec::is_empty")]
241 pub blocked_submission_validators: Vec<String>,
242
243 #[serde(default = "bool_true")]
248 pub enable_early_validation: bool,
249}
250
251impl Default for TransactionDriverConfig {
252 fn default() -> Self {
253 Self {
254 allowed_submission_validators: vec![],
255 blocked_submission_validators: vec![],
256 enable_early_validation: true,
257 }
258 }
259}
260
261#[derive(Debug, Clone, Copy, Default, Deserialize, Serialize, PartialEq, Eq)]
262#[serde(rename_all = "kebab-case")]
263pub enum ForkCrashBehavior {
264 #[serde(rename = "await-fork-recovery")]
265 #[default]
266 AwaitForkRecovery,
267 #[serde(rename = "return-error")]
269 ReturnError,
270}
271
272#[derive(Clone, Debug, Default, Deserialize, Serialize)]
273#[serde(rename_all = "kebab-case")]
274pub struct ForkRecoveryConfig {
275 #[serde(default)]
278 pub transaction_overrides: BTreeMap<String, String>,
279
280 #[serde(default)]
284 pub checkpoint_overrides: BTreeMap<u64, String>,
285
286 #[serde(default)]
288 pub fork_crash_behavior: ForkCrashBehavior,
289}
290
291#[derive(Clone, Debug, Default, Deserialize, Serialize)]
292#[serde(rename_all = "kebab-case")]
293pub struct ExecutionTimeObserverConfig {
294 pub observation_channel_capacity: Option<NonZeroUsize>,
298
299 pub observation_cache_size: Option<NonZeroUsize>,
303
304 pub object_debt_channel_capacity: Option<NonZeroUsize>,
308
309 pub object_utilization_cache_size: Option<NonZeroUsize>,
313
314 pub report_object_utilization_metric_with_full_id: Option<bool>,
325
326 pub observation_sharing_object_utilization_threshold: Option<Duration>,
331
332 pub observation_sharing_diff_threshold: Option<f64>,
337
338 pub observation_sharing_min_interval: Option<Duration>,
342
343 pub observation_sharing_rate_limit: Option<NonZeroU32>,
348
349 pub observation_sharing_burst_limit: Option<NonZeroU32>,
353
354 pub enable_gas_price_weighting: Option<bool>,
361
362 pub weighted_moving_average_window_size: Option<usize>,
369
370 #[cfg(msim)]
376 pub inject_synthetic_execution_time: Option<bool>,
377}
378
379impl ExecutionTimeObserverConfig {
380 pub fn observation_channel_capacity(&self) -> NonZeroUsize {
381 self.observation_channel_capacity
382 .unwrap_or(nonzero!(1_024usize))
383 }
384
385 pub fn observation_cache_size(&self) -> NonZeroUsize {
386 self.observation_cache_size.unwrap_or(nonzero!(10_000usize))
387 }
388
389 pub fn object_debt_channel_capacity(&self) -> NonZeroUsize {
390 self.object_debt_channel_capacity
391 .unwrap_or(nonzero!(128usize))
392 }
393
394 pub fn object_utilization_cache_size(&self) -> NonZeroUsize {
395 self.object_utilization_cache_size
396 .unwrap_or(nonzero!(50_000usize))
397 }
398
399 pub fn report_object_utilization_metric_with_full_id(&self) -> bool {
400 self.report_object_utilization_metric_with_full_id
401 .unwrap_or(false)
402 }
403
404 pub fn observation_sharing_object_utilization_threshold(&self) -> Duration {
405 self.observation_sharing_object_utilization_threshold
406 .unwrap_or(Duration::from_millis(500))
407 }
408
409 pub fn observation_sharing_diff_threshold(&self) -> f64 {
410 self.observation_sharing_diff_threshold.unwrap_or(0.1)
411 }
412
413 pub fn observation_sharing_min_interval(&self) -> Duration {
414 self.observation_sharing_min_interval
415 .unwrap_or(Duration::from_secs(5))
416 }
417
418 pub fn observation_sharing_rate_limit(&self) -> NonZeroU32 {
419 self.observation_sharing_rate_limit
420 .unwrap_or(nonzero!(10u32))
421 }
422
423 pub fn observation_sharing_burst_limit(&self) -> NonZeroU32 {
424 self.observation_sharing_burst_limit
425 .unwrap_or(nonzero!(100u32))
426 }
427
428 pub fn enable_gas_price_weighting(&self) -> bool {
429 self.enable_gas_price_weighting.unwrap_or(false)
430 }
431
432 pub fn weighted_moving_average_window_size(&self) -> usize {
433 self.weighted_moving_average_window_size.unwrap_or(20)
434 }
435
436 #[cfg(msim)]
437 pub fn inject_synthetic_execution_time(&self) -> bool {
438 self.inject_synthetic_execution_time.unwrap_or(false)
439 }
440}
441
442#[allow(clippy::large_enum_variant)]
443#[derive(Clone, Debug, Deserialize, Serialize)]
444#[serde(rename_all = "kebab-case")]
445pub enum ExecutionCacheConfig {
446 PassthroughCache,
447 WritebackCache {
448 max_cache_size: Option<u64>,
451
452 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>,
468
469 backpressure_threshold_for_rpc: Option<u64>,
472
473 fastpath_transaction_outputs_cache_size: Option<u64>,
474 },
475}
476
477impl Default for ExecutionCacheConfig {
478 fn default() -> Self {
479 ExecutionCacheConfig::WritebackCache {
480 max_cache_size: None,
481 backpressure_threshold: None,
482 backpressure_threshold_for_rpc: None,
483 package_cache_size: None,
484 object_cache_size: None,
485 marker_cache_size: None,
486 object_by_id_cache_size: None,
487 transaction_cache_size: None,
488 executed_effect_cache_size: None,
489 effect_cache_size: None,
490 events_cache_size: None,
491 transaction_objects_cache_size: None,
492 fastpath_transaction_outputs_cache_size: None,
493 }
494 }
495}
496
497impl ExecutionCacheConfig {
498 pub fn max_cache_size(&self) -> u64 {
499 std::env::var("SUI_MAX_CACHE_SIZE")
500 .ok()
501 .and_then(|s| s.parse().ok())
502 .unwrap_or_else(|| match self {
503 ExecutionCacheConfig::PassthroughCache => fatal!("invalid cache config"),
504 ExecutionCacheConfig::WritebackCache { max_cache_size, .. } => {
505 max_cache_size.unwrap_or(100000)
506 }
507 })
508 }
509
510 pub fn package_cache_size(&self) -> u64 {
511 std::env::var("SUI_PACKAGE_CACHE_SIZE")
512 .ok()
513 .and_then(|s| s.parse().ok())
514 .unwrap_or_else(|| match self {
515 ExecutionCacheConfig::PassthroughCache => fatal!("invalid cache config"),
516 ExecutionCacheConfig::WritebackCache {
517 package_cache_size, ..
518 } => package_cache_size.unwrap_or(1000),
519 })
520 }
521
522 pub fn object_cache_size(&self) -> u64 {
523 std::env::var("SUI_OBJECT_CACHE_SIZE")
524 .ok()
525 .and_then(|s| s.parse().ok())
526 .unwrap_or_else(|| match self {
527 ExecutionCacheConfig::PassthroughCache => fatal!("invalid cache config"),
528 ExecutionCacheConfig::WritebackCache {
529 object_cache_size, ..
530 } => object_cache_size.unwrap_or(self.max_cache_size()),
531 })
532 }
533
534 pub fn marker_cache_size(&self) -> u64 {
535 std::env::var("SUI_MARKER_CACHE_SIZE")
536 .ok()
537 .and_then(|s| s.parse().ok())
538 .unwrap_or_else(|| match self {
539 ExecutionCacheConfig::PassthroughCache => fatal!("invalid cache config"),
540 ExecutionCacheConfig::WritebackCache {
541 marker_cache_size, ..
542 } => marker_cache_size.unwrap_or(self.object_cache_size()),
543 })
544 }
545
546 pub fn object_by_id_cache_size(&self) -> u64 {
547 std::env::var("SUI_OBJECT_BY_ID_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 {
553 object_by_id_cache_size,
554 ..
555 } => object_by_id_cache_size.unwrap_or(self.object_cache_size()),
556 })
557 }
558
559 pub fn transaction_cache_size(&self) -> u64 {
560 std::env::var("SUI_TRANSACTION_CACHE_SIZE")
561 .ok()
562 .and_then(|s| s.parse().ok())
563 .unwrap_or_else(|| match self {
564 ExecutionCacheConfig::PassthroughCache => fatal!("invalid cache config"),
565 ExecutionCacheConfig::WritebackCache {
566 transaction_cache_size,
567 ..
568 } => transaction_cache_size.unwrap_or(self.max_cache_size()),
569 })
570 }
571
572 pub fn executed_effect_cache_size(&self) -> u64 {
573 std::env::var("SUI_EXECUTED_EFFECT_CACHE_SIZE")
574 .ok()
575 .and_then(|s| s.parse().ok())
576 .unwrap_or_else(|| match self {
577 ExecutionCacheConfig::PassthroughCache => fatal!("invalid cache config"),
578 ExecutionCacheConfig::WritebackCache {
579 executed_effect_cache_size,
580 ..
581 } => executed_effect_cache_size.unwrap_or(self.transaction_cache_size()),
582 })
583 }
584
585 pub fn effect_cache_size(&self) -> u64 {
586 std::env::var("SUI_EFFECT_CACHE_SIZE")
587 .ok()
588 .and_then(|s| s.parse().ok())
589 .unwrap_or_else(|| match self {
590 ExecutionCacheConfig::PassthroughCache => fatal!("invalid cache config"),
591 ExecutionCacheConfig::WritebackCache {
592 effect_cache_size, ..
593 } => effect_cache_size.unwrap_or(self.executed_effect_cache_size()),
594 })
595 }
596
597 pub fn events_cache_size(&self) -> u64 {
598 std::env::var("SUI_EVENTS_CACHE_SIZE")
599 .ok()
600 .and_then(|s| s.parse().ok())
601 .unwrap_or_else(|| match self {
602 ExecutionCacheConfig::PassthroughCache => fatal!("invalid cache config"),
603 ExecutionCacheConfig::WritebackCache {
604 events_cache_size, ..
605 } => events_cache_size.unwrap_or(self.transaction_cache_size()),
606 })
607 }
608
609 pub fn transaction_objects_cache_size(&self) -> u64 {
610 std::env::var("SUI_TRANSACTION_OBJECTS_CACHE_SIZE")
611 .ok()
612 .and_then(|s| s.parse().ok())
613 .unwrap_or_else(|| match self {
614 ExecutionCacheConfig::PassthroughCache => fatal!("invalid cache config"),
615 ExecutionCacheConfig::WritebackCache {
616 transaction_objects_cache_size,
617 ..
618 } => transaction_objects_cache_size.unwrap_or(1000),
619 })
620 }
621
622 pub fn backpressure_threshold(&self) -> u64 {
623 std::env::var("SUI_BACKPRESSURE_THRESHOLD")
624 .ok()
625 .and_then(|s| s.parse().ok())
626 .unwrap_or_else(|| match self {
627 ExecutionCacheConfig::PassthroughCache => fatal!("invalid cache config"),
628 ExecutionCacheConfig::WritebackCache {
629 backpressure_threshold,
630 ..
631 } => backpressure_threshold.unwrap_or(100_000),
632 })
633 }
634
635 pub fn backpressure_threshold_for_rpc(&self) -> u64 {
636 std::env::var("SUI_BACKPRESSURE_THRESHOLD_FOR_RPC")
637 .ok()
638 .and_then(|s| s.parse().ok())
639 .unwrap_or_else(|| match self {
640 ExecutionCacheConfig::PassthroughCache => fatal!("invalid cache config"),
641 ExecutionCacheConfig::WritebackCache {
642 backpressure_threshold_for_rpc,
643 ..
644 } => backpressure_threshold_for_rpc.unwrap_or(self.backpressure_threshold()),
645 })
646 }
647
648 pub fn fastpath_transaction_outputs_cache_size(&self) -> u64 {
649 std::env::var("SUI_FASTPATH_TRANSACTION_OUTPUTS_CACHE_SIZE")
650 .ok()
651 .and_then(|s| s.parse().ok())
652 .unwrap_or_else(|| match self {
653 ExecutionCacheConfig::PassthroughCache => fatal!("invalid cache config"),
654 ExecutionCacheConfig::WritebackCache {
655 fastpath_transaction_outputs_cache_size,
656 ..
657 } => fastpath_transaction_outputs_cache_size.unwrap_or(10_000),
658 })
659 }
660}
661
662#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
663#[serde(rename_all = "lowercase")]
664pub enum ServerType {
665 WebSocket,
666 Http,
667 Both,
668}
669
670#[derive(Clone, Debug, Deserialize, Serialize)]
671#[serde(rename_all = "kebab-case")]
672pub struct TransactionKeyValueStoreReadConfig {
673 #[serde(default = "default_base_url")]
674 pub base_url: String,
675
676 #[serde(default = "default_cache_size")]
677 pub cache_size: u64,
678}
679
680impl Default for TransactionKeyValueStoreReadConfig {
681 fn default() -> Self {
682 Self {
683 base_url: default_base_url(),
684 cache_size: default_cache_size(),
685 }
686 }
687}
688
689fn default_base_url() -> String {
690 "https://transactions.sui.io/".to_string()
691}
692
693fn default_cache_size() -> u64 {
694 100_000
695}
696
697fn default_jwk_fetch_interval_seconds() -> u64 {
698 3600
699}
700
701pub fn default_zklogin_oauth_providers() -> BTreeMap<Chain, BTreeSet<String>> {
702 let mut map = BTreeMap::new();
703
704 let experimental_providers = BTreeSet::from([
706 "Google".to_string(),
707 "Facebook".to_string(),
708 "Twitch".to_string(),
709 "Kakao".to_string(),
710 "Apple".to_string(),
711 "Slack".to_string(),
712 "TestIssuer".to_string(),
713 "Microsoft".to_string(),
714 "KarrierOne".to_string(),
715 "Credenza3".to_string(),
716 "Playtron".to_string(),
717 "Threedos".to_string(),
718 "Onefc".to_string(),
719 "FanTV".to_string(),
720 "AwsTenant-region:us-east-1-tenant_id:us-east-1_qPsZxYqd8".to_string(), "Arden".to_string(), "AwsTenant-region:eu-west-3-tenant_id:eu-west-3_gGVCx53Es".to_string(), "EveFrontier".to_string(),
724 "TestEveFrontier".to_string(),
725 "AwsTenant-region:ap-southeast-1-tenant_id:ap-southeast-1_2QQPyQXDz".to_string(), ]);
727
728 let providers = BTreeSet::from([
730 "Google".to_string(),
731 "Facebook".to_string(),
732 "Twitch".to_string(),
733 "Apple".to_string(),
734 "AwsTenant-region:us-east-1-tenant_id:us-east-1_qPsZxYqd8".to_string(), "KarrierOne".to_string(),
736 "Credenza3".to_string(),
737 "Playtron".to_string(),
738 "Onefc".to_string(),
739 "Threedos".to_string(),
740 "AwsTenant-region:eu-west-3-tenant_id:eu-west-3_gGVCx53Es".to_string(), "Arden".to_string(),
742 "FanTV".to_string(),
743 "EveFrontier".to_string(),
744 "TestEveFrontier".to_string(),
745 "AwsTenant-region:ap-southeast-1-tenant_id:ap-southeast-1_2QQPyQXDz".to_string(), ]);
747 map.insert(Chain::Mainnet, providers.clone());
748 map.insert(Chain::Testnet, providers);
749 map.insert(Chain::Unknown, experimental_providers);
750 map
751}
752
753fn default_transaction_kv_store_config() -> TransactionKeyValueStoreReadConfig {
754 TransactionKeyValueStoreReadConfig::default()
755}
756
757fn default_authority_store_pruning_config() -> AuthorityStorePruningConfig {
758 AuthorityStorePruningConfig::default()
759}
760
761pub fn default_enable_index_processing() -> bool {
762 true
763}
764
765fn default_grpc_address() -> Multiaddr {
766 "/ip4/0.0.0.0/tcp/8080".parse().unwrap()
767}
768fn default_authority_key_pair() -> AuthorityKeyPairWithPath {
769 AuthorityKeyPairWithPath::new(get_key_pair_from_rng::<AuthorityKeyPair, _>(&mut OsRng).1)
770}
771
772fn default_key_pair() -> KeyPairWithPath {
773 KeyPairWithPath::new(
774 get_key_pair_from_rng::<AccountKeyPair, _>(&mut OsRng)
775 .1
776 .into(),
777 )
778}
779
780fn default_metrics_address() -> SocketAddr {
781 use std::net::{IpAddr, Ipv4Addr};
782 SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 9184)
783}
784
785pub fn default_admin_interface_port() -> u16 {
786 1337
787}
788
789pub fn default_json_rpc_address() -> SocketAddr {
790 use std::net::{IpAddr, Ipv4Addr};
791 SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 9000)
792}
793
794pub fn default_concurrency_limit() -> Option<usize> {
795 Some(DEFAULT_GRPC_CONCURRENCY_LIMIT)
796}
797
798pub fn default_end_of_epoch_broadcast_channel_capacity() -> usize {
799 128
800}
801
802pub fn bool_true() -> bool {
803 true
804}
805
806fn is_true(value: &bool) -> bool {
807 *value
808}
809
810impl Config for NodeConfig {}
811
812impl NodeConfig {
813 pub fn protocol_key_pair(&self) -> &AuthorityKeyPair {
814 self.protocol_key_pair.authority_keypair()
815 }
816
817 pub fn worker_key_pair(&self) -> &NetworkKeyPair {
818 match self.worker_key_pair.keypair() {
819 SuiKeyPair::Ed25519(kp) => kp,
820 other => panic!(
821 "Invalid keypair type: {:?}, only Ed25519 is allowed for worker key",
822 other
823 ),
824 }
825 }
826
827 pub fn network_key_pair(&self) -> &NetworkKeyPair {
828 match self.network_key_pair.keypair() {
829 SuiKeyPair::Ed25519(kp) => kp,
830 other => panic!(
831 "Invalid keypair type: {:?}, only Ed25519 is allowed for network key",
832 other
833 ),
834 }
835 }
836
837 pub fn protocol_public_key(&self) -> AuthorityPublicKeyBytes {
838 self.protocol_key_pair().public().into()
839 }
840
841 pub fn db_path(&self) -> PathBuf {
842 self.db_path.join("live")
843 }
844
845 pub fn db_checkpoint_path(&self) -> PathBuf {
846 self.db_path.join("db_checkpoints")
847 }
848
849 pub fn archive_path(&self) -> PathBuf {
850 self.db_path.join("archive")
851 }
852
853 pub fn snapshot_path(&self) -> PathBuf {
854 self.db_path.join("snapshot")
855 }
856
857 pub fn network_address(&self) -> &Multiaddr {
858 &self.network_address
859 }
860
861 pub fn consensus_config(&self) -> Option<&ConsensusConfig> {
862 self.consensus_config.as_ref()
863 }
864
865 pub fn genesis(&self) -> Result<&genesis::Genesis> {
866 self.genesis.genesis()
867 }
868
869 pub fn sui_address(&self) -> SuiAddress {
870 (&self.account_key_pair.keypair().public()).into()
871 }
872
873 pub fn archive_reader_config(&self) -> Option<ArchiveReaderConfig> {
874 self.state_archive_read_config
875 .first()
876 .map(|config| ArchiveReaderConfig {
877 ingestion_url: config.ingestion_url.clone(),
878 remote_store_options: config.remote_store_options.clone(),
879 download_concurrency: NonZeroUsize::new(config.concurrency)
880 .unwrap_or(NonZeroUsize::new(5).unwrap()),
881 remote_store_config: ObjectStoreConfig::default(),
882 })
883 }
884
885 pub fn jsonrpc_server_type(&self) -> ServerType {
886 self.jsonrpc_server_type.unwrap_or(ServerType::Http)
887 }
888
889 pub fn rpc(&self) -> Option<&crate::RpcConfig> {
890 self.rpc.as_ref()
891 }
892}
893
894#[derive(Debug, Clone, Deserialize, Serialize)]
895pub enum ConsensusProtocol {
896 #[serde(rename = "narwhal")]
897 Narwhal,
898 #[serde(rename = "mysticeti")]
899 Mysticeti,
900}
901
902#[derive(Debug, Clone, Deserialize, Serialize)]
903#[serde(rename_all = "kebab-case")]
904pub struct ConsensusConfig {
905 pub db_path: PathBuf,
907
908 pub db_retention_epochs: Option<u64>,
911
912 pub db_pruner_period_secs: Option<u64>,
915
916 pub max_pending_transactions: Option<usize>,
920
921 pub max_submit_position: Option<usize>,
924
925 pub submit_delay_step_override_millis: Option<u64>,
929
930 pub parameters: Option<ConsensusParameters>,
931}
932
933impl ConsensusConfig {
934 pub fn db_path(&self) -> &Path {
935 &self.db_path
936 }
937
938 pub fn max_pending_transactions(&self) -> usize {
939 self.max_pending_transactions.unwrap_or(20_000)
940 }
941
942 pub fn submit_delay_step_override(&self) -> Option<Duration> {
943 self.submit_delay_step_override_millis
944 .map(Duration::from_millis)
945 }
946
947 pub fn db_retention_epochs(&self) -> u64 {
948 self.db_retention_epochs.unwrap_or(0)
949 }
950
951 pub fn db_pruner_period(&self) -> Duration {
952 self.db_pruner_period_secs
954 .map(Duration::from_secs)
955 .unwrap_or(Duration::from_secs(3_600))
956 }
957}
958
959#[derive(Clone, Debug, Deserialize, Serialize)]
960#[serde(rename_all = "kebab-case")]
961pub struct CheckpointExecutorConfig {
962 #[serde(default = "default_checkpoint_execution_max_concurrency")]
966 pub checkpoint_execution_max_concurrency: usize,
967
968 #[serde(default = "default_local_execution_timeout_sec")]
974 pub local_execution_timeout_sec: u64,
975
976 #[serde(default, skip_serializing_if = "Option::is_none")]
979 pub data_ingestion_dir: Option<PathBuf>,
980}
981
982#[derive(Clone, Debug, Default, Deserialize, Serialize)]
983#[serde(rename_all = "kebab-case")]
984pub struct ExpensiveSafetyCheckConfig {
985 #[serde(default)]
990 enable_epoch_sui_conservation_check: bool,
991
992 #[serde(default)]
996 enable_deep_per_tx_sui_conservation_check: bool,
997
998 #[serde(default)]
1000 force_disable_epoch_sui_conservation_check: bool,
1001
1002 #[serde(default)]
1005 enable_state_consistency_check: bool,
1006
1007 #[serde(default)]
1009 force_disable_state_consistency_check: bool,
1010
1011 #[serde(default)]
1012 enable_secondary_index_checks: bool,
1013 }
1015
1016impl ExpensiveSafetyCheckConfig {
1017 pub fn new_enable_all() -> Self {
1018 Self {
1019 enable_epoch_sui_conservation_check: true,
1020 enable_deep_per_tx_sui_conservation_check: true,
1021 force_disable_epoch_sui_conservation_check: false,
1022 enable_state_consistency_check: true,
1023 force_disable_state_consistency_check: false,
1024 enable_secondary_index_checks: false, }
1026 }
1027
1028 pub fn new_disable_all() -> Self {
1029 Self {
1030 enable_epoch_sui_conservation_check: false,
1031 enable_deep_per_tx_sui_conservation_check: false,
1032 force_disable_epoch_sui_conservation_check: true,
1033 enable_state_consistency_check: false,
1034 force_disable_state_consistency_check: true,
1035 enable_secondary_index_checks: false,
1036 }
1037 }
1038
1039 pub fn force_disable_epoch_sui_conservation_check(&mut self) {
1040 self.force_disable_epoch_sui_conservation_check = true;
1041 }
1042
1043 pub fn enable_epoch_sui_conservation_check(&self) -> bool {
1044 (self.enable_epoch_sui_conservation_check || cfg!(debug_assertions))
1045 && !self.force_disable_epoch_sui_conservation_check
1046 }
1047
1048 pub fn force_disable_state_consistency_check(&mut self) {
1049 self.force_disable_state_consistency_check = true;
1050 }
1051
1052 pub fn enable_state_consistency_check(&self) -> bool {
1053 (self.enable_state_consistency_check || cfg!(debug_assertions))
1054 && !self.force_disable_state_consistency_check
1055 }
1056
1057 pub fn enable_deep_per_tx_sui_conservation_check(&self) -> bool {
1058 self.enable_deep_per_tx_sui_conservation_check || cfg!(debug_assertions)
1059 }
1060
1061 pub fn enable_secondary_index_checks(&self) -> bool {
1062 self.enable_secondary_index_checks
1063 }
1064}
1065
1066fn default_checkpoint_execution_max_concurrency() -> usize {
1067 4
1068}
1069
1070fn default_local_execution_timeout_sec() -> u64 {
1071 30
1072}
1073
1074impl Default for CheckpointExecutorConfig {
1075 fn default() -> Self {
1076 Self {
1077 checkpoint_execution_max_concurrency: default_checkpoint_execution_max_concurrency(),
1078 local_execution_timeout_sec: default_local_execution_timeout_sec(),
1079 data_ingestion_dir: None,
1080 }
1081 }
1082}
1083
1084#[derive(Debug, Clone, Deserialize, Serialize)]
1085#[serde(rename_all = "kebab-case")]
1086pub struct AuthorityStorePruningConfig {
1087 #[serde(default = "default_num_latest_epoch_dbs_to_retain")]
1089 pub num_latest_epoch_dbs_to_retain: usize,
1090 #[serde(default = "default_epoch_db_pruning_period_secs")]
1092 pub epoch_db_pruning_period_secs: u64,
1093 #[serde(default)]
1098 pub num_epochs_to_retain: u64,
1099 #[serde(skip_serializing_if = "Option::is_none")]
1101 pub pruning_run_delay_seconds: Option<u64>,
1102 #[serde(default = "default_max_checkpoints_in_batch")]
1104 pub max_checkpoints_in_batch: usize,
1105 #[serde(default = "default_max_transactions_in_batch")]
1107 pub max_transactions_in_batch: usize,
1108 #[serde(
1112 default = "default_periodic_compaction_threshold_days",
1113 skip_serializing_if = "Option::is_none"
1114 )]
1115 pub periodic_compaction_threshold_days: Option<usize>,
1116 #[serde(skip_serializing_if = "Option::is_none")]
1118 pub num_epochs_to_retain_for_checkpoints: Option<u64>,
1119 #[serde(default, skip_serializing_if = "std::ops::Not::not")]
1121 pub killswitch_tombstone_pruning: bool,
1122 #[serde(default = "default_smoothing", skip_serializing_if = "is_true")]
1123 pub smooth: bool,
1124 #[serde(default, skip_serializing_if = "std::ops::Not::not")]
1130 pub enable_compaction_filter: bool,
1131 #[serde(skip_serializing_if = "Option::is_none")]
1132 pub num_epochs_to_retain_for_indexes: Option<u64>,
1133}
1134
1135fn default_num_latest_epoch_dbs_to_retain() -> usize {
1136 3
1137}
1138
1139fn default_epoch_db_pruning_period_secs() -> u64 {
1140 3600
1141}
1142
1143fn default_max_transactions_in_batch() -> usize {
1144 1000
1145}
1146
1147fn default_max_checkpoints_in_batch() -> usize {
1148 10
1149}
1150
1151fn default_smoothing() -> bool {
1152 cfg!(not(test))
1153}
1154
1155fn default_periodic_compaction_threshold_days() -> Option<usize> {
1156 Some(1)
1157}
1158
1159impl Default for AuthorityStorePruningConfig {
1160 fn default() -> Self {
1161 Self {
1162 num_latest_epoch_dbs_to_retain: default_num_latest_epoch_dbs_to_retain(),
1163 epoch_db_pruning_period_secs: default_epoch_db_pruning_period_secs(),
1164 num_epochs_to_retain: 0,
1165 pruning_run_delay_seconds: if cfg!(msim) { Some(2) } else { None },
1166 max_checkpoints_in_batch: default_max_checkpoints_in_batch(),
1167 max_transactions_in_batch: default_max_transactions_in_batch(),
1168 periodic_compaction_threshold_days: None,
1169 num_epochs_to_retain_for_checkpoints: if cfg!(msim) { Some(2) } else { None },
1170 killswitch_tombstone_pruning: false,
1171 smooth: true,
1172 enable_compaction_filter: cfg!(test) || cfg!(msim),
1173 num_epochs_to_retain_for_indexes: None,
1174 }
1175 }
1176}
1177
1178impl AuthorityStorePruningConfig {
1179 pub fn set_num_epochs_to_retain(&mut self, num_epochs_to_retain: u64) {
1180 self.num_epochs_to_retain = num_epochs_to_retain;
1181 }
1182
1183 pub fn set_num_epochs_to_retain_for_checkpoints(&mut self, num_epochs_to_retain: Option<u64>) {
1184 self.num_epochs_to_retain_for_checkpoints = num_epochs_to_retain;
1185 }
1186
1187 pub fn num_epochs_to_retain_for_checkpoints(&self) -> Option<u64> {
1188 self.num_epochs_to_retain_for_checkpoints
1189 .map(|n| {
1191 if n < 2 {
1192 info!("num_epochs_to_retain_for_checkpoints must be at least 2, rounding up from {}", n);
1193 2
1194 } else {
1195 n
1196 }
1197 })
1198 }
1199
1200 pub fn set_killswitch_tombstone_pruning(&mut self, killswitch_tombstone_pruning: bool) {
1201 self.killswitch_tombstone_pruning = killswitch_tombstone_pruning;
1202 }
1203}
1204
1205#[derive(Debug, Clone, Deserialize, Serialize)]
1206#[serde(rename_all = "kebab-case")]
1207pub struct MetricsConfig {
1208 #[serde(skip_serializing_if = "Option::is_none")]
1209 pub push_interval_seconds: Option<u64>,
1210 #[serde(skip_serializing_if = "Option::is_none")]
1211 pub push_url: Option<String>,
1212}
1213
1214#[derive(Default, Debug, Clone, Deserialize, Serialize)]
1215#[serde(rename_all = "kebab-case")]
1216pub struct DBCheckpointConfig {
1217 #[serde(default)]
1218 pub perform_db_checkpoints_at_epoch_end: bool,
1219 #[serde(skip_serializing_if = "Option::is_none")]
1220 pub checkpoint_path: Option<PathBuf>,
1221 #[serde(skip_serializing_if = "Option::is_none")]
1222 pub object_store_config: Option<ObjectStoreConfig>,
1223 #[serde(skip_serializing_if = "Option::is_none")]
1224 pub perform_index_db_checkpoints_at_epoch_end: Option<bool>,
1225 #[serde(skip_serializing_if = "Option::is_none")]
1226 pub prune_and_compact_before_upload: Option<bool>,
1227}
1228
1229#[derive(Debug, Clone)]
1230pub struct ArchiveReaderConfig {
1231 pub remote_store_config: ObjectStoreConfig,
1232 pub download_concurrency: NonZeroUsize,
1233 pub ingestion_url: Option<String>,
1234 pub remote_store_options: Vec<(String, String)>,
1235}
1236
1237#[derive(Default, Debug, Clone, Deserialize, Serialize)]
1238#[serde(rename_all = "kebab-case")]
1239pub struct StateArchiveConfig {
1240 #[serde(skip_serializing_if = "Option::is_none")]
1241 pub object_store_config: Option<ObjectStoreConfig>,
1242 pub concurrency: usize,
1243 #[serde(skip_serializing_if = "Option::is_none")]
1244 pub ingestion_url: Option<String>,
1245 #[serde(
1246 skip_serializing_if = "Vec::is_empty",
1247 default,
1248 deserialize_with = "deserialize_remote_store_options"
1249 )]
1250 pub remote_store_options: Vec<(String, String)>,
1251}
1252
1253#[derive(Default, Debug, Clone, Deserialize, Serialize)]
1254#[serde(rename_all = "kebab-case")]
1255pub struct StateSnapshotConfig {
1256 #[serde(skip_serializing_if = "Option::is_none")]
1257 pub object_store_config: Option<ObjectStoreConfig>,
1258 pub concurrency: usize,
1259 #[serde(default)]
1263 pub archive_interval_epochs: u64,
1264}
1265
1266#[derive(Default, Debug, Clone, Deserialize, Serialize)]
1267#[serde(rename_all = "kebab-case")]
1268pub struct TransactionKeyValueStoreWriteConfig {
1269 pub aws_access_key_id: String,
1270 pub aws_secret_access_key: String,
1271 pub aws_region: String,
1272 pub table_name: String,
1273 pub bucket_name: String,
1274 pub concurrency: usize,
1275}
1276
1277#[derive(Clone, Debug, Deserialize, Serialize)]
1282#[serde(rename_all = "kebab-case")]
1283pub struct AuthorityOverloadConfig {
1284 #[serde(default = "default_max_txn_age_in_queue")]
1285 pub max_txn_age_in_queue: Duration,
1286
1287 #[serde(default = "default_overload_monitor_interval")]
1289 pub overload_monitor_interval: Duration,
1290
1291 #[serde(default = "default_execution_queue_latency_soft_limit")]
1293 pub execution_queue_latency_soft_limit: Duration,
1294
1295 #[serde(default = "default_execution_queue_latency_hard_limit")]
1297 pub execution_queue_latency_hard_limit: Duration,
1298
1299 #[serde(default = "default_max_load_shedding_percentage")]
1301 pub max_load_shedding_percentage: u32,
1302
1303 #[serde(default = "default_min_load_shedding_percentage_above_hard_limit")]
1306 pub min_load_shedding_percentage_above_hard_limit: u32,
1307
1308 #[serde(default = "default_safe_transaction_ready_rate")]
1311 pub safe_transaction_ready_rate: u32,
1312
1313 #[serde(default = "default_check_system_overload_at_signing")]
1316 pub check_system_overload_at_signing: bool,
1317
1318 #[serde(default, skip_serializing_if = "std::ops::Not::not")]
1321 pub check_system_overload_at_execution: bool,
1322
1323 #[serde(default = "default_max_transaction_manager_queue_length")]
1326 pub max_transaction_manager_queue_length: usize,
1327
1328 #[serde(default = "default_max_transaction_manager_per_object_queue_length")]
1331 pub max_transaction_manager_per_object_queue_length: usize,
1332}
1333
1334fn default_max_txn_age_in_queue() -> Duration {
1335 Duration::from_millis(1000)
1336}
1337
1338fn default_overload_monitor_interval() -> Duration {
1339 Duration::from_secs(10)
1340}
1341
1342fn default_execution_queue_latency_soft_limit() -> Duration {
1343 Duration::from_secs(1)
1344}
1345
1346fn default_execution_queue_latency_hard_limit() -> Duration {
1347 Duration::from_secs(10)
1348}
1349
1350fn default_max_load_shedding_percentage() -> u32 {
1351 95
1352}
1353
1354fn default_min_load_shedding_percentage_above_hard_limit() -> u32 {
1355 50
1356}
1357
1358fn default_safe_transaction_ready_rate() -> u32 {
1359 100
1360}
1361
1362fn default_check_system_overload_at_signing() -> bool {
1363 true
1364}
1365
1366fn default_max_transaction_manager_queue_length() -> usize {
1367 100_000
1368}
1369
1370fn default_max_transaction_manager_per_object_queue_length() -> usize {
1371 2000
1372}
1373
1374impl Default for AuthorityOverloadConfig {
1375 fn default() -> Self {
1376 Self {
1377 max_txn_age_in_queue: default_max_txn_age_in_queue(),
1378 overload_monitor_interval: default_overload_monitor_interval(),
1379 execution_queue_latency_soft_limit: default_execution_queue_latency_soft_limit(),
1380 execution_queue_latency_hard_limit: default_execution_queue_latency_hard_limit(),
1381 max_load_shedding_percentage: default_max_load_shedding_percentage(),
1382 min_load_shedding_percentage_above_hard_limit:
1383 default_min_load_shedding_percentage_above_hard_limit(),
1384 safe_transaction_ready_rate: default_safe_transaction_ready_rate(),
1385 check_system_overload_at_signing: true,
1386 check_system_overload_at_execution: false,
1387 max_transaction_manager_queue_length: default_max_transaction_manager_queue_length(),
1388 max_transaction_manager_per_object_queue_length:
1389 default_max_transaction_manager_per_object_queue_length(),
1390 }
1391 }
1392}
1393
1394fn default_authority_overload_config() -> AuthorityOverloadConfig {
1395 AuthorityOverloadConfig::default()
1396}
1397
1398fn default_traffic_controller_policy_config() -> Option<PolicyConfig> {
1399 Some(PolicyConfig::default_dos_protection_policy())
1400}
1401
1402#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Eq)]
1403pub struct Genesis {
1404 #[serde(flatten)]
1405 location: GenesisLocation,
1406
1407 #[serde(skip)]
1408 genesis: once_cell::sync::OnceCell<genesis::Genesis>,
1409}
1410
1411impl Genesis {
1412 pub fn new(genesis: genesis::Genesis) -> Self {
1413 Self {
1414 location: GenesisLocation::InPlace { genesis },
1415 genesis: Default::default(),
1416 }
1417 }
1418
1419 pub fn new_from_file<P: Into<PathBuf>>(path: P) -> Self {
1420 Self {
1421 location: GenesisLocation::File {
1422 genesis_file_location: path.into(),
1423 },
1424 genesis: Default::default(),
1425 }
1426 }
1427
1428 pub fn genesis(&self) -> Result<&genesis::Genesis> {
1429 match &self.location {
1430 GenesisLocation::InPlace { genesis } => Ok(genesis),
1431 GenesisLocation::File {
1432 genesis_file_location,
1433 } => self
1434 .genesis
1435 .get_or_try_init(|| genesis::Genesis::load(genesis_file_location)),
1436 }
1437 }
1438}
1439
1440#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Eq)]
1441#[serde(untagged)]
1442#[allow(clippy::large_enum_variant)]
1443enum GenesisLocation {
1444 InPlace {
1445 genesis: genesis::Genesis,
1446 },
1447 File {
1448 #[serde(rename = "genesis-file-location")]
1449 genesis_file_location: PathBuf,
1450 },
1451}
1452
1453#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
1455pub struct KeyPairWithPath {
1456 #[serde(flatten)]
1457 location: KeyPairLocation,
1458
1459 #[serde(skip)]
1460 keypair: OnceCell<Arc<SuiKeyPair>>,
1461}
1462
1463#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Eq)]
1464#[serde_as]
1465#[serde(untagged)]
1466enum KeyPairLocation {
1467 InPlace {
1468 #[serde_as(as = "Arc<KeyPairBase64>")]
1469 value: Arc<SuiKeyPair>,
1470 },
1471 File {
1472 #[serde(rename = "path")]
1473 path: PathBuf,
1474 },
1475}
1476
1477impl KeyPairWithPath {
1478 pub fn new(kp: SuiKeyPair) -> Self {
1479 let cell: OnceCell<Arc<SuiKeyPair>> = OnceCell::new();
1480 let arc_kp = Arc::new(kp);
1481 cell.set(arc_kp.clone()).expect("Failed to set keypair");
1483 Self {
1484 location: KeyPairLocation::InPlace { value: arc_kp },
1485 keypair: cell,
1486 }
1487 }
1488
1489 pub fn new_from_path(path: PathBuf) -> Self {
1490 let cell: OnceCell<Arc<SuiKeyPair>> = OnceCell::new();
1491 cell.set(Arc::new(read_keypair_from_file(&path).unwrap_or_else(
1493 |e| panic!("Invalid keypair file at path {:?}: {e}", &path),
1494 )))
1495 .expect("Failed to set keypair");
1496 Self {
1497 location: KeyPairLocation::File { path },
1498 keypair: cell,
1499 }
1500 }
1501
1502 pub fn keypair(&self) -> &SuiKeyPair {
1503 self.keypair
1504 .get_or_init(|| match &self.location {
1505 KeyPairLocation::InPlace { value } => value.clone(),
1506 KeyPairLocation::File { path } => {
1507 Arc::new(
1509 read_keypair_from_file(path).unwrap_or_else(|e| {
1510 panic!("Invalid keypair file at path {:?}: {e}", path)
1511 }),
1512 )
1513 }
1514 })
1515 .as_ref()
1516 }
1517}
1518
1519#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
1521pub struct AuthorityKeyPairWithPath {
1522 #[serde(flatten)]
1523 location: AuthorityKeyPairLocation,
1524
1525 #[serde(skip)]
1526 keypair: OnceCell<Arc<AuthorityKeyPair>>,
1527}
1528
1529#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Eq)]
1530#[serde_as]
1531#[serde(untagged)]
1532enum AuthorityKeyPairLocation {
1533 InPlace { value: Arc<AuthorityKeyPair> },
1534 File { path: PathBuf },
1535}
1536
1537impl AuthorityKeyPairWithPath {
1538 pub fn new(kp: AuthorityKeyPair) -> Self {
1539 let cell: OnceCell<Arc<AuthorityKeyPair>> = OnceCell::new();
1540 let arc_kp = Arc::new(kp);
1541 cell.set(arc_kp.clone())
1543 .expect("Failed to set authority keypair");
1544 Self {
1545 location: AuthorityKeyPairLocation::InPlace { value: arc_kp },
1546 keypair: cell,
1547 }
1548 }
1549
1550 pub fn new_from_path(path: PathBuf) -> Self {
1551 let cell: OnceCell<Arc<AuthorityKeyPair>> = OnceCell::new();
1552 cell.set(Arc::new(
1554 read_authority_keypair_from_file(&path)
1555 .unwrap_or_else(|_| panic!("Invalid authority keypair file at path {:?}", &path)),
1556 ))
1557 .expect("Failed to set authority keypair");
1558 Self {
1559 location: AuthorityKeyPairLocation::File { path },
1560 keypair: cell,
1561 }
1562 }
1563
1564 pub fn authority_keypair(&self) -> &AuthorityKeyPair {
1565 self.keypair
1566 .get_or_init(|| match &self.location {
1567 AuthorityKeyPairLocation::InPlace { value } => value.clone(),
1568 AuthorityKeyPairLocation::File { path } => {
1569 Arc::new(
1571 read_authority_keypair_from_file(path).unwrap_or_else(|_| {
1572 panic!("Invalid authority keypair file {:?}", &path)
1573 }),
1574 )
1575 }
1576 })
1577 .as_ref()
1578 }
1579}
1580
1581#[derive(Clone, Debug, Deserialize, Serialize, Default)]
1584#[serde(rename_all = "kebab-case")]
1585pub struct StateDebugDumpConfig {
1586 #[serde(skip_serializing_if = "Option::is_none")]
1587 pub dump_file_directory: Option<PathBuf>,
1588}
1589
1590fn read_credential_from_path_or_literal(value: &str) -> Result<String, std::io::Error> {
1591 let path = Path::new(value);
1592 if path.exists() && path.is_file() {
1593 std::fs::read_to_string(path).map(|content| content.trim().to_string())
1594 } else {
1595 Ok(value.to_string())
1596 }
1597}
1598
1599fn deserialize_remote_store_options<'de, D>(
1601 deserializer: D,
1602) -> Result<Vec<(String, String)>, D::Error>
1603where
1604 D: serde::Deserializer<'de>,
1605{
1606 use serde::de::Error;
1607
1608 let raw_options: Vec<(String, String)> = Vec::deserialize(deserializer)?;
1609 let mut processed_options = Vec::new();
1610
1611 for (key, value) in raw_options {
1612 let is_service_account_path = matches!(
1615 key.as_str(),
1616 "google_service_account"
1617 | "service_account"
1618 | "google_service_account_path"
1619 | "service_account_path"
1620 );
1621
1622 let processed_value = if is_service_account_path {
1623 value
1624 } else {
1625 match read_credential_from_path_or_literal(&value) {
1626 Ok(processed) => processed,
1627 Err(e) => {
1628 return Err(D::Error::custom(format!(
1629 "Failed to read credential for key '{}': {}",
1630 key, e
1631 )));
1632 }
1633 }
1634 };
1635
1636 processed_options.push((key, processed_value));
1637 }
1638
1639 Ok(processed_options)
1640}
1641
1642#[cfg(test)]
1643mod tests {
1644 use std::path::PathBuf;
1645
1646 use fastcrypto::traits::KeyPair;
1647 use rand::{SeedableRng, rngs::StdRng};
1648 use sui_keys::keypair_file::{write_authority_keypair_to_file, write_keypair_to_file};
1649 use sui_types::crypto::{AuthorityKeyPair, NetworkKeyPair, SuiKeyPair, get_key_pair_from_rng};
1650
1651 use super::{Genesis, StateArchiveConfig};
1652 use crate::NodeConfig;
1653
1654 #[test]
1655 fn serialize_genesis_from_file() {
1656 let g = Genesis::new_from_file("path/to/file");
1657
1658 let s = serde_yaml::to_string(&g).unwrap();
1659 assert_eq!("---\ngenesis-file-location: path/to/file\n", s);
1660 let loaded_genesis: Genesis = serde_yaml::from_str(&s).unwrap();
1661 assert_eq!(g, loaded_genesis);
1662 }
1663
1664 #[test]
1665 fn fullnode_template() {
1666 const TEMPLATE: &str = include_str!("../data/fullnode-template.yaml");
1667
1668 let _template: NodeConfig = serde_yaml::from_str(TEMPLATE).unwrap();
1669 }
1670
1671 #[test]
1673 fn legacy_validator_config() {
1674 const FILE: &str = include_str!("../data/sui-node-legacy.yaml");
1675
1676 let _template: NodeConfig = serde_yaml::from_str(FILE).unwrap();
1677 }
1678
1679 #[test]
1680 fn load_key_pairs_to_node_config() {
1681 let protocol_key_pair: AuthorityKeyPair =
1682 get_key_pair_from_rng(&mut StdRng::from_seed([0; 32])).1;
1683 let worker_key_pair: NetworkKeyPair =
1684 get_key_pair_from_rng(&mut StdRng::from_seed([0; 32])).1;
1685 let network_key_pair: NetworkKeyPair =
1686 get_key_pair_from_rng(&mut StdRng::from_seed([0; 32])).1;
1687
1688 write_authority_keypair_to_file(&protocol_key_pair, PathBuf::from("protocol.key")).unwrap();
1689 write_keypair_to_file(
1690 &SuiKeyPair::Ed25519(worker_key_pair.copy()),
1691 PathBuf::from("worker.key"),
1692 )
1693 .unwrap();
1694 write_keypair_to_file(
1695 &SuiKeyPair::Ed25519(network_key_pair.copy()),
1696 PathBuf::from("network.key"),
1697 )
1698 .unwrap();
1699
1700 const TEMPLATE: &str = include_str!("../data/fullnode-template-with-path.yaml");
1701 let template: NodeConfig = serde_yaml::from_str(TEMPLATE).unwrap();
1702 assert_eq!(
1703 template.protocol_key_pair().public(),
1704 protocol_key_pair.public()
1705 );
1706 assert_eq!(
1707 template.network_key_pair().public(),
1708 network_key_pair.public()
1709 );
1710 assert_eq!(
1711 template.worker_key_pair().public(),
1712 worker_key_pair.public()
1713 );
1714 }
1715
1716 #[test]
1717 fn test_remote_store_options_file_path_support() {
1718 let temp_dir = std::env::temp_dir();
1720 let access_key_file = temp_dir.join("test_access_key");
1721 let secret_key_file = temp_dir.join("test_secret_key");
1722
1723 std::fs::write(&access_key_file, "test_access_key_value").unwrap();
1724 std::fs::write(&secret_key_file, "test_secret_key_value\n").unwrap();
1725
1726 let yaml_config = format!(
1727 r#"
1728object-store-config: null
1729concurrency: 5
1730ingestion-url: "https://example.com"
1731remote-store-options:
1732 - ["aws_access_key_id", "{}"]
1733 - ["aws_secret_access_key", "{}"]
1734 - ["literal_key", "literal_value"]
1735"#,
1736 access_key_file.to_string_lossy(),
1737 secret_key_file.to_string_lossy()
1738 );
1739
1740 let config: StateArchiveConfig = serde_yaml::from_str(&yaml_config).unwrap();
1741
1742 assert_eq!(config.remote_store_options.len(), 3);
1744
1745 let access_key_option = config
1746 .remote_store_options
1747 .iter()
1748 .find(|(key, _)| key == "aws_access_key_id")
1749 .unwrap();
1750 assert_eq!(access_key_option.1, "test_access_key_value");
1751
1752 let secret_key_option = config
1753 .remote_store_options
1754 .iter()
1755 .find(|(key, _)| key == "aws_secret_access_key")
1756 .unwrap();
1757 assert_eq!(secret_key_option.1, "test_secret_key_value");
1758
1759 let literal_option = config
1760 .remote_store_options
1761 .iter()
1762 .find(|(key, _)| key == "literal_key")
1763 .unwrap();
1764 assert_eq!(literal_option.1, "literal_value");
1765
1766 std::fs::remove_file(&access_key_file).ok();
1768 std::fs::remove_file(&secret_key_file).ok();
1769 }
1770
1771 #[test]
1772 fn test_remote_store_options_literal_values_only() {
1773 let yaml_config = r#"
1774object-store-config: null
1775concurrency: 5
1776ingestion-url: "https://example.com"
1777remote-store-options:
1778 - ["aws_access_key_id", "literal_access_key"]
1779 - ["aws_secret_access_key", "literal_secret_key"]
1780"#;
1781
1782 let config: StateArchiveConfig = serde_yaml::from_str(yaml_config).unwrap();
1783
1784 assert_eq!(config.remote_store_options.len(), 2);
1785 assert_eq!(config.remote_store_options[0].1, "literal_access_key");
1786 assert_eq!(config.remote_store_options[1].1, "literal_secret_key");
1787 }
1788
1789 #[test]
1790 fn test_remote_store_options_gcs_service_account_path_preserved() {
1791 let temp_dir = std::env::temp_dir();
1792 let service_account_file = temp_dir.join("test_service_account.json");
1793 let aws_key_file = temp_dir.join("test_aws_key");
1794
1795 std::fs::write(&service_account_file, r#"{"type": "service_account"}"#).unwrap();
1796 std::fs::write(&aws_key_file, "aws_key_value").unwrap();
1797
1798 let yaml_config = format!(
1799 r#"
1800object-store-config: null
1801concurrency: 5
1802ingestion-url: "gs://my-bucket"
1803remote-store-options:
1804 - ["service_account", "{}"]
1805 - ["google_service_account_path", "{}"]
1806 - ["aws_access_key_id", "{}"]
1807"#,
1808 service_account_file.to_string_lossy(),
1809 service_account_file.to_string_lossy(),
1810 aws_key_file.to_string_lossy()
1811 );
1812
1813 let config: StateArchiveConfig = serde_yaml::from_str(&yaml_config).unwrap();
1814
1815 assert_eq!(config.remote_store_options.len(), 3);
1816
1817 let service_account_option = config
1819 .remote_store_options
1820 .iter()
1821 .find(|(key, _)| key == "service_account")
1822 .unwrap();
1823 assert_eq!(
1824 service_account_option.1,
1825 service_account_file.to_string_lossy()
1826 );
1827
1828 let gcs_path_option = config
1830 .remote_store_options
1831 .iter()
1832 .find(|(key, _)| key == "google_service_account_path")
1833 .unwrap();
1834 assert_eq!(gcs_path_option.1, service_account_file.to_string_lossy());
1835
1836 let aws_option = config
1838 .remote_store_options
1839 .iter()
1840 .find(|(key, _)| key == "aws_access_key_id")
1841 .unwrap();
1842 assert_eq!(aws_option.1, "aws_key_value");
1843
1844 std::fs::remove_file(&service_account_file).ok();
1846 std::fs::remove_file(&aws_key_file).ok();
1847 }
1848}
1849
1850#[derive(Clone, Copy, PartialEq, Debug, Serialize, Deserialize)]
1853pub enum RunWithRange {
1854 Epoch(EpochId),
1855 Checkpoint(CheckpointSequenceNumber),
1856}
1857
1858impl RunWithRange {
1859 pub fn is_epoch_gt(&self, epoch_id: EpochId) -> bool {
1861 matches!(self, RunWithRange::Epoch(e) if epoch_id > *e)
1862 }
1863
1864 pub fn matches_checkpoint(&self, seq_num: CheckpointSequenceNumber) -> bool {
1865 matches!(self, RunWithRange::Checkpoint(seq) if *seq == seq_num)
1866 }
1867
1868 pub fn into_checkpoint_bound(self) -> Option<CheckpointSequenceNumber> {
1869 match self {
1870 RunWithRange::Epoch(_) => None,
1871 RunWithRange::Checkpoint(seq) => Some(seq),
1872 }
1873 }
1874}