casper_node/types/
node_config.rs1use datasize::DataSize;
2use serde::{Deserialize, Serialize};
3
4use casper_types::{BlockHash, TimeDiff};
5
6const DEFAULT_IDLE_TOLERANCE: &str = "20min";
7const DEFAULT_MAX_ATTEMPTS: usize = 3;
8const DEFAULT_CONTROL_LOGIC_DEFAULT_DELAY: &str = "1sec";
9const DEFAULT_SHUTDOWN_FOR_UPGRADE_TIMEOUT: &str = "2min";
10const DEFAULT_UPGRADE_TIMEOUT: &str = "30sec";
11
12#[derive(DataSize, Debug, Deserialize, Serialize, Clone, Default, Eq, PartialEq)]
14#[serde(rename_all = "lowercase")]
15pub enum SyncHandling {
16 Genesis,
18 #[default]
20 Ttl,
21 NoSync,
23 CompleteBlock,
26 Isolated,
29}
30
31impl SyncHandling {
32 pub fn is_sync_to_genesis(&self) -> bool {
34 matches!(self, SyncHandling::Genesis)
35 }
36
37 pub fn is_sync_to_ttl(&self) -> bool {
39 matches!(self, SyncHandling::Ttl)
40 }
41
42 pub fn is_no_sync(&self) -> bool {
44 matches!(self, SyncHandling::NoSync)
45 }
46
47 pub fn is_complete_block(&self) -> bool {
49 matches!(self, SyncHandling::CompleteBlock)
50 }
51
52 pub fn is_isolated(&self) -> bool {
54 matches!(self, SyncHandling::Isolated)
55 }
56}
57
58#[derive(DataSize, Debug, Deserialize, Serialize, Clone)]
60#[serde(deny_unknown_fields)]
62pub struct NodeConfig {
63 pub trusted_hash: Option<BlockHash>,
65
66 pub sync_handling: SyncHandling,
71
72 pub idle_tolerance: TimeDiff,
74
75 pub max_attempts: usize,
78
79 pub control_logic_default_delay: TimeDiff,
81
82 pub force_resync: bool,
84
85 pub shutdown_for_upgrade_timeout: TimeDiff,
88
89 pub upgrade_timeout: TimeDiff,
91
92 pub prevent_validator_shutdown: bool,
94}
95
96impl Default for NodeConfig {
97 fn default() -> NodeConfig {
98 NodeConfig {
99 trusted_hash: None,
100 sync_handling: SyncHandling::default(),
101 idle_tolerance: DEFAULT_IDLE_TOLERANCE.parse().unwrap(),
102 max_attempts: DEFAULT_MAX_ATTEMPTS,
103 control_logic_default_delay: DEFAULT_CONTROL_LOGIC_DEFAULT_DELAY.parse().unwrap(),
104 force_resync: false,
105 shutdown_for_upgrade_timeout: DEFAULT_SHUTDOWN_FOR_UPGRADE_TIMEOUT.parse().unwrap(),
106 upgrade_timeout: DEFAULT_UPGRADE_TIMEOUT.parse().unwrap(),
107 prevent_validator_shutdown: false,
108 }
109 }
110}