diem_config/config/
consensus_config.rs

1// Copyright (c) The Diem Core Contributors
2// SPDX-License-Identifier: Apache-2.0
3
4// Copyright 2021 Conflux Foundation. All rights reserved.
5// Conflux is free software and distributed under GNU General Public License.
6// See http://www.gnu.org/licenses/
7
8use crate::config::SafetyRulesConfig;
9use diem_types::{
10    account_address::AccountAddress, block_info::Round,
11    validator_verifier::ValidatorVerifier,
12};
13use serde::{Deserialize, Serialize};
14use std::{
15    collections::{BTreeMap, HashMap},
16    path::PathBuf,
17};
18
19#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
20#[serde(default, deny_unknown_fields)]
21pub struct ConsensusConfig {
22    pub contiguous_rounds: u32,
23    pub max_block_size: u64,
24    pub max_pruned_blocks_in_mem: usize,
25    // Timeout for consensus to get an ack from mempool after sending a
26    // commit notification for committed transactions (in milliseconds).
27    pub mempool_commit_timeout_ms: u64,
28    // Timeout for consensus to pull transactions from mempool and get a
29    // response (in milliseconds)
30    pub mempool_txn_pull_timeout_ms: u64,
31    pub round_initial_timeout_ms: u64,
32    pub cip113_round_initial_timeout_ms: u64,
33    pub cip113_transition_epoch: u64,
34
35    pub proposer_type: ConsensusProposerType,
36    pub safety_rules: SafetyRulesConfig,
37    // Only sync committed transactions but not vote for any pending blocks.
38    // This is useful when validators coordinate on the latest version to
39    // apply a manual transaction.
40    pub sync_only: bool,
41    // how many times to wait for txns from mempool when propose
42    pub mempool_poll_count: u64,
43
44    pub hardcoded_epoch_committee: BTreeMap<u64, ValidatorVerifier>,
45}
46
47impl Default for ConsensusConfig {
48    fn default() -> ConsensusConfig {
49        ConsensusConfig {
50            contiguous_rounds: 2,
51            max_block_size: 1000,
52            max_pruned_blocks_in_mem: 100,
53            mempool_commit_timeout_ms: 5000,
54            mempool_txn_pull_timeout_ms: 5000,
55            // TODO(lpl): Decide value.
56            // 60 epochs should have been generated in 4 minutes.
57            round_initial_timeout_ms: 60_000,
58            cip113_round_initial_timeout_ms: 30_000,
59            cip113_transition_epoch: u64::MAX,
60            proposer_type: ConsensusProposerType::VrfProposer,
61            safety_rules: SafetyRulesConfig::default(),
62            sync_only: false,
63            mempool_poll_count: 1,
64            hardcoded_epoch_committee: Default::default(),
65        }
66    }
67}
68
69impl ConsensusConfig {
70    pub fn set_data_dir(&mut self, data_dir: PathBuf) {
71        self.safety_rules.set_data_dir(data_dir);
72    }
73}
74
75#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
76#[serde(rename_all = "snake_case", tag = "type")]
77pub enum ConsensusProposerType {
78    // Choose the smallest PeerId as the proposer
79    FixedProposer,
80    // Round robin rotation of proposers
81    RotatingProposer,
82    // Pre-specified proposers for each round,
83    // or default proposer if round proposer not
84    // specified
85    RoundProposer(HashMap<Round, AccountAddress>),
86    // TODO(lpl): Add threshold?
87    VrfProposer,
88}