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
+36 -28
View File
@@ -1331,7 +1331,7 @@ mod tests {
use runtime_primitives::testing::{Block as GenericTestBlock, Header as TestHeader};
use primitives::H256;
use keyring::AuthorityKeyring;
use keyring::Ed25519Keyring;
type TestBlock = GenericTestBlock<()>;
@@ -1436,7 +1436,7 @@ mod tests {
start_round: 0,
})),
round_timeout_multiplier: 10,
key: Arc::new(AuthorityKeyring::One.into()),
key: Arc::new(Ed25519Keyring::One.into()),
factory: DummyFactory
}
}
@@ -1462,10 +1462,10 @@ mod tests {
fn future_gets_preempted() {
let client = FakeClient {
authorities: vec![
AuthorityKeyring::One.into(),
AuthorityKeyring::Two.into(),
AuthorityKeyring::Alice.into(),
AuthorityKeyring::Eve.into(),
Ed25519Keyring::One.into(),
Ed25519Keyring::Two.into(),
Ed25519Keyring::Alice.into(),
Ed25519Keyring::Eve.into(),
],
imported_heights: Mutex::new(HashSet::new()),
};
@@ -1509,17 +1509,17 @@ mod tests {
let hash = [0xff; 32].into();
let authorities = vec![
AuthorityKeyring::One.into(),
AuthorityKeyring::Two.into(),
AuthorityKeyring::Alice.into(),
AuthorityKeyring::Eve.into(),
Ed25519Keyring::One.into(),
Ed25519Keyring::Two.into(),
Ed25519Keyring::Alice.into(),
Ed25519Keyring::Eve.into(),
];
let authorities_keys = vec![
AuthorityKeyring::One.into(),
AuthorityKeyring::Two.into(),
AuthorityKeyring::Alice.into(),
AuthorityKeyring::Eve.into(),
Ed25519Keyring::One.into(),
Ed25519Keyring::Two.into(),
Ed25519Keyring::Alice.into(),
Ed25519Keyring::Eve.into(),
];
let unchecked = UncheckedJustification(rhododendron::UncheckedJustification {
@@ -1570,8 +1570,8 @@ mod tests {
let parent_hash = Default::default();
let authorities = vec![
AuthorityKeyring::Alice.into(),
AuthorityKeyring::Eve.into(),
Ed25519Keyring::Alice.into(),
Ed25519Keyring::Eve.into(),
];
let block = TestBlock {
@@ -1579,7 +1579,11 @@ mod tests {
extrinsics: Default::default()
};
let proposal = sign_message(rhododendron::Message::Propose(1, block.clone()), &AuthorityKeyring::Alice.pair(), parent_hash);;
let proposal = sign_message(
rhododendron::Message::Propose(1, block.clone()),
&Ed25519Keyring::Alice.pair(),
parent_hash,
);
if let rhododendron::LocalizedMessage::Propose(proposal) = proposal {
assert!(check_proposal(&authorities, &parent_hash, &proposal).is_ok());
let mut invalid_round = proposal.clone();
@@ -1593,7 +1597,11 @@ mod tests {
}
// Not an authority
let proposal = sign_message::<TestBlock>(rhododendron::Message::Propose(1, block), &AuthorityKeyring::Bob.pair(), parent_hash);;
let proposal = sign_message::<TestBlock>(
rhododendron::Message::Propose(1, block),
&Ed25519Keyring::Bob.pair(),
parent_hash,
);
if let rhododendron::LocalizedMessage::Propose(proposal) = proposal {
assert!(check_proposal(&authorities, &parent_hash, &proposal).is_err());
} else {
@@ -1607,8 +1615,8 @@ mod tests {
let hash: H256 = [0xff; 32].into();
let authorities = vec![
AuthorityKeyring::Alice.into(),
AuthorityKeyring::Eve.into(),
Ed25519Keyring::Alice.into(),
Ed25519Keyring::Eve.into(),
];
let vote = sign_message::<TestBlock>(rhododendron::Message::Vote(rhododendron::Vote::Prepare(1, hash)), &Keyring::Alice.pair(), parent_hash);;
@@ -1634,10 +1642,10 @@ mod tests {
fn drop_bft_future_does_not_deadlock() {
let client = FakeClient {
authorities: vec![
AuthorityKeyring::One.into(),
AuthorityKeyring::Two.into(),
AuthorityKeyring::Alice.into(),
AuthorityKeyring::Eve.into(),
Ed25519Keyring::One.into(),
Ed25519Keyring::Two.into(),
Ed25519Keyring::Alice.into(),
Ed25519Keyring::Eve.into(),
],
imported_heights: Mutex::new(HashSet::new()),
};
@@ -1659,10 +1667,10 @@ mod tests {
fn bft_can_build_though_skipped() {
let client = FakeClient {
authorities: vec![
AuthorityKeyring::One.into(),
AuthorityKeyring::Two.into(),
AuthorityKeyring::Alice.into(),
AuthorityKeyring::Eve.into(),
Ed25519Keyring::One.into(),
Ed25519Keyring::Two.into(),
Ed25519Keyring::Alice.into(),
Ed25519Keyring::Eve.into(),
],
imported_heights: Mutex::new(HashSet::new()),
};
@@ -74,7 +74,7 @@ pub fn evaluate_misbehavior<B: Codec, H: Codec + Copy>(
mod tests {
use super::*;
use keyring::AuthorityKeyring;
use keyring::Ed25519Keyring;
use rhododendron;
use runtime_primitives::testing::{H256, Block as RawBlock};
@@ -109,7 +109,7 @@ mod tests {
#[test]
fn evaluates_double_prepare() {
let key = AuthorityKeyring::One.pair();
let key = Ed25519Keyring::One.pair();
let parent_hash = [0xff; 32].into();
let hash_1 = [0; 32].into();
let hash_2 = [1; 32].into();
@@ -138,7 +138,7 @@ mod tests {
// misbehavior has wrong target.
assert!(!evaluate_misbehavior::<Block, H256>(
&AuthorityKeyring::Two.into(),
&Ed25519Keyring::Two.into(),
parent_hash,
&MisbehaviorKind::BftDoublePrepare(
1,
@@ -150,7 +150,7 @@ mod tests {
#[test]
fn evaluates_double_commit() {
let key = AuthorityKeyring::One.pair();
let key = Ed25519Keyring::One.pair();
let parent_hash = [0xff; 32].into();
let hash_1 = [0; 32].into();
let hash_2 = [1; 32].into();
@@ -179,7 +179,7 @@ mod tests {
// misbehavior has wrong target.
assert!(!evaluate_misbehavior::<Block, H256>(
&AuthorityKeyring::Two.into(),
&Ed25519Keyring::Two.into(),
parent_hash,
&MisbehaviorKind::BftDoubleCommit(
1,