From 406aad0f9b79dd0c93e0991ebf61ee5b1499c786 Mon Sep 17 00:00:00 2001
From: Gavin Wood <gavin@parity.io>
Date: Fri, 16 Aug 2019 21:48:42 +0200
Subject: [PATCH] Blocktime and epoch length tweaks. (#379)

* Blocktime and epoch length tweaks.

* Tweak probabilities.

* Deduplication.

* Add testnet values.
---
 polkadot/runtime/src/constants.rs  | 23 ++++++++++++-----------
 polkadot/runtime/src/lib.rs        |  4 ++--
 polkadot/runtime/src/parachains.rs |  2 +-
 3 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/polkadot/runtime/src/constants.rs b/polkadot/runtime/src/constants.rs
index 46e6ea0b8db..2a7663a0fd2 100644
--- a/polkadot/runtime/src/constants.rs
+++ b/polkadot/runtime/src/constants.rs
@@ -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.
diff --git a/polkadot/runtime/src/lib.rs b/polkadot/runtime/src/lib.rs
index 3a4fe08e5e7..f98d78ea9ae 100644
--- a/polkadot/runtime/src/lib.rs
+++ b/polkadot/runtime/src/lib.rs
@@ -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,
 			}
 		}
 
diff --git a/polkadot/runtime/src/parachains.rs b/polkadot/runtime/src/parachains.rs
index e6d4b92e45d..84c838319bc 100644
--- a/polkadot/runtime/src/parachains.rs
+++ b/polkadot/runtime/src/parachains.rs
@@ -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;
 	}
 
-- 
GitLab