Skip to content

Commit

Permalink
A0-4277: Unit creation delay (#1707)
Browse files Browse the repository at this point in the history
# Description

Change `DEFAULT_UNIT_CREATION_DELAY` from `300` ms to `200` ms. Change
`MAX_ROUNDS` and exponential slowdown params accordingly so that the
time to reach it after updating unit creation delay is similar to the
time before the update.

Change the starting round of exponential slowdown from proportionally,
i.e. from 5000 rounds to 7500 rounds, so that the no-slowdown time is 25
min which remains significantly longer than the expected session time
(15 min).

## Testing
The following dummy test-case in AlephBFT:
```rust
let t1: Duration = (0..7000).map(|t| exponential_slowdown(t, 300.0, 5000, 1.005)).sum();
let t2: Duration = (0..10000).map(|t| exponential_slowdown(t, 200.0, 7500, 1.004)).sum();
println!("T1: {:?}", t1);
println!("T2: {:?}", t2);
```
gave output:
```
T1: 1290504.822s
T2: 1081023.038s
```
which is ~14.9 and ~12.5 days correspondingly. This means that the new
time to reach max round will be 12.5 days which is not much smaller than
14.9 days, and at the same time, noticeably longer than the required 7
days.

**Reference**: [exponential
slowdown](https://github.com/Cardinal-Cryptography/AlephBFT/blob/main/consensus/src/config.rs#L97)

## Type of change
- New feature (non-breaking change which adds functionality)
  • Loading branch information
woocash2 authored Apr 30, 2024
1 parent 071be6c commit 8a1778e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docker/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
- CHAIN=/data/chainspec.json
- ALLOW_PRIVATE_IPV4=true
- DISCOVER_LOCAL=true
- UNIT_CREATION_DELAY=300
- UNIT_CREATION_DELAY=200
volumes:
- ./data/:/data/

Expand Down
2 changes: 1 addition & 1 deletion docker/docker_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ PROMETHEUS_ENABLED=${PROMETHEUS_ENABLED:-true}
TELEMETRY_ENABLED=${TELEMETRY_ENABLED:-false}
TELEMETRY_URL=${TELEMETRY_URL:-'wss://telemetry.polkadot.io/submit/'}
TELEMETRY_VERBOSITY_LVL=${TELEMETRY_VERBOSITY_LVL:-'0'}
UNIT_CREATION_DELAY=${UNIT_CREATION_DELAY:-300}
UNIT_CREATION_DELAY=${UNIT_CREATION_DELAY:-200}
DB_CACHE=${DB_CACHE:-1024}
RUNTIME_CACHE_SIZE=${RUNTIME_CACHE_SIZE:-2}
MAX_RUNTIME_INSTANCES=${MAX_RUNTIME_INSTANCES:-8}
Expand Down
2 changes: 1 addition & 1 deletion docker/smartnet-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
- PURGE_BEFORE_START=false
- RPC_PORT=9943
- RUST_LOG=info
- UNIT_CREATION_DELAY=300
- UNIT_CREATION_DELAY=200
- BOOT_NODES=/ip4/127.0.0.1/tcp/30333/p2p/$BOOTNODE_PEER_ID
- PUBLIC_ADDR=/ip4/127.0.0.1/tcp/30333
- VALIDATOR_PORT=30343
Expand Down
17 changes: 15 additions & 2 deletions finality-aleph/src/abft/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ use std::{sync::Arc, time::Duration};

use crate::UnitCreationDelay;

pub const MAX_ROUNDS: u16 = 7000;
// Chosen as a round number large enough so that given the default 200 ms unit creation delay, and the exponential
// slowdown consts below, the time to reach the max round noticeably surpasses the required 7 days. With this
// setting max round should be reached in ~12.5 days.
pub const MAX_ROUNDS: u16 = 10_000;

// Given the default 200 ms unit creation delay, the expected no-slowdown time will be 7500*200/1000/60 = 25 minutes
// which is noticeably longer than the expected 15 minutes of session time.
const EXP_SLOWDOWN_START_ROUND: usize = 7500;
const EXP_SLOWDOWN_MUL: f64 = 1.004;

fn exponential_slowdown(
t: usize,
Expand All @@ -29,7 +37,12 @@ pub type DelaySchedule = Arc<dyn Fn(usize) -> Duration + 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),
_ => exponential_slowdown(
t,
unit_creation_delay.0 as f64,
EXP_SLOWDOWN_START_ROUND,
EXP_SLOWDOWN_MUL,
),
})
}

Expand Down
2 changes: 1 addition & 1 deletion primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ pub const TOKEN: u128 = 10u128.pow(TOKEN_DECIMALS);
pub const ADDRESSES_ENCODING: u8 = 42;

/// ABFT unit creation delay (in ms)
pub const DEFAULT_UNIT_CREATION_DELAY: u64 = 300;
pub const DEFAULT_UNIT_CREATION_DELAY: u64 = 200;

/// Committee Size for new chains
pub const DEFAULT_COMMITTEE_SIZE: u32 = 4;
Expand Down

0 comments on commit 8a1778e

Please sign in to comment.