use crate::components::consensus::config::Config as ConsensusConfig;
use datasize::DataSize;
use num_rational::Ratio;
use serde::{Deserialize, Serialize};
pub(crate) const NUM_ROUNDS_TO_CONSIDER: usize = 40;
pub(crate) const NUM_ROUNDS_SLOWDOWN: usize = 10;
pub(crate) const NUM_ROUNDS_SPEEDUP: usize = 32;
pub(crate) const ACCELERATION_PARAMETER: u64 = 40;
pub(crate) const THRESHOLD: u64 = 1;
#[cfg(test)]
pub(crate) const MAX_FAILED_ROUNDS: usize = NUM_ROUNDS_TO_CONSIDER - NUM_ROUNDS_SLOWDOWN - 1;
#[derive(DataSize, Debug, Clone, Copy, Serialize, Deserialize)]
pub struct Config {
pub num_rounds_to_consider: u64,
pub num_rounds_slowdown: u64,
pub num_rounds_speedup: u64,
pub acceleration_parameter: u64,
#[data_size(skip)]
pub acceleration_ftt: Ratio<u64>,
}
impl Default for Config {
fn default() -> Self {
Self {
num_rounds_to_consider: NUM_ROUNDS_TO_CONSIDER as u64,
num_rounds_slowdown: NUM_ROUNDS_SLOWDOWN as u64,
num_rounds_speedup: NUM_ROUNDS_SPEEDUP as u64,
acceleration_parameter: ACCELERATION_PARAMETER,
acceleration_ftt: Ratio::new(THRESHOLD, 100),
}
}
}
impl Config {
pub(crate) fn max_failed_rounds(&self) -> u64 {
self.num_rounds_to_consider
.saturating_sub(self.num_rounds_slowdown)
.saturating_sub(1)
}
pub(crate) fn max_failures_for_acceleration(&self) -> u64 {
self.num_rounds_to_consider
.saturating_sub(self.num_rounds_speedup)
}
}
impl From<&ConsensusConfig> for Config {
fn from(config: &ConsensusConfig) -> Self {
config.highway.round_success_meter
}
}