Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e70f3bd
babe: initial implementation of secondary slots
andresilva Aug 13, 2019
65370d2
babe: validate secondary slot author
andresilva Aug 13, 2019
086b01d
babe: implement weight based fork choice
andresilva Aug 13, 2019
86468f3
babe: remove unused
andresilva Aug 13, 2019
46005e9
aura: cleanup unused imports
andresilva Aug 13, 2019
1fb767f
babe: pass in parent weight when authoring and verifying
andresilva Aug 13, 2019
36d7896
babe: use epoch randomness for picking secondary slot authors
andresilva Aug 13, 2019
e277fcf
babe: fix tests
andresilva Aug 13, 2019
1643b71
babe: fix wasm build
andresilva Aug 13, 2019
0da1733
babe: node-side code for disabling secondary slots
andresilva Aug 13, 2019
730c328
babe: allow enabling/disabling secondary slots from runtime
andresilva Aug 13, 2019
3568ce8
babe: fix test
andresilva Aug 13, 2019
763c617
babe: use blake2_256 for secondary slot assignment
andresilva Aug 13, 2019
8c0ff02
babe: run block initialization in should_end_session
andresilva Aug 13, 2019
3b38b14
node: increase slot duration to 6s
andresilva Aug 13, 2019
ca6b9a0
babe: add docs
andresilva Aug 15, 2019
b5b2d6e
node: bump spec_version
andresilva Aug 15, 2019
fed3e6f
Apply suggestions from code review
andresilva Aug 15, 2019
f28273c
babe: simplify secondary slot assignment calculation
andresilva Aug 15, 2019
382aefa
Merge branch 'master' into andre/aurababeous
andresilva Aug 16, 2019
cca85f9
babe: remove unnecessary comment
andresilva Aug 16, 2019
8a95966
node: bump spec_version
andresilva Aug 16, 2019
11fe7a6
Merge branch 'master' into andre/aurababeous
andresilva Aug 16, 2019
4f75dd8
babe: fix bad merge
andresilva Aug 16, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
babe: fix tests
  • Loading branch information
andresilva committed Aug 15, 2019
commit e277fcf4ae63a95c27619ea652e703d49e9e797b
19 changes: 8 additions & 11 deletions core/consensus/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1426,30 +1426,27 @@ pub mod test_helpers {
/// Try to claim the given slot and return a `BabePreDigest` if
/// successful.
pub fn claim_slot<B, C>(
client: &C,
at: &BlockId<B>,
slot_number: u64,
parent: &B::Header,
client: &C,
c: (u64, u64),
keystore: &KeyStorePtr,
) -> Option<BabePreDigest> where
B: BlockT,
C: ProvideRuntimeApi + ProvideCache<B>,
C::Api: BabeApi<B>,
{
let epoch = epoch(client, at).unwrap();
let epoch = epoch(client, &BlockId::Hash(parent.hash())).unwrap();

let weight = find_pre_digest::<B>(parent).ok()
.map(|d| d.weight())?;

super::claim_slot(
slot_number,
weight,
&epoch,
c,
keystore,
).map(|((inout, vrf_proof, _), authority_index, _)| {
BabePreDigest {
vrf_proof,
vrf_output: inout.to_output(),
authority_index: authority_index as u32,
slot_number,
}
})
).map(|(digest, _)| digest)
}
}
27 changes: 19 additions & 8 deletions core/consensus/babe/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@
// https://github.com/paritytech/substrate/issues/2532
#![allow(deprecated)]
use super::*;
use super::generic::DigestItem;

use babe_primitives::AuthorityPair;
use client::{LongestChain, block_builder::BlockBuilder};
use consensus_common::NoNetwork as DummyOracle;
use network::test::*;
use network::test::{Block as TestBlock, PeersClient};
use sr_primitives::traits::{Block as BlockT, DigestFor};
use sr_primitives::{generic::DigestItem, traits::{Block as BlockT, DigestFor}};
use network::config::ProtocolConfig;
use tokio::runtime::current_thread;
use keyring::sr25519::Keyring;
use client::BlockchainEvents;
use test_client;
use log::debug;
use std::{time::Duration, borrow::Borrow, cell::RefCell};
type Item = generic::DigestItem<Hash>;

type Item = DigestItem<Hash>;

type Error = client::error::Error;

Expand Down Expand Up @@ -88,7 +88,14 @@ type TestHeader = <TestBlock as BlockT>::Header;
type TestExtrinsic = <TestBlock as BlockT>::Extrinsic;

pub struct TestVerifier {
inner: BabeVerifier<PeersFullClient, ()>,
inner: BabeVerifier<
test_client::Backend,
test_client::Executor,
TestBlock,
test_client::runtime::RuntimeApi,
PeersFullClient,
()
>,
mutator: Mutator,
}

Expand Down Expand Up @@ -126,9 +133,9 @@ impl TestNetFactory for BabeTestNet {
fn make_verifier(&self, client: PeersClient, _cfg: &ProtocolConfig)
-> Self::Verifier
{
let api = client.as_full().expect("only full clients are used in test");
let client = client.as_full().expect("only full clients are used in test");
trace!(target: "babe", "Creating a verifier");
let config = Config::get_or_compute(&*api)
let config = Config::get_or_compute(&*client)
.expect("slot duration available");
let inherent_data_providers = InherentDataProviders::new();
register_babe_inherent_data_provider(
Expand All @@ -139,7 +146,8 @@ impl TestNetFactory for BabeTestNet {

TestVerifier {
inner: BabeVerifier {
api,
client: client.clone(),
api: client,
inherent_data_providers,
config,
time_source: Default::default(),
Expand Down Expand Up @@ -324,8 +332,11 @@ fn can_author_block() {
epoch_index: 1,
duration: 100,
};

let parent_weight = 0;

loop {
match claim_slot(i, &epoch.clone(), (3, 10), &keystore) {
match claim_slot(i, parent_weight, &epoch.clone(), (3, 10), &keystore) {
None => i += 1,
Some(s) => {
debug!(target: "babe", "Authored block {:?}", s.0);
Expand Down
4 changes: 2 additions & 2 deletions node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,9 @@ mod tests {
let babe_pre_digest = loop {
inherent_data.replace_data(timestamp::INHERENT_IDENTIFIER, &(slot_num * SLOT_DURATION));
if let Some(babe_pre_digest) = babe::test_helpers::claim_slot(
&*service.client(),
&parent_id,
slot_num,
&parent_header,
&*service.client(),
(278, 1000),
&keystore,
) {
Expand Down