Unverified Commit 23f1e765 authored by Gavin Wood's avatar Gavin Wood Committed by GitHub
Browse files

Blocktime and epoch length tweaks. (#379)

* Blocktime and epoch length tweaks.

* Tweak probabilities.

* Deduplication.

* Add testnet values.
parent 726d2e8d
Pipeline #49544 passed with stages
in 13 minutes and 47 seconds
......@@ -24,25 +24,26 @@ pub mod currency {
pub const MILLICENTS: Balance = CENTS / 1_000;
}
/// Time.
/// Time and blocks.
pub mod time {
use primitives::{Moment, BlockNumber};
pub const MILLISECS_PER_BLOCK: Moment = 6000;
pub const SLOT_DURATION: Moment = 1650;
// Kusama & mainnet
// pub const MILLISECS_PER_BLOCK: Moment = 6000;
// Testnet
pub const MILLISECS_PER_BLOCK: Moment = 1000;
pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK;
// Kusama & mainnet
// pub const EPOCH_DURATION_IN_BLOCKS: BlockNumber = 4 * HOURS;
// Testnet
pub const EPOCH_DURATION_IN_BLOCKS: BlockNumber = 10 * MINUTES;
pub const EPOCH_DURATION_IN_SLOTS: u64 = {
const SLOT_FILL_RATE: f64 = MILLISECS_PER_BLOCK as f64 / SLOT_DURATION as f64;
(EPOCH_DURATION_IN_BLOCKS as f64 * SLOT_FILL_RATE) as u64
};
// These time units are defined in number of blocks.
pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);
pub const HOURS: BlockNumber = MINUTES * 60;
pub const DAYS: BlockNumber = HOURS * 24;
// 1 in 4 blocks (on average, not counting collisions) will be primary babe blocks.
pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4);
}
/// Fee-related.
......
......@@ -162,7 +162,7 @@ impl system::Trait for Runtime {
}
parameter_types! {
pub const EpochDuration: u64 = EPOCH_DURATION_IN_SLOTS;
pub const EpochDuration: u64 = EPOCH_DURATION_IN_BLOCKS as u64;
pub const ExpectedBlockTime: Moment = MILLISECS_PER_BLOCK;
}
......@@ -647,7 +647,7 @@ impl_runtime_apis! {
babe_primitives::BabeConfiguration {
median_required_blocks: 1000,
slot_duration: Babe::slot_duration(),
c: (278, 1000),
c: PRIMARY_PROBABILITY,
}
}
......
......@@ -969,7 +969,7 @@ mod tests {
}
parameter_types! {
pub const EpochDuration: u64 = EPOCH_DURATION_IN_SLOTS;
pub const EpochDuration: u64 = EPOCH_DURATION_IN_BLOCKS as u64;
pub const ExpectedBlockTime: u64 = MILLISECS_PER_BLOCK;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment