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
+32 -20
View File
@@ -26,9 +26,10 @@ use support::{
};
use substrate_primitives::u32_trait::{_1, _2, _3, _4};
use node_primitives::{
AccountId, AccountIndex, AuraId, Balance, BlockNumber, Hash, Index,
AccountId, AccountIndex, Balance, BlockNumber, Hash, Index,
Moment, Signature,
};
use babe::{AuthorityId as BabeId};
use grandpa::fg_primitives::{self, ScheduledChange};
use client::{
block_builder::api::{self as block_builder_api, InherentData, CheckInherentsResult},
@@ -137,9 +138,12 @@ impl system::Trait for Runtime {
type MaximumBlockLength = MaximumBlockLength;
}
impl aura::Trait for Runtime {
type HandleReport = aura::StakingSlasher<Runtime>;
type AuthorityId = AuraId;
parameter_types! {
pub const EpochDuration: u64 = 10 * MINUTES;
}
impl babe::Trait for Runtime {
type EpochDuration = EpochDuration;
}
impl indices::Trait for Runtime {
@@ -177,7 +181,7 @@ parameter_types! {
}
impl timestamp::Trait for Runtime {
type Moment = Moment;
type OnTimestampSet = Aura;
type OnTimestampSet = Babe;
type MinimumPeriod = MinimumPeriod;
}
@@ -193,17 +197,14 @@ impl authorship::Trait for Runtime {
type EventHandler = ();
}
parameter_types! {
pub const Period: BlockNumber = 10 * MINUTES;
pub const Offset: BlockNumber = 0;
}
type SessionHandlers = (Grandpa, Aura, ImOnline);
type SessionHandlers = (Grandpa, Babe, ImOnline);
impl_opaque_keys! {
pub struct SessionKeys {
#[id(key_types::ED25519)]
pub ed25519: GrandpaId,
#[id(key_types::SR25519)]
pub sr25519: BabeId,
}
}
@@ -216,7 +217,7 @@ impl_opaque_keys! {
impl session::Trait for Runtime {
type OnSessionEnding = Staking;
type SessionHandler = SessionHandlers;
type ShouldEndSession = session::PeriodicSessions<Period, Offset>;
type ShouldEndSession = Babe;
type Event = Event;
type Keys = SessionKeys;
type ValidatorId = AccountId;
@@ -378,12 +379,12 @@ impl sudo::Trait for Runtime {
}
impl im_online::Trait for Runtime {
type AuthorityId = AuraId;
type AuthorityId = BabeId;
type Call = Call;
type Event = Event;
type SessionsPerEra = SessionsPerEra;
type UncheckedExtrinsic = UncheckedExtrinsic;
type IsValidAuthorityId = Aura;
type IsValidAuthorityId = Babe;
}
impl grandpa::Trait for Runtime {
@@ -408,7 +409,7 @@ construct_runtime!(
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system::{Module, Call, Storage, Config, Event},
Aura: aura::{Module, Call, Storage, Config<T>, Inherent(Timestamp)},
Babe: babe::{Module, Call, Storage, Config, Inherent(Timestamp)},
Timestamp: timestamp::{Module, Call, Storage, Inherent},
Authorship: authorship::{Module, Call, Storage},
Indices: indices,
@@ -525,12 +526,23 @@ impl_runtime_apis! {
}
}
impl consensus_aura::AuraApi<Block, AuraId> for Runtime {
fn slot_duration() -> u64 {
Aura::slot_duration()
impl babe_primitives::BabeApi<Block> for Runtime {
fn startup_data() -> babe_primitives::BabeConfiguration {
babe_primitives::BabeConfiguration {
median_required_blocks: 1000,
slot_duration: Babe::slot_duration(),
c: (3, 10),
}
}
fn authorities() -> Vec<AuraId> {
Aura::authorities()
fn epoch() -> babe_primitives::Epoch {
babe_primitives::Epoch {
start_slot: Babe::epoch_start_slot(),
authorities: Babe::authorities(),
epoch_index: Babe::epoch_index(),
randomness: Babe::randomness(),
duration: EpochDuration::get(),
}
}
}
}