Dispatch on-disabled digests from consensus modules (#3055)

* on-disable primitives for engines

* dispatch on-disabled digests from SRML consensus

* bump runtime versions

* use find_map
This commit is contained in:
Robert Habermeier
2019-07-08 16:22:15 +02:00
committed by Gavin Wood
parent 3d72844710
commit 13b9e49688
11 changed files with 140 additions and 72 deletions
@@ -26,11 +26,18 @@ use runtime_primitives::ConsensusEngineId;
/// The `ConsensusEngineId` of AuRa.
pub const AURA_ENGINE_ID: ConsensusEngineId = [b'a', b'u', b'r', b'a'];
/// The index of an authority.
pub type AuthorityIndex = u64;
/// An consensus log item for Aura.
#[derive(Decode, Encode)]
pub enum ConsensusLog<AuthorityId: Codec> {
/// The authorities have changed.
#[codec(index = "1")]
AuthoritiesChange(Vec<AuthorityId>),
/// Disable the authority with given index.
#[codec(index = "2")]
OnDisabled(AuthorityIndex),
}
decl_runtime_apis! {
+10 -5
View File
@@ -564,14 +564,19 @@ impl<B: Block, C, P> Verifier<B> for AuraVerifier<C, P> where
trace!(target: "aura", "Checked {:?}; importing.", pre_header);
telemetry!(CONSENSUS_TRACE; "aura.checked_and_importing"; "pre_header" => ?pre_header);
// `Consensus` is the Aura-specific authorities change log.
// Look for an authorities-change log.
let maybe_keys = pre_header.digest()
.convert_first(|l| l.try_to::<ConsensusLog<AuthorityId<P>>>(
.logs()
.iter()
.filter_map(|l| l.try_to::<ConsensusLog<AuthorityId<P>>>(
OpaqueDigestItemId::Consensus(&AURA_ENGINE_ID)
))
.map(|ConsensusLog::AuthoritiesChange(a)|
vec![(well_known_cache_keys::AUTHORITIES, a.encode())]
);
.find_map(|l| match l {
ConsensusLog::AuthoritiesChange(a) => Some(
vec![(well_known_cache_keys::AUTHORITIES, a.encode())]
),
_ => None,
});
let import_block = ImportBlock {
origin,
@@ -40,6 +40,29 @@ pub const VRF_PROOF_LENGTH: usize = 64;
/// The length of the public key
pub const PUBLIC_KEY_LENGTH: usize = 32;
/// The index of an authority.
pub type AuthorityIndex = u64;
/// A slot number.
pub type SlotNumber = u64;
/// The weight of an authority.
pub type Weight = u64;
/// An consensus log item for BABE.
#[derive(Decode, Encode)]
pub enum ConsensusLog {
/// The epoch has changed. This provides information about the
/// epoch _after_ next: what slot number it will start at, who are the authorities (and their weights)
/// and the next epoch randomness. The information for the _next_ epoch should already
/// be available.
#[codec(index = "1")]
NextEpochData(SlotNumber, Vec<(AuthorityId, Weight)>, [u8; VRF_OUTPUT_LENGTH]),
/// Disable the authority with given index.
#[codec(index = "2")]
OnDisabled(AuthorityIndex),
}
/// Configuration data used by the BABE consensus engine.
#[derive(Copy, Clone, Hash, PartialEq, Eq, Debug, Encode, Decode)]
pub struct BabeConfiguration {
+3 -3
View File
@@ -17,7 +17,7 @@
//! Private implementation details of BABE digests.
use primitives::sr25519::Signature;
use babe_primitives::{self, BABE_ENGINE_ID};
use babe_primitives::{self, BABE_ENGINE_ID, SlotNumber};
use runtime_primitives::{DigestItem, generic::OpaqueDigestItemId};
use std::fmt::Debug;
use parity_codec::{Decode, Encode, Codec, Input};
@@ -33,8 +33,8 @@ use schnorrkel::{vrf::{VRFProof, VRFOutput, VRF_OUTPUT_LENGTH, VRF_PROOF_LENGTH}
pub struct BabePreDigest {
pub(super) vrf_output: VRFOutput,
pub(super) proof: VRFProof,
pub(super) index: u64,
pub(super) slot_num: u64,
pub(super) index: babe_primitives::AuthorityIndex,
pub(super) slot_num: SlotNumber,
}
/// The prefix used by BABE for its VRF keys.