Skip to content

Commit

Permalink
Fixed max-rounds in alephbft. (#1040)
Browse files Browse the repository at this point in the history
  • Loading branch information
DamianStraszak authored Mar 18, 2023
1 parent 642d388 commit 1c24e9e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 102 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bin/node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aleph-node"
version = "0.9.0+mainnet"
version = "0.9.1+mainnet"
authors = ["Cardinal Cryptography"]
description = "Aleph node binary"
edition = "2021"
Expand Down
98 changes: 2 additions & 96 deletions finality-aleph/src/abft/common.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::{sync::Arc, time::Duration};

use crate::{NodeIndex, SessionId, UnitCreationDelay};

const MAX_ROUNDS: u16 = 7000;
use crate::UnitCreationDelay;
pub const MAX_ROUNDS: u16 = 7000;

fn exponential_slowdown(
t: usize,
Expand All @@ -25,103 +24,10 @@ fn exponential_slowdown(
}

pub type DelaySchedule = Arc<dyn Fn(usize) -> Duration + Sync + Send + 'static>;
pub type RecipientCountSchedule = Arc<dyn Fn(usize) -> usize + Sync + Send + 'static>;

pub fn unit_creation_delay_fn(unit_creation_delay: UnitCreationDelay) -> DelaySchedule {
Arc::new(move |t| match t {
0 => Duration::from_millis(2000),
_ => exponential_slowdown(t, unit_creation_delay.0 as f64, 5000, 1.005),
})
}

pub struct DelayConfig {
pub tick_interval: Duration,
pub requests_interval: Duration,
pub unit_rebroadcast_interval_min: Duration,
pub unit_rebroadcast_interval_max: Duration,
pub unit_creation_delay: DelaySchedule,
pub coord_request_delay: DelaySchedule,
pub coord_request_recipients: RecipientCountSchedule,
pub parent_request_delay: DelaySchedule,
pub parent_request_recipients: RecipientCountSchedule,
pub newest_request_delay: DelaySchedule,
}

pub struct AlephConfig {
delay_config: DelayConfig,
n_members: usize,
node_id: NodeIndex,
session_id: SessionId,
}

impl AlephConfig {
pub fn new(
delay_config: DelayConfig,
n_members: usize,
node_id: NodeIndex,
session_id: SessionId,
) -> AlephConfig {
AlephConfig {
delay_config,
n_members,
node_id,
session_id,
}
}
}

impl From<DelayConfig> for legacy_aleph_bft::DelayConfig {
fn from(cfg: DelayConfig) -> Self {
Self {
tick_interval: cfg.tick_interval,
requests_interval: cfg.requests_interval,
unit_rebroadcast_interval_max: cfg.unit_rebroadcast_interval_max,
unit_rebroadcast_interval_min: cfg.unit_rebroadcast_interval_min,
unit_creation_delay: cfg.unit_creation_delay,
}
}
}

impl From<DelayConfig> for current_aleph_bft::DelayConfig {
fn from(cfg: DelayConfig) -> Self {
Self {
tick_interval: cfg.tick_interval,
unit_rebroadcast_interval_max: cfg.unit_rebroadcast_interval_max,
unit_rebroadcast_interval_min: cfg.unit_rebroadcast_interval_min,
unit_creation_delay: cfg.unit_creation_delay,
coord_request_delay: cfg.coord_request_delay,
coord_request_recipients: cfg.coord_request_recipients,
parent_request_delay: cfg.parent_request_delay,
parent_request_recipients: cfg.parent_request_recipients,
newest_request_delay: cfg.newest_request_delay,
}
}
}

impl From<AlephConfig> for current_aleph_bft::Config {
fn from(cfg: AlephConfig) -> Self {
let mut aleph_config = current_aleph_bft::default_config(
cfg.n_members.into(),
cfg.node_id.into(),
cfg.session_id.0 as u64,
);
aleph_config.max_round = MAX_ROUNDS;
aleph_config.delay_config = cfg.delay_config.into();

aleph_config
}
}

impl From<AlephConfig> for legacy_aleph_bft::Config {
fn from(cfg: AlephConfig) -> Self {
let mut aleph_config = legacy_aleph_bft::default_config(
cfg.n_members.into(),
cfg.node_id.into(),
cfg.session_id.0 as u64,
);
aleph_config.max_round = MAX_ROUNDS;
aleph_config.delay_config = cfg.delay_config.into();

aleph_config
}
}
7 changes: 5 additions & 2 deletions finality-aleph/src/abft/current.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use sp_blockchain::HeaderBackend;
use sp_runtime::traits::Block;

use crate::{
abft::{common::unit_creation_delay_fn, NetworkWrapper, SpawnHandleT},
abft::{
common::{unit_creation_delay_fn, MAX_ROUNDS},
NetworkWrapper, SpawnHandleT,
},
crypto::Signature,
data_io::{AlephData, OrderedDataInterpreter},
network::data::Network,
Expand Down Expand Up @@ -72,6 +75,6 @@ pub fn create_aleph_config(
) -> Config {
let mut config = default_config(n_members.into(), node_id.into(), session_id.0 as u64);
config.delay_config.unit_creation_delay = unit_creation_delay_fn(unit_creation_delay);

config.max_round = MAX_ROUNDS;
config
}
4 changes: 2 additions & 2 deletions finality-aleph/src/abft/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use log::debug;
use sp_blockchain::HeaderBackend;
use sp_runtime::traits::Block;

use super::common::unit_creation_delay_fn;
use super::common::{unit_creation_delay_fn, MAX_ROUNDS};
use crate::{
abft::{NetworkWrapper, SpawnHandleT},
data_io::{AlephData, OrderedDataInterpreter},
Expand Down Expand Up @@ -69,6 +69,6 @@ pub fn create_aleph_config(
) -> Config {
let mut config = default_config(n_members.into(), node_id.into(), session_id.0 as u64);
config.delay_config.unit_creation_delay = unit_creation_delay_fn(unit_creation_delay);

config.max_round = MAX_ROUNDS;
config
}

0 comments on commit 1c24e9e

Please sign in to comment.