Use BABE instead of AuRa in node (#3171)

* babe: add babe module trait

* babe: track current slot and epoch start slot

* babe: implement ShouldEndSession based on epochs

* babe: rename weight type to avoid ambiguities

* babe: expose epoch start slot in Epoch digest

* babe: use epoch start for validating epoch transitions

* babe: make the epoch duration a parameter type

* babe: remove unused fields from config

* node: update runtime to use babe instead of aura

* node: use babe instead of aura

* core: generate sr25519 keys from seed and add to keystore

* core: remove AuthorityKeyring

* node: remove unused primitive types related to babe crypto

* uniform babe primitives crate import name

* wrap long lines

* babe: fix find_epoch_digest

* fork-tree: fix find_node_where

* node: set babe epoch duration to "10 minutes"

* babe: cleanup import key cache if authorities don't change

* node: make integration test compile (but fail)

* node: bump spec_version

* node: fix import

* babe: don't use constants in storage fields array sizes

* babe: account for first epoch slot way in the past

* babe: signal next epoch change (not current)

* babe: calculate next epoch randomness with next epoch index

* babe: track next epoch in node

* babe: cache current epoch and authorities separately

* babe: generate valid babe vrf proofs in integration test

* babe: cleanup claim_slot

* babe: perform threshold calculation according to spec

* babe: compute relative weight in threshold

* babe: more precise threshold calculation

* babe: use floats for threshold exponent calculation

* babe: update constant c
This commit is contained in:
André Silva
2019-07-24 20:53:04 +01:00
committed by DemiMarie-parity
parent 407970406d
commit 9f50c8fce4
33 changed files with 784 additions and 429 deletions
+33 -25
View File
@@ -50,11 +50,10 @@ use runtime_version::NativeVersion;
use runtime_support::{impl_outer_origin, parameter_types};
use inherents::{CheckInherentsResult, InherentData};
use cfg_if::cfg_if;
pub use consensus_babe::AuthorityId;
// Ensure Babe and Aura use the same crypto to simplify things a bit.
pub use babe_primitives::AuthorityId;
pub type AuraId = AuthorityId;
// Ensure Babe and Aura use the same crypto to simplify things a bit.
pub type BabeId = AuthorityId;
// Inlucde the WASM binary
#[cfg(feature = "std")]
@@ -356,6 +355,14 @@ impl srml_timestamp::Trait for Runtime {
type MinimumPeriod = MinimumPeriod;
}
parameter_types! {
pub const EpochDuration: u64 = 6;
}
impl srml_babe::Trait for Runtime {
type EpochDuration = EpochDuration;
}
/// Adds one to the given input and returns the final result.
#[inline(never)]
fn benchmark_add_one(i: u64) -> u64 {
@@ -514,29 +521,30 @@ cfg_if! {
}
}
impl consensus_aura::AuraApi<Block, AuraId> for Runtime {
impl aura_primitives::AuraApi<Block, AuraId> for Runtime {
fn slot_duration() -> u64 { 1 }
fn authorities() -> Vec<AuraId> { system::authorities() }
}
impl consensus_babe::BabeApi<Block> for Runtime {
fn startup_data() -> consensus_babe::BabeConfiguration {
consensus_babe::BabeConfiguration {
impl babe_primitives::BabeApi<Block> for Runtime {
fn startup_data() -> babe_primitives::BabeConfiguration {
babe_primitives::BabeConfiguration {
median_required_blocks: 0,
slot_duration: 3,
expected_block_time: 1,
threshold: core::u64::MAX,
slots_per_epoch: 6,
c: (3, 10),
}
}
fn epoch() -> consensus_babe::Epoch {
fn epoch() -> babe_primitives::Epoch {
let authorities = system::authorities();
let authorities: Vec<_> = authorities.into_iter().map(|x|(x, 1)).collect();
consensus_babe::Epoch {
babe_primitives::Epoch {
start_slot: <srml_babe::Module<Runtime>>::epoch_start_slot(),
authorities,
randomness: <srml_babe::Module<Runtime>>::randomness(),
epoch_index: 1,
duration: 6,
epoch_index: <srml_babe::Module<Runtime>>::epoch_index(),
duration: EpochDuration::get(),
}
}
}
@@ -669,30 +677,30 @@ cfg_if! {
}
}
impl consensus_aura::AuraApi<Block, AuraId> for Runtime {
impl aura_primitives::AuraApi<Block, AuraId> for Runtime {
fn slot_duration() -> u64 { 1 }
fn authorities() -> Vec<AuraId> { system::authorities() }
}
impl consensus_babe::BabeApi<Block> for Runtime {
fn startup_data() -> consensus_babe::BabeConfiguration {
consensus_babe::BabeConfiguration {
impl babe_primitives::BabeApi<Block> for Runtime {
fn startup_data() -> babe_primitives::BabeConfiguration {
babe_primitives::BabeConfiguration {
median_required_blocks: 0,
slot_duration: 1,
expected_block_time: 1,
threshold: core::u64::MAX,
slots_per_epoch: 6,
c: (3, 10),
}
}
fn epoch() -> consensus_babe::Epoch {
fn epoch() -> babe_primitives::Epoch {
let authorities = system::authorities();
let authorities: Vec<_> = authorities.into_iter().map(|x|(x, 1)).collect();
consensus_babe::Epoch {
babe_primitives::Epoch {
start_slot: <srml_babe::Module<Runtime>>::epoch_start_slot(),
authorities,
randomness: <srml_babe::Module<Runtime>>::randomness(),
epoch_index: 1,
duration: 6,
epoch_index: <srml_babe::Module<Runtime>>::epoch_index(),
duration: EpochDuration::get(),
}
}
}