From b255f8f98711c398eb532041bf4394ead2e2739b Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Thu, 4 Oct 2018 17:54:56 -0400 Subject: [PATCH] grandpa-compatible digest items --- substrate/core/finality-grandpa/src/lib.rs | 19 ++++++++++++++++++- substrate/core/sr-primitives/src/traits.rs | 4 ++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/substrate/core/finality-grandpa/src/lib.rs b/substrate/core/finality-grandpa/src/lib.rs index 969ebc197a..3321e9edad 100644 --- a/substrate/core/finality-grandpa/src/lib.rs +++ b/substrate/core/finality-grandpa/src/lib.rs @@ -43,7 +43,9 @@ use futures::stream::Fuse; use futures::sync::mpsc; use client::{Client, ImportNotifications, backend::Backend, CallExecutor}; use codec::{Encode, Decode}; -use runtime_primitives::traits::{As, NumberFor, Block as BlockT, Header as HeaderT}; +use runtime_primitives::traits::{ + As, NumberFor, Block as BlockT, Header as HeaderT, DigestItemFor, +}; use runtime_primitives::generic::BlockId; use substrate_primitives::{ed25519, AuthorityId, Blake2Hasher}; use tokio::timer::Interval; @@ -390,6 +392,7 @@ impl grandpa::Chain for Environment: As, + DigestItemFor: CompatibleDigestItem>, { fn ancestry(&self, base: Block::Hash, block: Block::Hash) -> Result, GrandpaError> { let tree_route_res = ::client::blockchain::tree_route( @@ -434,6 +437,16 @@ impl grandpa::Chain for Environment { + /// If this digest item notes a GRANDPA set change, return the number of + /// blocks the change should occur after. + fn scheduled_change_in(&self) -> Option { None } +} + impl voter::Environment for Environment where Block: 'static, B: Backend + 'static, @@ -441,6 +454,7 @@ impl voter::Environment for Environment: As, + DigestItemFor: CompatibleDigestItem>, { type Timer = Box>; type Id = AuthorityId; @@ -555,6 +569,7 @@ pub fn run_grandpa( N: Network + 'static, N::In: 'static, NumberFor: As, + DigestItemFor: CompatibleDigestItem>, { let chain_info = client.info()?; let genesis_hash = chain_info.chain.genesis_hash; @@ -597,6 +612,8 @@ mod tests { use keyring::Keyring; use client::BlockchainEvents; + impl CompatibleDigestItem> for DigestItemFor { } + #[derive(Clone)] struct TestGrandpaNetwork { inner: Arc>, diff --git a/substrate/core/sr-primitives/src/traits.rs b/substrate/core/sr-primitives/src/traits.rs index 24dda09345..072dffe3f3 100644 --- a/substrate/core/sr-primitives/src/traits.rs +++ b/substrate/core/sr-primitives/src/traits.rs @@ -447,6 +447,10 @@ pub trait Block: Clone + Send + Sync + Codec + Eq + MaybeSerializeDebug + 'stati pub type HashFor = <::Header as Header>::Hashing; /// Extract the number type for a block. pub type NumberFor = <::Header as Header>::Number; +/// Extract the digest type for a block. +pub type DigestFor = <::Header as Header>::Digest; +/// Extract the digest item type for a block. +pub type DigestItemFor = as Digest>::Item; /// A "checkable" piece of information, used by the standard Substrate Executive in order to /// check the validity of a piece of extrinsic information, usually by verifying the signature.