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
+34 -22
View File
@@ -16,13 +16,14 @@
//! Substrate chain configurations.
use babe_primitives::AuthorityId as BabeId;
use primitives::{ed25519, sr25519, Pair, crypto::UncheckedInto};
use node_primitives::{AccountId, AuraId, Balance};
use node_primitives::{AccountId, Balance};
use node_runtime::{
GrandpaConfig, BalancesConfig, ContractsConfig, ElectionsConfig, DemocracyConfig,
CouncilConfig, AuraConfig, ImOnlineConfig, IndicesConfig, SessionConfig, StakingConfig,
SudoConfig, TechnicalCommitteeConfig, SystemConfig, WASM_BINARY, Perbill, SessionKeys,
StakerStatus, DAYS, DOLLARS, MILLICENTS,
BabeConfig, BalancesConfig, ContractsConfig, CouncilConfig, DemocracyConfig,
ElectionsConfig, GrandpaConfig, ImOnlineConfig, IndicesConfig, Perbill,
SessionConfig, SessionKeys, StakerStatus, StakingConfig, SudoConfig, SystemConfig,
TechnicalCommitteeConfig, DAYS, DOLLARS, MILLICENTS, WASM_BINARY,
};
pub use node_runtime::GenesisConfig;
use substrate_service;
@@ -40,8 +41,11 @@ pub fn flaming_fir_config() -> Result<ChainSpec, String> {
ChainSpec::from_embedded(include_bytes!("../res/flaming-fir.json"))
}
fn session_keys(key: ed25519::Public) -> SessionKeys {
SessionKeys { ed25519: key }
fn session_keys(ed_key: ed25519::Public, sr_key: sr25519::Public) -> SessionKeys {
SessionKeys {
ed25519: ed_key,
sr25519: sr_key,
}
}
fn staging_testnet_config_genesis() -> GenesisConfig {
@@ -51,7 +55,7 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
// and
// for i in 1 2 3 4 ; do for j in session; do subkey --ed25519 inspect "$secret"//fir//$j//$i; done; done
let initial_authorities: Vec<(AccountId, AccountId, AuraId, GrandpaId)> = vec![(
let initial_authorities: Vec<(AccountId, AccountId, BabeId, GrandpaId)> = vec![(
// 5Fbsd6WXDGiLTxunqeK5BATNiocfCqu9bS1yArVjCgeBLkVy
hex!["9c7a2ee14e565db0c69f78c7b4cd839fbf52b607d867e9e9c5a79042898a0d12"].unchecked_into(),
// 5EnCiV7wSHeNhjW3FSUwiJNkcc2SBkPLn5Nj93FmbLtBjQUq
@@ -116,7 +120,9 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
.collect::<Vec<_>>(),
}),
session: Some(SessionConfig {
keys: initial_authorities.iter().map(|x| (x.0.clone(), session_keys(x.2.clone()))).collect::<Vec<_>>(),
keys: initial_authorities.iter().map(|x| {
(x.0.clone(), session_keys(x.3.clone(), x.2.clone()))
}).collect::<Vec<_>>(),
}),
staking: Some(StakingConfig {
current_era: 0,
@@ -124,7 +130,9 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
validator_count: 7,
offline_slash_grace: 4,
minimum_validator_count: 4,
stakers: initial_authorities.iter().map(|x| (x.0.clone(), x.1.clone(), STASH, StakerStatus::Validator)).collect(),
stakers: initial_authorities.iter().map(|x| {
(x.0.clone(), x.1.clone(), STASH, StakerStatus::Validator)
}).collect(),
invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(),
}),
democracy: Some(DemocracyConfig::default()),
@@ -149,8 +157,8 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
sudo: Some(SudoConfig {
key: endowed_accounts[0].clone(),
}),
aura: Some(AuraConfig {
authorities: initial_authorities.iter().map(|x| x.2.clone()).collect(),
babe: Some(BabeConfig {
authorities: initial_authorities.iter().map(|x| (x.2.clone(), 1)).collect(),
}),
im_online: Some(ImOnlineConfig {
gossip_at: 0,
@@ -184,9 +192,9 @@ pub fn get_account_id_from_seed(seed: &str) -> AccountId {
.public()
}
/// Helper function to generate AuraId from seed
pub fn get_aura_id_from_seed(seed: &str) -> AuraId {
ed25519::Pair::from_string(&format!("//{}", seed), None)
/// Helper function to generate BabeId from seed
pub fn get_babe_id_from_seed(seed: &str) -> BabeId {
sr25519::Pair::from_string(&format!("//{}", seed), None)
.expect("static values are valid; qed")
.public()
}
@@ -199,18 +207,18 @@ pub fn get_grandpa_id_from_seed(seed: &str) -> GrandpaId {
}
/// Helper function to generate stash, controller and session key from seed
pub fn get_authority_keys_from_seed(seed: &str) -> (AccountId, AccountId, AuraId, GrandpaId) {
pub fn get_authority_keys_from_seed(seed: &str) -> (AccountId, AccountId, BabeId, GrandpaId) {
(
get_account_id_from_seed(&format!("{}//stash", seed)),
get_account_id_from_seed(seed),
get_aura_id_from_seed(seed),
get_babe_id_from_seed(seed),
get_grandpa_id_from_seed(seed)
)
}
/// Helper function to create GenesisConfig for testing
pub fn testnet_genesis(
initial_authorities: Vec<(AccountId, AccountId, AuraId, GrandpaId)>,
initial_authorities: Vec<(AccountId, AccountId, BabeId, GrandpaId)>,
root_key: AccountId,
endowed_accounts: Option<Vec<AccountId>>,
enable_println: bool,
@@ -250,7 +258,9 @@ pub fn testnet_genesis(
vesting: vec![],
}),
session: Some(SessionConfig {
keys: initial_authorities.iter().map(|x| (x.0.clone(), session_keys(x.2.clone()))).collect::<Vec<_>>(),
keys: initial_authorities.iter().map(|x| {
(x.0.clone(), session_keys(x.3.clone(), x.2.clone()))
}).collect::<Vec<_>>(),
}),
staking: Some(StakingConfig {
current_era: 0,
@@ -258,7 +268,9 @@ pub fn testnet_genesis(
validator_count: 2,
offline_slash: Perbill::zero(),
offline_slash_grace: 0,
stakers: initial_authorities.iter().map(|x| (x.0.clone(), x.1.clone(), STASH, StakerStatus::Validator)).collect(),
stakers: initial_authorities.iter().map(|x| {
(x.0.clone(), x.1.clone(), STASH, StakerStatus::Validator)
}).collect(),
invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(),
}),
democracy: Some(DemocracyConfig::default()),
@@ -288,8 +300,8 @@ pub fn testnet_genesis(
sudo: Some(SudoConfig {
key: root_key,
}),
aura: Some(AuraConfig {
authorities: initial_authorities.iter().map(|x| x.2.clone()).collect(),
babe: Some(BabeConfig {
authorities: initial_authorities.iter().map(|x| (x.2.clone(), 1)).collect(),
}),
im_online: Some(ImOnlineConfig{
gossip_at: 0,