Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
d95c733
begin accounting for next epoch in epoch function
rphmeier Sep 11, 2019
aa429f5
slots passes header to epoch_data
rphmeier Sep 11, 2019
73d9221
pass slot_number to SlotWorker::epoch_data
rphmeier Sep 12, 2019
4269d9d
begin extracting epoch-change logic into its own module
rphmeier Sep 16, 2019
4289869
aux methods for block weight
rphmeier Sep 16, 2019
abf57ca
aux methods for genesis configuration
rphmeier Sep 16, 2019
2173879
comment-out most, refactor header-check pipeline
rphmeier Sep 16, 2019
5c321ef
mostly flesh out verifier again
rphmeier Sep 16, 2019
81aaab7
reinstantiate babe BlockImport implementation
rphmeier Sep 16, 2019
f22846a
reinstate import-queue instantiation
rphmeier Sep 16, 2019
bb0ef7b
reintroduce slot-worker implementation
rphmeier Sep 16, 2019
4b74154
reinstate pretty much all the rest
rphmeier Sep 16, 2019
b6dba9a
move fork-choice logic to BlockImport
rphmeier Sep 16, 2019
35e3c89
fix some, but not all errors
rphmeier Sep 16, 2019
e7d7545
patch test-runtime
rphmeier Sep 16, 2019
9f1cbe7
make is_descendent of slightly more generic
rphmeier Sep 16, 2019
c6c46a5
get skeleton compiling when passing is_descendent_of
rphmeier Sep 16, 2019
ad87669
make descendent-of-builder more succinct
rphmeier Sep 16, 2019
0d8d5b2
restore ordering of authority_index / slot_number
rphmeier Sep 16, 2019
1a4f223
start fiddling with tests
rphmeier Sep 16, 2019
3a655d8
fix warnings
rphmeier Sep 17, 2019
144fb6f
improve initialization architecture and handle genesis
rphmeier Sep 17, 2019
1cfbde0
tests use correct block-import
rphmeier Sep 17, 2019
9454ea1
fix BABE tests
rphmeier Sep 17, 2019
6d8a151
fix some compiler errors
rphmeier Sep 17, 2019
975afdd
fix node-cli compilation
rphmeier Sep 18, 2019
582f558
all crates compile
rphmeier Sep 18, 2019
b147ebe
bump runtime versions and fix some warnings
rphmeier Sep 18, 2019
d8ffc2d
tweak fork-tree search implementation
rphmeier Sep 18, 2019
aa37321
do backtracking search in fork-tree
rphmeier Sep 18, 2019
20ec772
node-cli integration tests now work
rphmeier Sep 18, 2019
825a75d
First BABE SRML test
Demi-Marie Aug 5, 2019
48ec1d9
Testing infrastructure for BABE
Demi-Marie Aug 6, 2019
f7e04b4
Apply suggestions from code review
Demi-Marie Aug 6, 2019
1199d26
A little more test progress
Demi-Marie Aug 7, 2019
63f5674
More work on BABE testing
Demi-Marie Aug 9, 2019
27a7bc5
Try to get the tests working
Demi-Marie Aug 9, 2019
1b6d295
Implement `UintAuthorityId`-based test mocks
Demi-Marie Aug 9, 2019
6d514a8
Fix compilation errors
Demi-Marie Aug 16, 2019
6b039b8
Adjust to upstream changes
Demi-Marie Aug 18, 2019
387297f
Block numbers are ignored in BABE epoch calculation
Demi-Marie Aug 19, 2019
ff8e266
authority_index() should ignore invalid authorities
Demi-Marie Aug 19, 2019
d84387e
Fix compile error
Demi-Marie Aug 26, 2019
d7a4e38
Add tests that session transitions happen
Demi-Marie Aug 26, 2019
a385da5
Check if BABE produces logs
Demi-Marie Aug 28, 2019
a510e45
Fix test suite
Demi-Marie Aug 28, 2019
bbf4be3
Add additional tests
Demi-Marie Aug 29, 2019
0867ab6
Make the tests more readable
Demi-Marie Aug 30, 2019
e4fd5b3
Fix excessive line width
Demi-Marie Aug 30, 2019
4e7ad94
Remove unused imports
Demi-Marie Sep 3, 2019
fe1b3a1
Update srml/babe/src/lib.rs
Demi-Marie Sep 3, 2019
692996e
try to fix imports
Demi-Marie Sep 12, 2019
7de2cae
Fix build errors in test suite
Demi-Marie Sep 12, 2019
97295d5
tests did not pass
Demi-Marie Sep 13, 2019
1b41c98
Try to get at least one digest to be output
Demi-Marie Sep 17, 2019
203d0fb
More tests
Demi-Marie Sep 18, 2019
e488ca4
fix silly error
Demi-Marie Sep 18, 2019
3e3d524
Don’t even try to compile a broken test
Demi-Marie Sep 18, 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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 19 additions & 7 deletions core/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1482,6 +1482,9 @@ impl<B, E, Block, RA> CallRuntimeAt<Block> for Client<B, E, Block, RA> where
}
}

/// NOTE: only use this implementation when you are sure there are NO consensus-level BlockImport
/// objects. Otherwise, importing blocks directly into the client would be bypassing
/// important verification work.
impl<'a, B, E, Block, RA> consensus::BlockImport<Block> for &'a Client<B, E, Block, RA> where
B: backend::Backend<Block, Blake2Hasher>,
E: CallExecutor<Block, Blake2Hasher> + Clone + Send + Sync,
Expand All @@ -1491,6 +1494,13 @@ impl<'a, B, E, Block, RA> consensus::BlockImport<Block> for &'a Client<B, E, Blo

/// Import a checked and validated block. If a justification is provided in
/// `BlockImportParams` then `finalized` *must* be true.
///
/// NOTE: only use this implementation when there are NO consensus-level BlockImport
/// objects. Otherwise, importing blocks directly into the client would be bypassing
/// important verification work.
///
/// If you are not sure that there are no BlockImport objects provided by the consensus
/// algorithm, don't use this function.
fn import_block(
&mut self,
import_block: BlockImportParams<Block>,
Expand Down Expand Up @@ -1899,25 +1909,27 @@ where
/// Utility methods for the client.
pub mod utils {
use super::*;
use crate::{backend::Backend, blockchain, error};
use crate::{blockchain, error};
use primitives::H256;
use std::borrow::Borrow;

/// Returns a function for checking block ancestry, the returned function will
/// return `true` if the given hash (second parameter) is a descendent of the
/// base (first parameter). If the `current` parameter is defined, it should
/// represent the current block `hash` and its `parent hash`, if given the
/// function that's returned will assume that `hash` isn't part of the local DB
/// yet, and all searches in the DB will instead reference the parent.
pub fn is_descendent_of<'a, B, E, Block: BlockT<Hash=H256>, RA>(
client: &'a Client<B, E, Block, RA>,
current: Option<(&'a H256, &'a H256)>,
pub fn is_descendent_of<'a, Block: BlockT<Hash=H256>, T, H: Borrow<H256> + 'a>(
client: &'a T,
current: Option<(H, H)>,
) -> impl Fn(&H256, &H256) -> Result<bool, error::Error> + 'a
where B: Backend<Block, Blake2Hasher>,
E: CallExecutor<Block, Blake2Hasher> + Send + Sync,
where T: ChainHeaderBackend<Block>,
{
move |base, hash| {
if base == hash { return Ok(false); }

let current = current.as_ref().map(|(c, p)| (c.borrow(), p.borrow()));

let mut hash = hash;
if let Some((current_hash, current_parent_hash)) = current {
if base == current_hash { return Ok(false); }
Expand All @@ -1931,7 +1943,7 @@ pub mod utils {
}

let tree_route = blockchain::tree_route(
|id| client.header(&id)?.ok_or_else(|| Error::UnknownBlock(format!("{:?}", id))),
|id| client.header(id)?.ok_or_else(|| Error::UnknownBlock(format!("{:?}", id))),
BlockId::Hash(*hash),
BlockId::Hash(*base),
)?;
Expand Down
6 changes: 3 additions & 3 deletions core/consensus/aura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ impl<H, B, C, E, I, P, Error, SO> slots::SimpleSlotWorker<B> for AuraWorker<C, E
self.block_import.clone()
}

fn epoch_data(&self, block: &B::Hash) -> Result<Self::EpochData, consensus_common::Error> {
authorities(self.client.as_ref(), &BlockId::Hash(*block))
fn epoch_data(&self, header: &B::Header, _slot_number: u64) -> Result<Self::EpochData, consensus_common::Error> {
authorities(self.client.as_ref(), &BlockId::Hash(header.hash()))
}

fn authorities_len(&self, epoch_data: &Self::EpochData) -> usize {
Expand Down Expand Up @@ -740,7 +740,7 @@ mod tests {
}
}

fn make_verifier(&self, client: PeersClient, _cfg: &ProtocolConfig)
fn make_verifier(&self, client: PeersClient, _cfg: &ProtocolConfig, _peer_data: &())
-> Self::Verifier
{
match client {
Expand Down
14 changes: 14 additions & 0 deletions core/consensus/babe/primitives/src/digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ impl BabePreDigest {
BabePreDigest::Secondary { slot_number, .. } => *slot_number,
}
}

/// Returns the weight _added_ by this digest, not the cumulative weight
/// of the chain.
pub fn added_weight(&self) -> crate::BabeBlockWeight {
match self {
BabePreDigest::Primary { .. } => 1,
BabePreDigest::Secondary { .. } => 0,
}
}
}

/// The prefix used by BABE for its VRF keys.
Expand All @@ -103,6 +112,11 @@ pub enum RawBabePreDigest {
#[codec(index = "2")]
Secondary {
/// Authority index
///
/// This is not strictly-speaking necessary, since the secondary slots
/// are assigned based on slot number and epoch randomness. But including
/// it makes things easier for higher-level users of the chain data to
/// be aware of the author of a secondary-slot block.
authority_index: AuthorityIndex,
/// Slot number
slot_number: SlotNumber,
Expand Down
19 changes: 16 additions & 3 deletions core/consensus/babe/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub struct Epoch {
/// The epoch index
pub epoch_index: u64,
/// The starting slot of the epoch,
pub start_slot: u64,
pub start_slot: SlotNumber,
/// The duration of this epoch
pub duration: SlotNumber,
/// The authorities and their weights
Expand All @@ -94,6 +94,19 @@ pub struct Epoch {
pub randomness: [u8; VRF_OUTPUT_LENGTH],
}

impl Epoch {
/// "increment" the epoch, with given descriptor for the next.
pub fn increment(&self, descriptor: NextEpochDescriptor) -> Epoch {
Epoch {
epoch_index: self.epoch_index + 1,
start_slot: self.start_slot + self.duration,
duration: self.duration,
authorities: descriptor.authorities,
randomness: descriptor.randomness,
}
}
}

/// An consensus log item for BABE.
#[derive(Decode, Encode, Clone, PartialEq, Eq)]
pub enum ConsensusLog {
Expand Down Expand Up @@ -131,7 +144,7 @@ pub struct BabeConfiguration {
/// The authorities for the genesis epoch.
pub genesis_authorities: Vec<(AuthorityId, BabeAuthorityWeight)>,

/// The randomness for this epoch.
/// The randomness for the genesis epoch.
pub randomness: [u8; VRF_OUTPUT_LENGTH],

/// Whether this chain should run with secondary slots, which are assigned
Expand All @@ -145,7 +158,7 @@ impl slots::SlotData for BabeConfiguration {
self.slot_duration
}

const SLOT_KEY: &'static [u8] = b"babe_bootstrap_data";
const SLOT_KEY: &'static [u8] = b"babe_configuration";
}

decl_runtime_apis! {
Expand Down
30 changes: 30 additions & 0 deletions core/consensus/babe/src/aux_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ use codec::{Decode, Encode};
use client::backend::AuxStore;
use client::error::{Result as ClientResult, Error as ClientError};
use sr_primitives::traits::Block as BlockT;
use babe_primitives::BabeBlockWeight;

use super::{EpochChanges, SharedEpochChanges};

const BABE_EPOCH_CHANGES: &[u8] = b"babe_epoch_changes";

fn block_weight_key<H: Encode>(block_hash: H) -> Vec<u8> {
(b"block_weight", block_hash).encode()
}

fn load_decode<B, T>(backend: &B, key: &[u8]) -> ClientResult<Option<T>>
where
B: AuxStore,
Expand Down Expand Up @@ -69,3 +74,28 @@ pub(crate) fn write_epoch_changes<Block: BlockT, F, R>(
&[(BABE_EPOCH_CHANGES, encoded_epoch_changes.as_slice())],
)
}

/// Write the cumulative chain-weight of a block ot aux storage.
pub(crate) fn write_block_weight<H: Encode, F, R>(
block_hash: H,
block_weight: &BabeBlockWeight,
write_aux: F,
) -> R where
F: FnOnce(&[(Vec<u8>, &[u8])]) -> R,
{

let key = block_weight_key(block_hash);
block_weight.using_encoded(|s|
write_aux(
&[(key, s)],
)
)
}

/// Load the cumulative chain-weight associated with a block.
pub(crate) fn load_block_weight<H: Encode, B: AuxStore>(
backend: &B,
block_hash: H,
) -> ClientResult<Option<BabeBlockWeight>> {
load_decode(backend, block_weight_key(block_hash).as_slice())
}
Loading