mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 08:11:03 +00:00
add substrate finality grandpa primitives for WASM
This commit is contained in:
Generated
+12
@@ -3019,6 +3019,17 @@ dependencies = [
|
|||||||
"wasmi 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"wasmi 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "substrate-fg-primitives"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"sr-api 0.1.0",
|
||||||
|
"sr-primitives 0.1.0",
|
||||||
|
"substrate-primitives 0.1.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "substrate-finality-grandpa"
|
name = "substrate-finality-grandpa"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@@ -3032,6 +3043,7 @@ dependencies = [
|
|||||||
"sr-primitives 0.1.0",
|
"sr-primitives 0.1.0",
|
||||||
"substrate-client 0.1.0",
|
"substrate-client 0.1.0",
|
||||||
"substrate-consensus-common 0.1.0",
|
"substrate-consensus-common 0.1.0",
|
||||||
|
"substrate-fg-primitives 0.1.0",
|
||||||
"substrate-keyring 0.1.0",
|
"substrate-keyring 0.1.0",
|
||||||
"substrate-network 0.1.0",
|
"substrate-network 0.1.0",
|
||||||
"substrate-primitives 0.1.0",
|
"substrate-primitives 0.1.0",
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ members = [
|
|||||||
"core/consensus/rhd",
|
"core/consensus/rhd",
|
||||||
"core/executor",
|
"core/executor",
|
||||||
"core/finality-grandpa",
|
"core/finality-grandpa",
|
||||||
|
"core/finality-grandpa/primitives",
|
||||||
"core/keyring",
|
"core/keyring",
|
||||||
"core/network",
|
"core/network",
|
||||||
"core/primitives",
|
"core/primitives",
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ substrate-client = { path = "../client" }
|
|||||||
log = "0.4"
|
log = "0.4"
|
||||||
parking_lot = "0.4"
|
parking_lot = "0.4"
|
||||||
tokio = "0.1.7"
|
tokio = "0.1.7"
|
||||||
|
substrate-fg-primitives = { path = "primitives" }
|
||||||
|
|
||||||
[dependencies.finality-grandpa]
|
[dependencies.finality-grandpa]
|
||||||
#version = "0.3.0"
|
#version = "0.3.0"
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
[package]
|
||||||
|
name = "substrate-fg-primitives"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Parity Technologies <admin@parity.io>"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
substrate-primitives = { path = "../../primitives", default-features = false }
|
||||||
|
parity-codec = { version = "2.1", default-features = false }
|
||||||
|
parity-codec-derive = { version = "2.1", default-features = false }
|
||||||
|
sr-api = { path = "../../sr-api", default-features = false }
|
||||||
|
sr-primitives = { path = "../../sr-primitives", default-features = false }
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["std"]
|
||||||
|
std = [
|
||||||
|
"substrate-primitives/std",
|
||||||
|
"parity-codec/std",
|
||||||
|
"parity-codec-derive/std",
|
||||||
|
"sr-api/std",
|
||||||
|
"sr-primitives/std",
|
||||||
|
]
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
// Copyright 2018 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)]
|
||||||
|
|
||||||
|
extern crate substrate_primitives;
|
||||||
|
extern crate sr_primitives;
|
||||||
|
extern crate parity_codec;
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate parity_codec_derive;
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate sr_api;
|
||||||
|
|
||||||
|
use substrate_primitives::AuthorityId;
|
||||||
|
use sr_primitives::traits::{Block as BlockT, DigestFor, NumberFor};
|
||||||
|
|
||||||
|
/// A scheduled change of authority set.
|
||||||
|
#[cfg_attr(feature = "std", derive(Debug, PartialEq))]
|
||||||
|
#[derive(Encode, Decode)]
|
||||||
|
pub struct ScheduledChange<N> {
|
||||||
|
/// The new authorities after the change, along with their respective weights.
|
||||||
|
pub next_authorities: Vec<(AuthorityId, u64)>,
|
||||||
|
/// The number of blocks to delay.
|
||||||
|
pub delay: N,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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_pending_change";
|
||||||
|
|
||||||
|
decl_apis! {
|
||||||
|
/// APIs for integrating the GRANDPA finality gadget into runtimes.
|
||||||
|
///
|
||||||
|
/// This is primarily used for negotiating authority-set changes for the
|
||||||
|
/// gadget. GRANDPA uses a signalling model of changing authority sets:
|
||||||
|
/// changes should be signalled 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.
|
||||||
|
pub trait Api<B: BlockT> {
|
||||||
|
/// Check a digest for pending changes.
|
||||||
|
/// Return `None` if there are no pending changes.
|
||||||
|
///
|
||||||
|
/// 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.
|
||||||
|
fn grandpa_pending_change(digest: DigestFor<B>) -> Option<ScheduledChange<NumberFor<B>>>;
|
||||||
|
|
||||||
|
/// Get the current GRANDPA authorities. This should not change except
|
||||||
|
/// for when changes are scheduled and the corresponding delay has passed.
|
||||||
|
fn grandpa_authorities() -> Vec<AuthorityId>;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,11 +14,9 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
// tag::description[]
|
|
||||||
//! Integration of the GRANDPA finality gadget into substrate.
|
//! Integration of the GRANDPA finality gadget into substrate.
|
||||||
//!
|
//!
|
||||||
//! This is a long-running future that produces finality notifications.
|
//! This is a long-running future that produces finality notifications.
|
||||||
// end::description[]
|
|
||||||
|
|
||||||
extern crate finality_grandpa as grandpa;
|
extern crate finality_grandpa as grandpa;
|
||||||
extern crate futures;
|
extern crate futures;
|
||||||
@@ -29,6 +27,7 @@ extern crate substrate_primitives;
|
|||||||
extern crate tokio;
|
extern crate tokio;
|
||||||
extern crate parking_lot;
|
extern crate parking_lot;
|
||||||
extern crate parity_codec as codec;
|
extern crate parity_codec as codec;
|
||||||
|
extern crate substrate_fg_primitives as fg_primitives;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log;
|
extern crate log;
|
||||||
@@ -64,6 +63,8 @@ use std::time::{Instant, Duration};
|
|||||||
|
|
||||||
use authorities::SharedAuthoritySet;
|
use authorities::SharedAuthoritySet;
|
||||||
|
|
||||||
|
pub use fg_primitives::ScheduledChange;
|
||||||
|
|
||||||
mod authorities;
|
mod authorities;
|
||||||
|
|
||||||
const LAST_COMPLETED_KEY: &[u8] = b"grandpa_completed_round";
|
const LAST_COMPLETED_KEY: &[u8] = b"grandpa_completed_round";
|
||||||
@@ -485,26 +486,6 @@ impl<Block: BlockT, B, E, N> grandpa::Chain<Block::Hash, NumberFor<Block>> for E
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A scheduled change of authority set.
|
|
||||||
#[derive(Debug, PartialEq)]
|
|
||||||
pub struct ScheduledChange<N> {
|
|
||||||
/// The new authorities after the change, along with their respective weights.
|
|
||||||
pub next_authorities: Vec<(AuthorityId, u64)>,
|
|
||||||
/// The number of blocks to delay.
|
|
||||||
pub delay: N,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A GRANDPA-compatible DigestItem. This can describe when GRANDPA set changes
|
|
||||||
/// are scheduled.
|
|
||||||
//
|
|
||||||
// With specialization, could do a blanket implementation so this trait
|
|
||||||
// doesn't have to be implemented by users.
|
|
||||||
pub trait CompatibleDigestItem<N> {
|
|
||||||
/// If this digest item notes a GRANDPA set change, return information about
|
|
||||||
/// the scheduled change.
|
|
||||||
fn scheduled_change(&self) -> Option<ScheduledChange<N>> { None }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A new authority set along with the canonical block it changed at.
|
/// A new authority set along with the canonical block it changed at.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct NewAuthoritySet<H, N> {
|
struct NewAuthoritySet<H, N> {
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ extern crate sr_io as runtime_io;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate sr_version as runtime_version;
|
extern crate sr_version as runtime_version;
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate hex_literal;
|
extern crate hex_literal;
|
||||||
|
|||||||
Reference in New Issue
Block a user