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, chain_id::ChainId,
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 for executed
26    // transactions (in milliseconds)
27    pub mempool_executed_txn_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 chain_id: ChainId,
45
46    pub hardcoded_epoch_committee: BTreeMap<u64, ValidatorVerifier>,
47}
48
49impl Default for ConsensusConfig {
50    fn default() -> ConsensusConfig {
51        ConsensusConfig {
52            contiguous_rounds: 2,
53            max_block_size: 1000,
54            max_pruned_blocks_in_mem: 100,
55            mempool_txn_pull_timeout_ms: 5000,
56            mempool_executed_txn_timeout_ms: 1000,
57            // TODO(lpl): Decide value.
58            // 60 epochs should have been generated in 4 minutes.
59            round_initial_timeout_ms: 60_000,
60            cip113_round_initial_timeout_ms: 30_000,
61            cip113_transition_epoch: u64::MAX,
62            proposer_type: ConsensusProposerType::VrfProposer,
63            safety_rules: SafetyRulesConfig::default(),
64            sync_only: false,
65            mempool_poll_count: 1,
66            chain_id: Default::default(),
67            hardcoded_epoch_committee: Default::default(),
68        }
69    }
70}
71
72impl ConsensusConfig {
73    pub fn set_data_dir(&mut self, data_dir: PathBuf) {
74        self.safety_rules.set_data_dir(data_dir);
75    }
76}
77
78#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
79#[serde(rename_all = "snake_case", tag = "type")]
80pub enum ConsensusProposerType {
81    // Choose the smallest PeerId as the proposer
82    FixedProposer,
83    // Round robin rotation of proposers
84    RotatingProposer,
85    // Pre-specified proposers for each round,
86    // or default proposer if round proposer not
87    // specified
88    RoundProposer(HashMap<Round, AccountAddress>),
89    // TODO(lpl): Add threshold?
90    VrfProposer,
91}
92
93#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
94#[serde(deny_unknown_fields)]
95pub struct LeaderReputationConfig {
96    pub active_weights: u64,
97    pub inactive_weights: u64,
98}