mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 23:51:05 +00:00
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:
committed by
Gavin Wood
parent
3d72844710
commit
13b9e49688
@@ -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! {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -23,7 +23,7 @@ extern crate alloc;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use serde::Serialize;
|
||||
use parity_codec::{Encode, Decode};
|
||||
use parity_codec::{Encode, Decode, Codec};
|
||||
use sr_primitives::{ConsensusEngineId, traits::{DigestFor, NumberFor}};
|
||||
use client::decl_runtime_apis;
|
||||
use rstd::vec::Vec;
|
||||
@@ -44,16 +44,75 @@ pub const GRANDPA_ENGINE_ID: ConsensusEngineId = *b"FRNK";
|
||||
/// The weight of an authority.
|
||||
pub type AuthorityWeight = u64;
|
||||
|
||||
/// The index of an authority.
|
||||
pub type AuthorityIndex = u64;
|
||||
|
||||
/// A scheduled change of authority set.
|
||||
#[cfg_attr(feature = "std", derive(Debug, Serialize))]
|
||||
#[derive(Clone, Eq, PartialEq, Encode, Decode)]
|
||||
pub struct ScheduledChange<N> {
|
||||
/// The new authorities after the change, along with their respective weights.
|
||||
pub next_authorities: Vec<(AuthorityId, u64)>,
|
||||
pub next_authorities: Vec<(AuthorityId, AuthorityWeight)>,
|
||||
/// The number of blocks to delay.
|
||||
pub delay: N,
|
||||
}
|
||||
|
||||
/// An consensus log item for GRANDPA.
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Debug))]
|
||||
#[derive(Decode, Encode, PartialEq, Eq, Clone)]
|
||||
pub enum ConsensusLog<N: Codec> {
|
||||
/// Schedule an authority set change.
|
||||
///
|
||||
/// Precedence towards earlier or later digest items can be given
|
||||
/// based on the rules of the chain.
|
||||
///
|
||||
/// No change should be scheduled if one is already and the delay has not
|
||||
/// passed completely.
|
||||
///
|
||||
/// This should be a pure function: i.e. as long as the runtime can interpret
|
||||
/// the digest type it should return the same result regardless of the current
|
||||
/// state.
|
||||
#[codec(index = "1")]
|
||||
ScheduledChange(ScheduledChange<N>),
|
||||
/// Force an authority set change.
|
||||
///
|
||||
/// Forced changes are applied after a delay of _imported_ blocks,
|
||||
/// while pending changes are applied after a delay of _finalized_ blocks.
|
||||
///
|
||||
/// Precedence towards earlier or later digest items can be given
|
||||
/// based on the rules of the chain.
|
||||
///
|
||||
/// No change should be scheduled if one is already and the delay has not
|
||||
/// passed completely.
|
||||
///
|
||||
/// This should be a pure function: i.e. as long as the runtime can interpret
|
||||
/// the digest type it should return the same result regardless of the current
|
||||
/// state.
|
||||
#[codec(index = "2")]
|
||||
ForcedChange(N, ScheduledChange<N>),
|
||||
/// Note that the authority with given index is disabled until the next change.
|
||||
#[codec(index = "3")]
|
||||
OnDisabled(AuthorityIndex),
|
||||
}
|
||||
|
||||
impl<N: Codec> ConsensusLog<N> {
|
||||
/// Try to cast the log entry as a contained signal.
|
||||
pub fn try_into_change(self) -> Option<ScheduledChange<N>> {
|
||||
match self {
|
||||
ConsensusLog::ScheduledChange(change) => Some(change),
|
||||
ConsensusLog::ForcedChange(_, _) | ConsensusLog::OnDisabled(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Try to cast the log entry as a contained forced signal.
|
||||
pub fn try_into_forced_change(self) -> Option<(N, ScheduledChange<N>)> {
|
||||
match self {
|
||||
ConsensusLog::ForcedChange(median, change) => Some((median, change)),
|
||||
ConsensusLog::ScheduledChange(_) | ConsensusLog::OnDisabled(_) => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// WASM function call to check for pending changes.
|
||||
pub const PENDING_CHANGE_CALL: &str = "grandpa_pending_change";
|
||||
/// WASM function call to get current GRANDPA authorities.
|
||||
|
||||
Reference in New Issue
Block a user