mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-17 18:21:02 +00:00
c7a14db792
* meaningfull -> meaningful * initialise -> initialize * tokans -> tokens * incentivise -> incentivize * lenght -> length * incentivisation -> incentivization * doesnt't -> doesn't * overwriten -> overwritten * lifecycle -> life cycle * lifecycle -> life cycle * usefull -> useful * noone -> no one * spaming -> spamming * defered -> deferred * hieght -> height * sumation -> summation * ingore -> ignore * registed -> registered * Auxialary -> Auxiliary * loggin -> logging * independance -> independence * trailling -> trailing * responsability -> responsibility * trunkated -> truncated * Weither -> Whether * informations -> information * Runtume -> Runtime * choosen -> chosen * delcataion -> declaration * Unchekced -> Unchecked * defintion -> definition * scrach -> scratch * imput -> input * transfered -> transferred * endownment -> endowment * Determinator -> Determiner * relevent -> relevant * emited -> emitted * acocunt -> account * proprotional -> proportional * instantiaion -> instantiation * commited -> committed * tombstonedead -> tombstone * uwnrap -> unwrap * acount -> account * specialised -> specialized * existant -> existent * requried -> required * Anull -> Annul * AUTHORITES -> AUTHORITIES * underyling -> underlying * recognisable -> recognizable * Capitalise -> Capitalize * reportfor -> report for * hearbeat -> heartbeat * onlineness -> being online * creater -> creator * Bytearray -> Byte array * Despoit -> Deposit * substratced -> subtracted * Curent -> Current * imbalanes -> imbalances * countfown -> countdown * inexisting -> inexistent * additionaly -> additionally * substracted -> subtracted * auxilary -> auxiliary * parital -> partial * in't -> isn't * compatability -> compatibility * infomation -> information * etected -> detected * extrinsiscs -> extrinsics * reprensentation -> representation * coonfiguration -> configuration * primtives -> primitives * miscelanious -> miscellaneous * VERISON -> VERSION * endcoded -> encoded * Genrates -> Generates * miliseconds -> milliseconds * occured -> occurred * trully -> truely * truely -> truly * conjuction -> conjunction * encouters -> encounters * customised -> customized * deterministicly -> deterministically * finalisation -> finalization * pluggable -> plugable * wakeup -> wake-up * interemdiate -> intermediate * intepreting -> interpreting * finalzied -> finalized * throgh -> through * extinsic -> extrinsic * convient -> convenient * allocater -> allocator * propagateable -> propagatable * succesfuly -> successfully * finalising -> finalizing * publically -> publicly * phrasee -> phrase * substration -> substractions * substractions -> subtractions * neccessarily -> necessarily * Inlucde -> Include * unefficient -> inefficient * thay -> they * funtion -> function * datastructures -> data structures * infromation -> information * propagatable -> propagable * ecountered -> encountered * recognise -> recognize * intergration -> integration * lastet -> latest * datatypes -> data types * datatype -> data type * Strongarming -> Strong Arming * avaible -> available * Commiting -> Committing * Retreiving -> Retrieving * shoud -> should * canonicaliziation -> canonicalization * comitted -> committed * clonable -> cloneable * Uknown -> Unknown * reponse -> response * arbitary -> arbitrary * Capapbilities -> Capabilities * responsbile -> responsible * initialisation -> initialization * cames -> came * intemediate -> intermediate * reqeust -> request * intance -> instance * explcitly -> explicitly * neighor -> neighbor * reolving -> resolving * untill -> until * Validte -> Validate * deserailize -> deserialize * literaly -> literally * preceeding -> preceding * abpve -> above * chcecked -> checked * numbet -> number * Unknow -> Unknown * halfs -> halves * gossup -> gossip * givent -> given * immediatelly -> immediately * slicable -> sliceable * conensus -> consensus * Mimicks -> Mimics * acccept -> accept * serialise -> serialize * exstrinsics -> extrinsics * panicks -> panics * maintaince -> maintenance * repeatidely -> repeatedly * anecstor -> ancestor * becasue -> because * processer -> processor * Prunning -> Pruning * insterested -> interested * unuseful -> not useful * yeided -> yielded * descendfing -> descending * corresponts -> corresponds * survivew -> survive * keps -> keeps * ligh -> light * prerequisities -> prerequisites * positiion -> position * depedency -> dependency * extrinisic -> extrinsic * atomicaly -> atomically * staticly -> statically * resul -> result * timestamb -> timestamp * Utilites -> Utilities * ammount -> amount * pocess -> process * exteral -> external * Update client/finality-grandpa/src/tests.rs * Update primitives/io/src/lib.rs Co-Authored-By: joe petrowski <25483142+joepetrowski@users.noreply.github.com> * Update primitives/blockchain/src/lib.rs Co-Authored-By: joe petrowski <25483142+joepetrowski@users.noreply.github.com> * Update frame/support/src/weights.rs Co-Authored-By: joe petrowski <25483142+joepetrowski@users.noreply.github.com> * Update bin/node/cli/tests/common.rs Co-Authored-By: joe petrowski <25483142+joepetrowski@users.noreply.github.com> * Update client/api/src/execution_extensions.rs Co-Authored-By: joe petrowski <25483142+joepetrowski@users.noreply.github.com> * Update client/cli/src/params.rs Co-Authored-By: joe petrowski <25483142+joepetrowski@users.noreply.github.com> * Update client/executor/common/src/sandbox.rs Co-Authored-By: joe petrowski <25483142+joepetrowski@users.noreply.github.com> * Update client/api/src/execution_extensions.rs Co-Authored-By: joe petrowski <25483142+joepetrowski@users.noreply.github.com> * Update client/finality-grandpa/src/communication/mod.rs Co-Authored-By: joe petrowski <25483142+joepetrowski@users.noreply.github.com> * Update client/state-db/src/pruning.rs Co-Authored-By: joe petrowski <25483142+joepetrowski@users.noreply.github.com> * Update frame/contracts/src/tests.rs Co-Authored-By: joe petrowski <25483142+joepetrowski@users.noreply.github.com> * Update client/api/src/execution_extensions.rs * bump impl * timestamb -> timestamp Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>
235 lines
8.0 KiB
Rust
235 lines
8.0 KiB
Rust
// Copyright 2018-2020 Parity Technologies (UK) Ltd.
|
|
// This file is part of Substrate.
|
|
|
|
// Substrate is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// Substrate is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//! Primitives for GRANDPA integration, suitable for WASM compilation.
|
|
|
|
#![cfg_attr(not(feature = "std"), no_std)]
|
|
|
|
#[cfg(not(feature = "std"))]
|
|
extern crate alloc;
|
|
|
|
#[cfg(feature = "std")]
|
|
use serde::Serialize;
|
|
use codec::{Encode, Decode, Input, Codec};
|
|
use sp_runtime::{ConsensusEngineId, RuntimeDebug};
|
|
use sp_std::borrow::Cow;
|
|
use sp_std::vec::Vec;
|
|
|
|
mod app {
|
|
use sp_application_crypto::{app_crypto, key_types::GRANDPA, ed25519};
|
|
app_crypto!(ed25519, GRANDPA);
|
|
}
|
|
|
|
sp_application_crypto::with_pair! {
|
|
/// The grandpa crypto scheme defined via the keypair type.
|
|
pub type AuthorityPair = app::Pair;
|
|
}
|
|
|
|
/// Identity of a Grandpa authority.
|
|
pub type AuthorityId = app::Public;
|
|
|
|
/// Signature for a Grandpa authority.
|
|
pub type AuthoritySignature = app::Signature;
|
|
|
|
/// The `ConsensusEngineId` of GRANDPA.
|
|
pub const GRANDPA_ENGINE_ID: ConsensusEngineId = *b"FRNK";
|
|
|
|
/// The storage key for the current set of weighted Grandpa authorities.
|
|
/// The value stored is an encoded VersionedAuthorityList.
|
|
pub const GRANDPA_AUTHORITIES_KEY: &'static [u8] = b":grandpa_authorities";
|
|
|
|
/// The weight of an authority.
|
|
pub type AuthorityWeight = u64;
|
|
|
|
/// The index of an authority.
|
|
pub type AuthorityIndex = u64;
|
|
|
|
/// The monotonic identifier of a GRANDPA set of authorities.
|
|
pub type SetId = u64;
|
|
|
|
/// The round indicator.
|
|
pub type RoundNumber = u64;
|
|
|
|
/// A list of Grandpa authorities with associated weights.
|
|
pub type AuthorityList = Vec<(AuthorityId, AuthorityWeight)>;
|
|
|
|
/// A scheduled change of authority set.
|
|
#[cfg_attr(feature = "std", derive(Serialize))]
|
|
#[derive(Clone, Eq, PartialEq, Encode, Decode, RuntimeDebug)]
|
|
pub struct ScheduledChange<N> {
|
|
/// The new authorities after the change, along with their respective weights.
|
|
pub next_authorities: AuthorityList,
|
|
/// The number of blocks to delay.
|
|
pub delay: N,
|
|
}
|
|
|
|
/// An consensus log item for GRANDPA.
|
|
#[cfg_attr(feature = "std", derive(Serialize))]
|
|
#[derive(Decode, Encode, PartialEq, Eq, Clone, RuntimeDebug)]
|
|
pub enum ConsensusLog<N: Codec> {
|
|
/// Schedule an authority set change.
|
|
///
|
|
/// The earliest digest of this type in a single block will be respected,
|
|
/// provided that there is no `ForcedChange` digest. If there is, then the
|
|
/// `ForcedChange` will take precedence.
|
|
///
|
|
/// 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.
|
|
///
|
|
/// The earliest digest of this type in a single block will be respected,
|
|
/// with others ignored.
|
|
///
|
|
/// 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),
|
|
/// A signal to pause the current authority set after the given delay.
|
|
/// After finalizing the block at _delay_ the authorities should stop voting.
|
|
#[codec(index = "4")]
|
|
Pause(N),
|
|
/// A signal to resume the current authority set after the given delay.
|
|
/// After authoring the block at _delay_ the authorities should resume voting.
|
|
#[codec(index = "5")]
|
|
Resume(N),
|
|
}
|
|
|
|
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),
|
|
_ => 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)),
|
|
_ => None,
|
|
}
|
|
}
|
|
|
|
/// Try to cast the log entry as a contained pause signal.
|
|
pub fn try_into_pause(self) -> Option<N> {
|
|
match self {
|
|
ConsensusLog::Pause(delay) => Some(delay),
|
|
_ => None,
|
|
}
|
|
}
|
|
|
|
/// Try to cast the log entry as a contained resume signal.
|
|
pub fn try_into_resume(self) -> Option<N> {
|
|
match self {
|
|
ConsensusLog::Resume(delay) => Some(delay),
|
|
_ => 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.
|
|
pub const AUTHORITIES_CALL: &str = "grandpa_authorities";
|
|
|
|
/// The current version of the stored AuthorityList type. The encoding version MUST be updated any
|
|
/// time the AuthorityList type changes.
|
|
const AUTHORITIES_VERSION: u8 = 1;
|
|
|
|
/// An AuthorityList that is encoded with a version specifier. The encoding version is updated any
|
|
/// time the AuthorityList type changes. This ensures that encodings of different versions of an
|
|
/// AuthorityList are differentiable. Attempting to decode an authority list with an unknown
|
|
/// version will fail.
|
|
#[derive(Default)]
|
|
pub struct VersionedAuthorityList<'a>(Cow<'a, AuthorityList>);
|
|
|
|
impl<'a> From<AuthorityList> for VersionedAuthorityList<'a> {
|
|
fn from(authorities: AuthorityList) -> Self {
|
|
VersionedAuthorityList(Cow::Owned(authorities))
|
|
}
|
|
}
|
|
|
|
impl<'a> From<&'a AuthorityList> for VersionedAuthorityList<'a> {
|
|
fn from(authorities: &'a AuthorityList) -> Self {
|
|
VersionedAuthorityList(Cow::Borrowed(authorities))
|
|
}
|
|
}
|
|
|
|
impl<'a> Into<AuthorityList> for VersionedAuthorityList<'a> {
|
|
fn into(self) -> AuthorityList {
|
|
self.0.into_owned()
|
|
}
|
|
}
|
|
|
|
impl<'a> Encode for VersionedAuthorityList<'a> {
|
|
fn size_hint(&self) -> usize {
|
|
(AUTHORITIES_VERSION, self.0.as_ref()).size_hint()
|
|
}
|
|
|
|
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
|
(AUTHORITIES_VERSION, self.0.as_ref()).using_encoded(f)
|
|
}
|
|
}
|
|
|
|
impl<'a> Decode for VersionedAuthorityList<'a> {
|
|
fn decode<I: Input>(value: &mut I) -> Result<Self, codec::Error> {
|
|
let (version, authorities): (u8, AuthorityList) = Decode::decode(value)?;
|
|
if version != AUTHORITIES_VERSION {
|
|
return Err("unknown Grandpa authorities version".into());
|
|
}
|
|
Ok(authorities.into())
|
|
}
|
|
}
|
|
|
|
sp_api::decl_runtime_apis! {
|
|
/// APIs for integrating the GRANDPA finality gadget into runtimes.
|
|
/// This should be implemented on the runtime side.
|
|
///
|
|
/// This is primarily used for negotiating authority-set changes for the
|
|
/// gadget. GRANDPA uses a signaling model of changing authority sets:
|
|
/// changes should be signaled with a delay of N blocks, and then automatically
|
|
/// applied in the runtime after those N blocks have passed.
|
|
///
|
|
/// The consensus protocol will coordinate the handoff externally.
|
|
#[api_version(2)]
|
|
pub trait GrandpaApi {
|
|
/// Get the current GRANDPA authorities and weights. This should not change except
|
|
/// for when changes are scheduled and the corresponding delay has passed.
|
|
///
|
|
/// When called at block B, it will return the set of authorities that should be
|
|
/// used to finalize descendants of this block (B+1, B+2, ...). The block B itself
|
|
/// is finalized by the authorities from block B-1.
|
|
fn grandpa_authorities() -> AuthorityList;
|
|
}
|
|
}
|