use crate::config::SafetyRulesConfig;
use diem_types::{
account_address::AccountAddress, block_info::Round, chain_id::ChainId,
validator_verifier::ValidatorVerifier,
};
use serde::{Deserialize, Serialize};
use std::{
collections::{BTreeMap, HashMap},
path::PathBuf,
};
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
#[serde(default, deny_unknown_fields)]
pub struct ConsensusConfig {
pub contiguous_rounds: u32,
pub max_block_size: u64,
pub max_pruned_blocks_in_mem: usize,
pub mempool_executed_txn_timeout_ms: u64,
pub mempool_txn_pull_timeout_ms: u64,
pub round_initial_timeout_ms: u64,
pub cip113_round_initial_timeout_ms: u64,
pub cip113_transition_epoch: u64,
pub proposer_type: ConsensusProposerType,
pub safety_rules: SafetyRulesConfig,
pub sync_only: bool,
pub mempool_poll_count: u64,
pub chain_id: ChainId,
pub hardcoded_epoch_committee: BTreeMap<u64, ValidatorVerifier>,
}
impl Default for ConsensusConfig {
fn default() -> ConsensusConfig {
ConsensusConfig {
contiguous_rounds: 2,
max_block_size: 1000,
max_pruned_blocks_in_mem: 100,
mempool_txn_pull_timeout_ms: 5000,
mempool_executed_txn_timeout_ms: 1000,
round_initial_timeout_ms: 60_000,
cip113_round_initial_timeout_ms: 30_000,
cip113_transition_epoch: u64::MAX,
proposer_type: ConsensusProposerType::VrfProposer,
safety_rules: SafetyRulesConfig::default(),
sync_only: false,
mempool_poll_count: 1,
chain_id: Default::default(),
hardcoded_epoch_committee: Default::default(),
}
}
}
impl ConsensusConfig {
pub fn set_data_dir(&mut self, data_dir: PathBuf) {
self.safety_rules.set_data_dir(data_dir);
}
}
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "snake_case", tag = "type")]
pub enum ConsensusProposerType {
FixedProposer,
RotatingProposer,
RoundProposer(HashMap<Round, AccountAddress>),
VrfProposer,
}
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(deny_unknown_fields)]
pub struct LeaderReputationConfig {
pub active_weights: u64,
pub inactive_weights: u64,
}