consensus_config/
consensus_protocol_config.rs1#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
7pub enum ChainType {
8 #[default]
9 Unknown,
10 Testnet,
11 Mainnet,
12}
13
14#[derive(Clone, Debug)]
18pub struct ConsensusProtocolConfig {
19 protocol_version: u64,
20 chain: ChainType,
21 max_transaction_size_bytes: u64,
22 max_transactions_in_block_bytes: u64,
23 max_num_transactions_in_block: u64,
24 gc_depth: u32,
25 transaction_voting_enabled: bool,
26 num_leaders_per_round: Option<usize>,
27 bad_nodes_stake_threshold: u64,
28 enable_v3: bool,
29}
30
31impl Default for ConsensusProtocolConfig {
32 fn default() -> Self {
33 Self {
34 protocol_version: 0,
35 chain: ChainType::Unknown,
36 max_transaction_size_bytes: 256 * 1024,
37 max_transactions_in_block_bytes: if cfg!(msim) { 256 * 1024 } else { 512 * 1024 },
38 max_num_transactions_in_block: if cfg!(msim) { 8 } else { 512 },
39 gc_depth: 0,
40 transaction_voting_enabled: false,
41 num_leaders_per_round: None,
42 bad_nodes_stake_threshold: 0,
43 enable_v3: false,
44 }
45 }
46}
47
48impl ConsensusProtocolConfig {
49 pub fn new(
50 protocol_version: u64,
51 chain: ChainType,
52 max_transaction_size_bytes: u64,
53 max_transactions_in_block_bytes: u64,
54 max_num_transactions_in_block: u64,
55 gc_depth: u32,
56 transaction_voting_enabled: bool,
57 num_leaders_per_round: Option<usize>,
58 bad_nodes_stake_threshold: u64,
59 enable_v3: bool,
60 ) -> Self {
61 Self {
62 protocol_version,
63 chain,
64 max_transaction_size_bytes,
65 max_transactions_in_block_bytes,
66 max_num_transactions_in_block,
67 gc_depth,
68 transaction_voting_enabled,
69 num_leaders_per_round,
70 bad_nodes_stake_threshold,
71 enable_v3,
72 }
73 }
74
75 pub fn for_testing() -> Self {
78 Self {
79 protocol_version: u64::MAX,
80 chain: ChainType::Unknown,
81 max_transaction_size_bytes: 256 * 1024,
82 max_transactions_in_block_bytes: if cfg!(msim) { 256 * 1024 } else { 512 * 1024 },
83 max_num_transactions_in_block: if cfg!(msim) { 8 } else { 512 },
84 gc_depth: if cfg!(msim) { 6 } else { 60 },
85 transaction_voting_enabled: true,
86 num_leaders_per_round: Some(1),
87 bad_nodes_stake_threshold: 30,
88 enable_v3: false,
89 }
90 }
91
92 pub fn protocol_version(&self) -> u64 {
95 self.protocol_version
96 }
97
98 pub fn chain(&self) -> ChainType {
99 self.chain
100 }
101
102 pub fn max_transaction_size_bytes(&self) -> u64 {
103 self.max_transaction_size_bytes
104 }
105
106 pub fn max_transactions_in_block_bytes(&self) -> u64 {
107 self.max_transactions_in_block_bytes
108 }
109
110 pub fn max_num_transactions_in_block(&self) -> u64 {
111 self.max_num_transactions_in_block
112 }
113
114 pub fn gc_depth(&self) -> u32 {
115 self.gc_depth
116 }
117
118 pub fn transaction_voting_enabled(&self) -> bool {
119 self.transaction_voting_enabled
120 }
121
122 pub fn num_leaders_per_round(&self) -> Option<usize> {
123 self.num_leaders_per_round
124 }
125
126 pub fn bad_nodes_stake_threshold(&self) -> u64 {
127 self.bad_nodes_stake_threshold
128 }
129
130 pub fn enable_v3(&self) -> bool {
131 self.enable_v3
132 }
133
134 pub fn set_gc_depth_for_testing(&mut self, val: u32) {
137 self.gc_depth = val;
138 }
139
140 pub fn set_transaction_voting_enabled_for_testing(&mut self, val: bool) {
141 self.transaction_voting_enabled = val;
142 }
143
144 pub fn set_max_transaction_size_bytes_for_testing(&mut self, val: u64) {
145 self.max_transaction_size_bytes = val;
146 }
147
148 pub fn set_max_transactions_in_block_bytes_for_testing(&mut self, val: u64) {
149 self.max_transactions_in_block_bytes = val;
150 }
151
152 pub fn set_max_num_transactions_in_block_for_testing(&mut self, val: u64) {
153 self.max_num_transactions_in_block = val;
154 }
155
156 pub fn set_bad_nodes_stake_threshold_for_testing(&mut self, val: u64) {
157 self.bad_nodes_stake_threshold = val;
158 }
159
160 pub fn set_num_leaders_per_round_for_testing(&mut self, val: Option<usize>) {
161 self.num_leaders_per_round = val;
162 }
163
164 pub fn set_enable_v3_for_testing(&mut self, val: bool) {
165 self.enable_v3 = val;
166 }
167}