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}
29
30impl Default for ConsensusProtocolConfig {
31 fn default() -> Self {
32 Self {
33 protocol_version: 0,
34 chain: ChainType::Unknown,
35 max_transaction_size_bytes: 256 * 1024,
36 max_transactions_in_block_bytes: if cfg!(msim) { 256 * 1024 } else { 512 * 1024 },
37 max_num_transactions_in_block: if cfg!(msim) { 8 } else { 512 },
38 gc_depth: 0,
39 transaction_voting_enabled: false,
40 num_leaders_per_round: None,
41 bad_nodes_stake_threshold: 0,
42 }
43 }
44}
45
46impl ConsensusProtocolConfig {
47 pub fn new(
48 protocol_version: u64,
49 chain: ChainType,
50 max_transaction_size_bytes: u64,
51 max_transactions_in_block_bytes: u64,
52 max_num_transactions_in_block: u64,
53 gc_depth: u32,
54 transaction_voting_enabled: bool,
55 num_leaders_per_round: Option<usize>,
56 bad_nodes_stake_threshold: u64,
57 ) -> Self {
58 Self {
59 protocol_version,
60 chain,
61 max_transaction_size_bytes,
62 max_transactions_in_block_bytes,
63 max_num_transactions_in_block,
64 gc_depth,
65 transaction_voting_enabled,
66 num_leaders_per_round,
67 bad_nodes_stake_threshold,
68 }
69 }
70
71 pub fn for_testing() -> Self {
74 Self {
75 protocol_version: u64::MAX,
76 chain: ChainType::Unknown,
77 max_transaction_size_bytes: 256 * 1024,
78 max_transactions_in_block_bytes: if cfg!(msim) { 256 * 1024 } else { 512 * 1024 },
79 max_num_transactions_in_block: if cfg!(msim) { 8 } else { 512 },
80 gc_depth: if cfg!(msim) { 6 } else { 60 },
81 transaction_voting_enabled: true,
82 num_leaders_per_round: Some(1),
83 bad_nodes_stake_threshold: 30,
84 }
85 }
86
87 pub fn protocol_version(&self) -> u64 {
90 self.protocol_version
91 }
92
93 pub fn chain(&self) -> ChainType {
94 self.chain
95 }
96
97 pub fn max_transaction_size_bytes(&self) -> u64 {
98 self.max_transaction_size_bytes
99 }
100
101 pub fn max_transactions_in_block_bytes(&self) -> u64 {
102 self.max_transactions_in_block_bytes
103 }
104
105 pub fn max_num_transactions_in_block(&self) -> u64 {
106 self.max_num_transactions_in_block
107 }
108
109 pub fn gc_depth(&self) -> u32 {
110 self.gc_depth
111 }
112
113 pub fn transaction_voting_enabled(&self) -> bool {
114 self.transaction_voting_enabled
115 }
116
117 pub fn num_leaders_per_round(&self) -> Option<usize> {
118 self.num_leaders_per_round
119 }
120
121 pub fn bad_nodes_stake_threshold(&self) -> u64 {
122 self.bad_nodes_stake_threshold
123 }
124
125 pub fn set_gc_depth_for_testing(&mut self, val: u32) {
128 self.gc_depth = val;
129 }
130
131 pub fn set_transaction_voting_enabled_for_testing(&mut self, val: bool) {
132 self.transaction_voting_enabled = val;
133 }
134
135 pub fn set_max_transaction_size_bytes_for_testing(&mut self, val: u64) {
136 self.max_transaction_size_bytes = val;
137 }
138
139 pub fn set_max_transactions_in_block_bytes_for_testing(&mut self, val: u64) {
140 self.max_transactions_in_block_bytes = val;
141 }
142
143 pub fn set_max_num_transactions_in_block_for_testing(&mut self, val: u64) {
144 self.max_num_transactions_in_block = val;
145 }
146
147 pub fn set_bad_nodes_stake_threshold_for_testing(&mut self, val: u64) {
148 self.bad_nodes_stake_threshold = val;
149 }
150
151 pub fn set_num_leaders_per_round_for_testing(&mut self, val: Option<usize>) {
152 self.num_leaders_per_round = val;
153 }
154}