embedded_td/config/
consensus.rs

1use time::Duration;
2
3use super::define_build_mode_setter;
4
5#[derive(Debug, Clone)]
6pub struct ConsensusConfig {
7    /// How long we wait for a proposal block before prevoting nil
8    pub timeout_propose: Duration,
9    /// How much timeout_propose increases with each round
10    pub timeout_propose_delta: Duration,
11    /// How long we wait after receiving +2/3 prevotes for “anything” (ie. not a single block or nil)
12    pub timeout_prevote: Duration,
13    /// How much the timeout_prevote increases with each round
14    pub timeout_prevote_delta: Duration,
15    /// How long we wait after receiving +2/3 precommits for “anything” (ie. not a single block or nil)
16    pub timeout_precommit: Duration,
17    /// How much the timeout_precommit increases with each round
18    pub timeout_precommit_delta: Duration,
19    /// How long we wait after committing a block, before starting on the new
20    /// height (this gives us a chance to receive some more precommits, even
21    /// though we already have +2/3).
22    pub timeout_commit: Duration,
23
24    /// How many blocks to look back to check existence of the node's consensus votes before joining consensus
25    /// When non-zero, the node will panic upon restart
26    /// if the same consensus key was used to sign {double_sign_check_height} last blocks.
27    /// So, validators should stop the state machine, wait for some blocks, and then restart the state machine to avoid panic.
28    pub double_sign_check_height: u64,
29
30    /// Make progress as soon as we have all the precommits (as if TimeoutCommit = 0)
31    pub skip_timeout_commit: bool,
32
33    /// EmptyBlocks mode and possible interval between empty blocks
34    pub create_empty_blocks: bool,
35    pub create_empty_blocks_interval: Duration,
36
37    /// Reactor sleep duration parameters
38    pub peer_gossip_sleep_duration: Duration,
39    pub peer_query_maj23_sleep_duration: Duration,
40
41    /// Set to true to discard ABCI responses from the state store, which can save a
42    /// considerable amount of disk space. Set to false to ensure ABCI responses are
43    /// persisted. ABCI responses are required for /block_results RPC queries, and to
44    /// reindex events in the command-line tool.
45    pub discard_abci_responses: bool,
46}
47
48impl Default for ConsensusConfig {
49    fn default() -> Self {
50        Self {
51            timeout_propose: Duration::seconds(3),
52            timeout_propose_delta: Duration::milliseconds(500),
53            timeout_prevote: Duration::seconds(1),
54            timeout_prevote_delta: Duration::milliseconds(500),
55            timeout_precommit: Duration::seconds(1),
56            timeout_precommit_delta: Duration::milliseconds(500),
57            timeout_commit: Duration::seconds(1),
58            double_sign_check_height: 0,
59            skip_timeout_commit: false,
60            create_empty_blocks: true,
61            create_empty_blocks_interval: Duration::seconds(0),
62            peer_gossip_sleep_duration: Duration::milliseconds(100),
63            peer_query_maj23_sleep_duration: Duration::seconds(2),
64            discard_abci_responses: false,
65        }
66    }
67}
68
69impl ConsensusConfig {
70    define_build_mode_setter!(timeout_commit, Duration);
71
72    define_build_mode_setter!(timeout_propose, Duration);
73
74    define_build_mode_setter!(timeout_propose_delta, Duration);
75
76    define_build_mode_setter!(timeout_prevote, Duration);
77
78    define_build_mode_setter!(timeout_prevote_delta, Duration);
79
80    define_build_mode_setter!(timeout_precommit, Duration);
81
82    define_build_mode_setter!(timeout_precommit_delta, Duration);
83
84    define_build_mode_setter!(double_sign_check_height, u64);
85
86    define_build_mode_setter!(skip_timeout_commit, bool);
87
88    define_build_mode_setter!(create_empty_blocks, bool);
89
90    define_build_mode_setter!(create_empty_blocks_interval, Duration);
91
92    define_build_mode_setter!(peer_gossip_sleep_duration, Duration);
93
94    define_build_mode_setter!(peer_query_maj23_sleep_duration, Duration);
95
96    define_build_mode_setter!(discard_abci_responses, bool);
97}