diff --git a/substrate/Cargo.lock b/substrate/Cargo.lock index 84f487ceedc99925f49a3f32afdedb76b7ed40be..fb944b782abd9636d722e8416222bfffeb28145e 100644 --- a/substrate/Cargo.lock +++ b/substrate/Cargo.lock @@ -1679,9 +1679,9 @@ dependencies = [ [[package]] name = "finality-grandpa" -version = "0.14.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6447e2f8178843749e8c8003206def83ec124a7859475395777a28b5338647c" +checksum = "74a1bfdcc776e63e49f741c7ce6116fa1b887e8ac2e3ccb14dd4aa113e54feb9" dependencies = [ "either", "futures 0.3.15", diff --git a/substrate/client/finality-grandpa-warp-sync/Cargo.toml b/substrate/client/finality-grandpa-warp-sync/Cargo.toml index 3557d543c987ebe3b99ab4d813e2bc70e2b74ede..27728e159c7622ea2f286bf2bd39e80f384042ed 100644 --- a/substrate/client/finality-grandpa-warp-sync/Cargo.toml +++ b/substrate/client/finality-grandpa-warp-sync/Cargo.toml @@ -28,7 +28,7 @@ sp-finality-grandpa = { version = "3.0.0", path = "../../primitives/finality-gra sp-runtime = { version = "3.0.0", path = "../../primitives/runtime" } [dev-dependencies] -finality-grandpa = { version = "0.14.0" } +finality-grandpa = { version = "0.14.1" } rand = "0.8" sc-block-builder = { version = "0.9.0", path = "../block-builder" } sp-consensus = { version = "0.9.0", path = "../../primitives/consensus/common" } diff --git a/substrate/client/finality-grandpa-warp-sync/src/lib.rs b/substrate/client/finality-grandpa-warp-sync/src/lib.rs index a6b7e46a0f02952a7a769f135c4b5c3b59bea9f1..c0ef93e625fd8ef230f1f174ead5dea8af407071 100644 --- a/substrate/client/finality-grandpa-warp-sync/src/lib.rs +++ b/substrate/client/finality-grandpa-warp-sync/src/lib.rs @@ -40,7 +40,8 @@ pub fn request_response_config_for_chain<TBlock: BlockT, TBackend: Backend<TBloc backend: Arc<TBackend>, authority_set: SharedAuthoritySet<TBlock::Hash, NumberFor<TBlock>>, ) -> RequestResponseConfig - where NumberFor<TBlock>: sc_finality_grandpa::BlockNumberOps, +where + NumberFor<TBlock>: sc_finality_grandpa::BlockNumberOps, { let protocol_id = config.protocol_id(); @@ -54,7 +55,7 @@ pub fn request_response_config_for_chain<TBlock: BlockT, TBackend: Backend<TBloc backend.clone(), authority_set, ); - spawn_handle.spawn("grandpa_warp_sync_request_handler", handler.run()); + spawn_handle.spawn("grandpa-warp-sync", handler.run()); request_response_config } } diff --git a/substrate/client/finality-grandpa/Cargo.toml b/substrate/client/finality-grandpa/Cargo.toml index ea91460972c9c52d10491183a8a325ba84b473e9..3cb577aee5db807b1d1c2630c59b1a413f9a0b03 100644 --- a/substrate/client/finality-grandpa/Cargo.toml +++ b/substrate/client/finality-grandpa/Cargo.toml @@ -44,7 +44,7 @@ sc-network-gossip = { version = "0.9.0", path = "../network-gossip" } sp-finality-grandpa = { version = "3.0.0", path = "../../primitives/finality-grandpa" } prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../utils/prometheus", version = "0.9.0"} sc-block-builder = { version = "0.9.0", path = "../block-builder" } -finality-grandpa = { version = "0.14.0", features = ["derive-codec"] } +finality-grandpa = { version = "0.14.1", features = ["derive-codec"] } pin-project = "1.0.4" linked-hash-map = "0.5.2" async-trait = "0.1.42" @@ -52,7 +52,7 @@ wasm-timer = "0.2" [dev-dependencies] assert_matches = "1.3.0" -finality-grandpa = { version = "0.14.0", features = ["derive-codec", "test-helpers"] } +finality-grandpa = { version = "0.14.1", features = ["derive-codec", "test-helpers"] } sc-network = { version = "0.9.0", path = "../network" } sc-network-test = { version = "0.8.0", path = "../network/test" } sp-keyring = { version = "3.0.0", path = "../../primitives/keyring" } diff --git a/substrate/client/finality-grandpa/rpc/Cargo.toml b/substrate/client/finality-grandpa/rpc/Cargo.toml index ff5b4cafdae77c3f12f6f9090ffdc204f3089acf..97359120fcaae604cf494075ad95b3bb67888197 100644 --- a/substrate/client/finality-grandpa/rpc/Cargo.toml +++ b/substrate/client/finality-grandpa/rpc/Cargo.toml @@ -14,7 +14,7 @@ sc-rpc = { version = "3.0.0", path = "../../rpc" } sp-blockchain = { version = "3.0.0", path = "../../../primitives/blockchain" } sp-core = { version = "3.0.0", path = "../../../primitives/core" } sp-runtime = { version = "3.0.0", path = "../../../primitives/runtime" } -finality-grandpa = { version = "0.14.0", features = ["derive-codec"] } +finality-grandpa = { version = "0.14.1", features = ["derive-codec"] } jsonrpc-core = "15.1.0" jsonrpc-core-client = "15.1.0" jsonrpc-derive = "15.1.0" diff --git a/substrate/client/finality-grandpa/src/communication/mod.rs b/substrate/client/finality-grandpa/src/communication/mod.rs index 0d287cc96e535696d2f9afeeae9ccb9af4a7d08a..45bc72223e4b5e04484460023a29ad11178ccfa2 100644 --- a/substrate/client/finality-grandpa/src/communication/mod.rs +++ b/substrate/client/finality-grandpa/src/communication/mod.rs @@ -117,7 +117,7 @@ impl LocalIdKeystore { } /// Returns a reference to the keystore. - fn keystore(&self) -> SyncCryptoStorePtr{ + fn keystore(&self) -> SyncCryptoStorePtr { (self.0).1.clone() } } diff --git a/substrate/client/finality-grandpa/src/environment.rs b/substrate/client/finality-grandpa/src/environment.rs index d3a5b49b50726d154e9a2f64ca8d27a4cc938863..3d593a17ffdbff4b515536f8c7aa74b3bdf34de2 100644 --- a/substrate/client/finality-grandpa/src/environment.rs +++ b/substrate/client/finality-grandpa/src/environment.rs @@ -23,43 +23,42 @@ use std::pin::Pin; use std::sync::Arc; use std::time::Duration; +use finality_grandpa::{ + round::State as RoundState, voter, voter_set::VoterSet, BlockNumberOps, Error as GrandpaError, +}; use futures::prelude::*; use futures_timer::Delay; use log::{debug, warn}; use parity_scale_codec::{Decode, Encode}; use parking_lot::RwLock; +use prometheus_endpoint::{register, Counter, Gauge, PrometheusError, U64}; -use sc_client_api::{backend::{Backend, apply_aux}, utils::is_descendent_of}; -use finality_grandpa::{ - BlockNumberOps, Error as GrandpaError, round::State as RoundState, - voter, voter_set::VoterSet, +use sc_client_api::{ + backend::{apply_aux, Backend}, + utils::is_descendent_of, }; +use sc_telemetry::{telemetry, TelemetryHandle, CONSENSUS_DEBUG, CONSENSUS_INFO}; use sp_blockchain::HeaderMetadata; -use sp_runtime::generic::BlockId; -use sp_runtime::traits::{ - Block as BlockT, Header as HeaderT, NumberFor, Zero, +use sp_consensus::SelectChain; +use sp_finality_grandpa::{ + AuthorityId, AuthoritySignature, Equivocation, EquivocationProof, GrandpaApi, RoundNumber, + SetId, GRANDPA_ENGINE_ID, }; -use sc_telemetry::{telemetry, TelemetryHandle, CONSENSUS_DEBUG, CONSENSUS_INFO}; +use sp_runtime::generic::BlockId; +use sp_runtime::traits::{Block as BlockT, Header as HeaderT, NumberFor, Zero}; use crate::{ - local_authority_id, CommandOrError, Commit, Config, Error, NewAuthoritySet, Precommit, Prevote, + authorities::{AuthoritySet, SharedAuthoritySet}, + communication::Network as NetworkT, + justification::GrandpaJustification, + local_authority_id, + notification::GrandpaJustificationSender, + until_imported::UntilVoteTargetImported, + voting_rule::VotingRule, + ClientForGrandpa, CommandOrError, Commit, Config, Error, NewAuthoritySet, Precommit, Prevote, PrimaryPropose, SignedMessage, VoterCommand, }; -use sp_consensus::SelectChain; - -use crate::authorities::{AuthoritySet, SharedAuthoritySet}; -use crate::communication::Network as NetworkT; -use crate::notification::GrandpaJustificationSender; -use crate::justification::GrandpaJustification; -use crate::until_imported::UntilVoteTargetImported; -use crate::voting_rule::VotingRule; -use sp_finality_grandpa::{ - AuthorityId, AuthoritySignature, Equivocation, EquivocationProof, GRANDPA_ENGINE_ID, - GrandpaApi, RoundNumber, SetId, -}; -use prometheus_endpoint::{register, Counter, Gauge, PrometheusError, U64}; - type HistoricalVotes<Block> = finality_grandpa::HistoricalVotes< <Block as BlockT>::Hash, NumberFor<Block>, @@ -480,10 +479,10 @@ impl<BE, Block, C, N, SC, VR> Environment<BE, Block, C, N, SC, VR> where Block: BlockT, BE: Backend<Block>, - C: crate::ClientForGrandpa<Block, BE>, + C: ClientForGrandpa<Block, BE>, C::Api: GrandpaApi<Block>, N: NetworkT<Block>, - SC: SelectChain<Block> + 'static, + SC: SelectChain<Block>, { /// Report the given equivocation to the GRANDPA runtime module. This method /// generates a session membership proof of the offender and then submits an @@ -578,24 +577,26 @@ where } } -impl<BE, Block: BlockT, C, N, SC, VR> - finality_grandpa::Chain<Block::Hash, NumberFor<Block>> -for Environment<BE, Block, C, N, SC, VR> +impl<BE, Block, C, N, SC, VR> finality_grandpa::Chain<Block::Hash, NumberFor<Block>> + for Environment<BE, Block, C, N, SC, VR> where - Block: 'static, + Block: BlockT, BE: Backend<Block>, - C: crate::ClientForGrandpa<Block, BE>, - N: NetworkT<Block> + 'static + Send, - SC: SelectChain<Block> + 'static, + C: ClientForGrandpa<Block, BE>, + N: NetworkT<Block>, + SC: SelectChain<Block>, VR: VotingRule<Block, C>, NumberFor<Block>: BlockNumberOps, { - fn ancestry(&self, base: Block::Hash, block: Block::Hash) -> Result<Vec<Block::Hash>, GrandpaError> { + fn ancestry( + &self, + base: Block::Hash, + block: Block::Hash, + ) -> Result<Vec<Block::Hash>, GrandpaError> { ancestry(&self.client, base, block) } } - pub(crate) fn ancestry<Block: BlockT, Client>( client: &Arc<Client>, base: Block::Hash, @@ -624,27 +625,31 @@ where // skip one because our ancestry is meant to start from the parent of `block`, // and `tree_route` includes it. - Ok(tree_route.retracted().iter().skip(1).map(|e| e.hash).collect()) + Ok(tree_route + .retracted() + .iter() + .skip(1) + .map(|e| e.hash) + .collect()) } -impl<B, Block: BlockT, C, N, SC, VR> voter::Environment<Block::Hash, NumberFor<Block>> +impl<B, Block, C, N, SC, VR> voter::Environment<Block::Hash, NumberFor<Block>> for Environment<B, Block, C, N, SC, VR> where - Block: 'static, + Block: BlockT, B: Backend<Block>, - C: crate::ClientForGrandpa<Block, B> + 'static, + C: ClientForGrandpa<Block, B> + 'static, C::Api: GrandpaApi<Block>, - N: NetworkT<Block> + 'static + Send + Sync, - SC: SelectChain<Block> + 'static, + N: NetworkT<Block>, + SC: SelectChain<Block>, VR: VotingRule<Block, C>, NumberFor<Block>: BlockNumberOps, { - type Timer = Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + Sync>>; + type Timer = Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send>>; type BestChain = Pin< Box< dyn Future<Output = Result<Option<(Block::Hash, NumberFor<Block>)>, Self::Error>> - + Send - + Sync + + Send, >, >; @@ -652,13 +657,29 @@ where type Signature = AuthoritySignature; // regular round message streams - type In = Pin<Box<dyn Stream< - Item = Result<::finality_grandpa::SignedMessage<Block::Hash, NumberFor<Block>, Self::Signature, Self::Id>, Self::Error> - > + Send + Sync>>; - type Out = Pin<Box<dyn Sink< - ::finality_grandpa::Message<Block::Hash, NumberFor<Block>>, - Error = Self::Error, - > + Send + Sync>>; + type In = Pin< + Box< + dyn Stream< + Item = Result< + ::finality_grandpa::SignedMessage< + Block::Hash, + NumberFor<Block>, + Self::Signature, + Self::Id, + >, + Self::Error, + >, + > + Send, + >, + >; + type Out = Pin< + Box< + dyn Sink< + ::finality_grandpa::Message<Block::Hash, NumberFor<Block>>, + Error = Self::Error, + > + Send, + >, + >; type Error = CommandOrError<Block::Hash, NumberFor<Block>>; @@ -1223,7 +1244,7 @@ pub(crate) fn finalize_block<BE, Block, Client>( where Block: BlockT, BE: Backend<Block>, - Client: crate::ClientForGrandpa<Block, BE>, + Client: ClientForGrandpa<Block, BE>, { // NOTE: lock must be held through writing to DB to avoid race. this lock // also implicitly synchronizes the check for last finalized number diff --git a/substrate/client/finality-grandpa/src/finality_proof.rs b/substrate/client/finality-grandpa/src/finality_proof.rs index 6735d91ba8b751c685195fb32dd06f433ee1670f..ec33d48774ae5735a91ba2df130a9cfa34bfb6c3 100644 --- a/substrate/client/finality-grandpa/src/finality_proof.rs +++ b/substrate/client/finality-grandpa/src/finality_proof.rs @@ -62,9 +62,10 @@ pub struct FinalityProofProvider<BE, Block: BlockT> { shared_authority_set: Option<SharedAuthoritySet<Block::Hash, NumberFor<Block>>>, } -impl<B, Block: BlockT> FinalityProofProvider<B, Block> +impl<B, Block> FinalityProofProvider<B, Block> where - B: Backend<Block> + Send + Sync + 'static, + Block: BlockT, + B: Backend<Block>, { /// Create new finality proof provider using: /// @@ -97,7 +98,7 @@ where impl<B, Block> FinalityProofProvider<B, Block> where Block: BlockT, - B: Backend<Block> + Send + Sync + 'static, + B: Backend<Block>, { /// Prove finality for the given block number by returning a Justification for the last block of /// the authority set. diff --git a/substrate/client/finality-grandpa/src/import.rs b/substrate/client/finality-grandpa/src/import.rs index 3d22cc8866100e178fa86ff408c2220b59f02a5d..de02ea357cac44e98c0a39fff9901f3fb6c10822 100644 --- a/substrate/client/finality-grandpa/src/import.rs +++ b/substrate/client/finality-grandpa/src/import.rs @@ -16,36 +16,33 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. -use std::{sync::Arc, collections::HashMap}; +use std::{collections::HashMap, marker::PhantomData, sync::Arc}; use log::debug; use parity_scale_codec::Encode; -use sp_blockchain::{BlockStatus, well_known_cache_keys}; use sc_client_api::{backend::Backend, utils::is_descendent_of}; +use sc_consensus::shared_data::{SharedDataLocked, SharedDataLockedUpgradable}; use sc_telemetry::TelemetryHandle; -use sp_utils::mpsc::TracingUnboundedSender; use sp_api::TransactionFor; -use sc_consensus::shared_data::{SharedDataLockedUpgradable, SharedDataLocked}; - +use sp_blockchain::{well_known_cache_keys, BlockStatus}; use sp_consensus::{ - BlockImport, Error as ConsensusError, - BlockCheckParams, BlockImportParams, BlockOrigin, ImportResult, JustificationImport, - SelectChain, + BlockCheckParams, BlockImport, BlockImportParams, BlockOrigin, Error as ConsensusError, + ImportResult, JustificationImport, SelectChain, }; use sp_finality_grandpa::{ConsensusLog, ScheduledChange, SetId, GRANDPA_ENGINE_ID}; -use sp_runtime::Justification; use sp_runtime::generic::{BlockId, OpaqueDigestItemId}; -use sp_runtime::traits::{ - Block as BlockT, DigestFor, Header as HeaderT, NumberFor, Zero, -}; +use sp_runtime::traits::{Block as BlockT, DigestFor, Header as HeaderT, NumberFor, Zero}; +use sp_runtime::Justification; +use sp_utils::mpsc::TracingUnboundedSender; -use crate::{Error, CommandOrError, NewAuthoritySet, VoterCommand}; -use crate::authorities::{AuthoritySet, SharedAuthoritySet, DelayKind, PendingChange}; -use crate::environment::finalize_block; -use crate::justification::GrandpaJustification; -use crate::notification::GrandpaJustificationSender; -use std::marker::PhantomData; +use crate::{ + authorities::{AuthoritySet, DelayKind, PendingChange, SharedAuthoritySet}, + environment::finalize_block, + justification::GrandpaJustification, + notification::GrandpaJustificationSender, + ClientForGrandpa, CommandOrError, Error, NewAuthoritySet, VoterCommand, +}; /// A block-import handler for GRANDPA. /// @@ -67,8 +64,8 @@ pub struct GrandpaBlockImport<Backend, Block: BlockT, Client, SC> { _phantom: PhantomData<Backend>, } -impl<Backend, Block: BlockT, Client, SC: Clone> Clone for - GrandpaBlockImport<Backend, Block, Client, SC> +impl<Backend, Block: BlockT, Client, SC: Clone> Clone + for GrandpaBlockImport<Backend, Block, Client, SC> { fn clone(&self) -> Self { GrandpaBlockImport { @@ -85,12 +82,13 @@ impl<Backend, Block: BlockT, Client, SC: Clone> Clone for } impl<BE, Block: BlockT, Client, SC> JustificationImport<Block> - for GrandpaBlockImport<BE, Block, Client, SC> where - NumberFor<Block>: finality_grandpa::BlockNumberOps, - DigestFor<Block>: Encode, - BE: Backend<Block>, - Client: crate::ClientForGrandpa<Block, BE>, - SC: SelectChain<Block>, + for GrandpaBlockImport<BE, Block, Client, SC> +where + NumberFor<Block>: finality_grandpa::BlockNumberOps, + DigestFor<Block>: Encode, + BE: Backend<Block>, + Client: ClientForGrandpa<Block, BE>, + SC: SelectChain<Block>, { type Error = ConsensusError; @@ -219,13 +217,12 @@ pub fn find_forced_change<B: BlockT>( header.digest().convert_first(|l| l.try_to(id).and_then(filter_log)) } -impl<BE, Block: BlockT, Client, SC> - GrandpaBlockImport<BE, Block, Client, SC> +impl<BE, Block: BlockT, Client, SC> GrandpaBlockImport<BE, Block, Client, SC> where NumberFor<Block>: finality_grandpa::BlockNumberOps, DigestFor<Block>: Encode, BE: Backend<Block>, - Client: crate::ClientForGrandpa<Block, BE>, + Client: ClientForGrandpa<Block, BE>, { // check for a new authority set change. fn check_new_change( @@ -416,21 +413,25 @@ where let just_in_case = just_in_case.map(|(o, i)| (o, i.release_mutex())); - Ok(PendingSetChanges { just_in_case, applied_changes, do_pause }) + Ok(PendingSetChanges { + just_in_case, + applied_changes, + do_pause, + }) } } #[async_trait::async_trait] -impl<BE, Block: BlockT, Client, SC> BlockImport<Block> - for GrandpaBlockImport<BE, Block, Client, SC> where - NumberFor<Block>: finality_grandpa::BlockNumberOps, - DigestFor<Block>: Encode, - BE: Backend<Block>, - Client: crate::ClientForGrandpa<Block, BE>, - for<'a> &'a Client: - BlockImport<Block, Error = ConsensusError, Transaction = TransactionFor<Client, Block>>, - TransactionFor<Client, Block>: Send + 'static, - SC: Send, +impl<BE, Block: BlockT, Client, SC> BlockImport<Block> for GrandpaBlockImport<BE, Block, Client, SC> +where + NumberFor<Block>: finality_grandpa::BlockNumberOps, + DigestFor<Block>: Encode, + BE: Backend<Block>, + Client: ClientForGrandpa<Block, BE>, + for<'a> &'a Client: + BlockImport<Block, Error = ConsensusError, Transaction = TransactionFor<Client, Block>>, + TransactionFor<Client, Block>: 'static, + SC: Send, { type Error = ConsensusError; type Transaction = TransactionFor<Client, Block>; @@ -630,7 +631,7 @@ impl<Backend, Block: BlockT, Client, SC> GrandpaBlockImport<Backend, Block, Clie impl<BE, Block: BlockT, Client, SC> GrandpaBlockImport<BE, Block, Client, SC> where BE: Backend<Block>, - Client: crate::ClientForGrandpa<Block, BE>, + Client: ClientForGrandpa<Block, BE>, NumberFor<Block>: finality_grandpa::BlockNumberOps, { /// Import a block justification and finalize the block. diff --git a/substrate/client/finality-grandpa/src/lib.rs b/substrate/client/finality-grandpa/src/lib.rs index f249d3982cf2512cc548965f14f92203ff2efafe..a133319fdbef43db59888830a1177971c4422bf0 100644 --- a/substrate/client/finality-grandpa/src/lib.rs +++ b/substrate/client/finality-grandpa/src/lib.rs @@ -627,13 +627,17 @@ fn global_communication<BE, Block: BlockT, C, N>( metrics: Option<until_imported::Metrics>, ) -> ( impl Stream< - Item = Result<CommunicationInH<Block, Block::Hash>, CommandOrError<Block::Hash, NumberFor<Block>>>, + Item = Result< + CommunicationInH<Block, Block::Hash>, + CommandOrError<Block::Hash, NumberFor<Block>>, + >, >, impl Sink< CommunicationOutH<Block, Block::Hash>, Error = CommandOrError<Block::Hash, NumberFor<Block>>, - > + Unpin, -) where + >, +) +where BE: Backend<Block> + 'static, C: ClientForGrandpa<Block, BE> + 'static, N: NetworkT<Block>, @@ -707,11 +711,11 @@ pub fn grandpa_peers_set_config() -> sc_network::config::NonDefaultSetConfig { /// block import worker that has already been instantiated with `block_import`. pub fn run_grandpa_voter<Block: BlockT, BE: 'static, C, N, SC, VR>( grandpa_params: GrandpaParams<Block, C, N, SC, VR>, -) -> sp_blockchain::Result<impl Future<Output = ()> + Unpin + Send + 'static> +) -> sp_blockchain::Result<impl Future<Output = ()> + Send> where Block::Hash: Ord, BE: Backend<Block> + 'static, - N: NetworkT<Block> + Send + Sync + Clone + 'static, + N: NetworkT<Block> + Sync + 'static, SC: SelectChain<Block> + 'static, VR: VotingRule<Block, C> + Clone + 'static, NumberFor<Block>: BlockNumberOps, diff --git a/substrate/client/finality-grandpa/src/observer.rs b/substrate/client/finality-grandpa/src/observer.rs index 5434cd08a91d0973ffe9182c9d64468b6fae1f33..23c4f873a10b7bcc4e49643e497654c9ba62a8f3 100644 --- a/substrate/client/finality-grandpa/src/observer.rs +++ b/substrate/client/finality-grandpa/src/observer.rs @@ -16,33 +16,33 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. +use std::marker::{PhantomData, Unpin}; use std::pin::Pin; use std::sync::Arc; use std::task::{Context, Poll}; +use finality_grandpa::{voter, voter_set::VoterSet, BlockNumberOps, Error as GrandpaError}; use futures::prelude::*; - -use finality_grandpa::{ - BlockNumberOps, Error as GrandpaError, voter, voter_set::VoterSet -}; use log::{debug, info, warn}; -use sp_keystore::SyncCryptoStorePtr; -use sp_consensus::SelectChain; + use sc_client_api::backend::Backend; use sc_telemetry::TelemetryHandle; -use sp_utils::mpsc::TracingUnboundedReceiver; -use sp_runtime::traits::{NumberFor, Block as BlockT}; use sp_blockchain::HeaderMetadata; +use sp_consensus::SelectChain; +use sp_finality_grandpa::AuthorityId; +use sp_keystore::SyncCryptoStorePtr; +use sp_runtime::traits::{Block as BlockT, NumberFor}; +use sp_utils::mpsc::TracingUnboundedReceiver; use crate::{ - global_communication, CommandOrError, CommunicationIn, Config, environment, - LinkHalf, Error, aux_schema::PersistentData, VoterCommand, VoterSetState, + authorities::SharedAuthoritySet, + aux_schema::PersistentData, + communication::{Network as NetworkT, NetworkBridge}, + environment, global_communication, + notification::GrandpaJustificationSender, + ClientForGrandpa, CommandOrError, CommunicationIn, Config, Error, LinkHalf, VoterCommand, + VoterSetState, }; -use crate::authorities::SharedAuthoritySet; -use crate::communication::{Network as NetworkT, NetworkBridge}; -use crate::notification::GrandpaJustificationSender; -use sp_finality_grandpa::AuthorityId; -use std::marker::{PhantomData, Unpin}; struct ObserverChain<'a, Block: BlockT, Client> { client: &'a Arc<Client>, @@ -50,12 +50,17 @@ struct ObserverChain<'a, Block: BlockT, Client> { } impl<'a, Block, Client> finality_grandpa::Chain<Block::Hash, NumberFor<Block>> - for ObserverChain<'a, Block, Client> where - Block: BlockT, - Client: HeaderMetadata<Block, Error = sp_blockchain::Error>, - NumberFor<Block>: BlockNumberOps, + for ObserverChain<'a, Block, Client> +where + Block: BlockT, + Client: HeaderMetadata<Block, Error = sp_blockchain::Error>, + NumberFor<Block>: BlockNumberOps, { - fn ancestry(&self, base: Block::Hash, block: Block::Hash) -> Result<Vec<Block::Hash>, GrandpaError> { + fn ancestry( + &self, + base: Block::Hash, + block: Block::Hash, + ) -> Result<Vec<Block::Hash>, GrandpaError> { environment::ancestry(&self.client, base, block) } } @@ -75,7 +80,7 @@ where S: Stream<Item = Result<CommunicationIn<Block>, CommandOrError<Block::Hash, NumberFor<Block>>>>, F: Fn(u64), BE: Backend<Block>, - Client: crate::ClientForGrandpa<Block, BE>, + Client: ClientForGrandpa<Block, BE>, { let authority_set = authority_set.clone(); let client = client.clone(); @@ -160,13 +165,13 @@ pub fn run_grandpa_observer<BE, Block: BlockT, Client, N, SC>( config: Config, link: LinkHalf<Block, Client, SC>, network: N, -) -> sp_blockchain::Result<impl Future<Output = ()> + Unpin + Send + 'static> +) -> sp_blockchain::Result<impl Future<Output = ()> + Send> where BE: Backend<Block> + Unpin + 'static, - N: NetworkT<Block> + Send + Clone + 'static, - SC: SelectChain<Block> + 'static, + N: NetworkT<Block>, + SC: SelectChain<Block>, NumberFor<Block>: BlockNumberOps, - Client: crate::ClientForGrandpa<Block, BE> + 'static, + Client: ClientForGrandpa<Block, BE> + 'static, { let LinkHalf { client, @@ -223,7 +228,7 @@ impl<B, BE, Client, Network> ObserverWork<B, BE, Client, Network> where B: BlockT, BE: Backend<B> + 'static, - Client: crate::ClientForGrandpa<B, BE> + 'static, + Client: ClientForGrandpa<B, BE> + 'static, Network: NetworkT<B>, NumberFor<B>: BlockNumberOps, { @@ -236,7 +241,6 @@ where justification_sender: Option<GrandpaJustificationSender<B>>, telemetry: Option<TelemetryHandle>, ) -> Self { - let mut work = ObserverWork { // `observer` is set to a temporary value and replaced below when // calling `rebuild_observer`. @@ -344,7 +348,7 @@ impl<B, BE, C, N> Future for ObserverWork<B, BE, C, N> where B: BlockT, BE: Backend<B> + Unpin + 'static, - C: crate::ClientForGrandpa<B, BE> + 'static, + C: ClientForGrandpa<B, BE> + 'static, N: NetworkT<B>, NumberFor<B>: BlockNumberOps, { diff --git a/substrate/client/finality-grandpa/src/tests.rs b/substrate/client/finality-grandpa/src/tests.rs index 475c11191b10cec7c23f891bc26bc6f0b2b931c7..725beec6a94b2449cdb39d7c5cdf1b65bfb9755d 100644 --- a/substrate/client/finality-grandpa/src/tests.rs +++ b/substrate/client/finality-grandpa/src/tests.rs @@ -1013,7 +1013,7 @@ fn voter_persists_its_votes() { fn alice_voter2( peers: &[Ed25519Keyring], net: Arc<Mutex<GrandpaTestNet>>, - ) -> impl Future<Output = ()> + Unpin + Send + 'static { + ) -> impl Future<Output = ()> + Send { let (keystore, _) = create_keystore(peers[0]); let mut net = net.lock(); diff --git a/substrate/client/finality-grandpa/src/until_imported.rs b/substrate/client/finality-grandpa/src/until_imported.rs index d2e896685658b6291a472e045cf424eac0c8e7ec..7cfd9e6074c47ef0c8ee103f31ae7950addd3883 100644 --- a/substrate/client/finality-grandpa/src/until_imported.rs +++ b/substrate/client/finality-grandpa/src/until_imported.rs @@ -136,12 +136,14 @@ impl Drop for Metrics { fn drop(&mut self) { // Reduce the global counter by the amount of messages that were still left in the dropped // queue. - self.global_waiting_messages.sub(self.local_waiting_messages) + self.global_waiting_messages + .sub(self.local_waiting_messages) } } /// Buffering incoming messages until blocks with given hashes are imported. -pub(crate) struct UntilImported<Block, BlockStatus, BlockSyncRequester, I, M> where +pub(crate) struct UntilImported<Block, BlockStatus, BlockSyncRequester, I, M> +where Block: BlockT, I: Stream<Item = M::Blocked> + Unpin, M: BlockUntilImported<Block>, @@ -152,7 +154,7 @@ pub(crate) struct UntilImported<Block, BlockStatus, BlockSyncRequester, I, M> wh incoming_messages: Fuse<I>, ready: VecDeque<M::Blocked>, /// Interval at which to check status of each awaited block. - check_pending: Pin<Box<dyn Stream<Item = Result<(), std::io::Error>> + Send + Sync>>, + check_pending: Pin<Box<dyn Stream<Item = Result<(), std::io::Error>> + Send>>, /// Mapping block hashes to their block number, the point in time it was /// first encountered (Instant) and a list of GRANDPA messages referencing /// the block hash. @@ -164,13 +166,18 @@ pub(crate) struct UntilImported<Block, BlockStatus, BlockSyncRequester, I, M> wh metrics: Option<Metrics>, } -impl<Block, BlockStatus, BlockSyncRequester, I, M> Unpin for UntilImported<Block, BlockStatus, BlockSyncRequester, I, M > where +impl<Block, BlockStatus, BlockSyncRequester, I, M> Unpin + for UntilImported<Block, BlockStatus, BlockSyncRequester, I, M> +where Block: BlockT, I: Stream<Item = M::Blocked> + Unpin, M: BlockUntilImported<Block>, -{} +{ +} -impl<Block, BlockStatus, BlockSyncRequester, I, M> UntilImported<Block, BlockStatus, BlockSyncRequester, I, M> where +impl<Block, BlockStatus, BlockSyncRequester, I, M> + UntilImported<Block, BlockStatus, BlockSyncRequester, I, M> +where Block: BlockT, BlockStatus: BlockStatusT<Block>, BlockSyncRequester: BlockSyncRequesterT<Block>, diff --git a/substrate/client/finality-grandpa/src/voting_rule.rs b/substrate/client/finality-grandpa/src/voting_rule.rs index 3ede7649a138786621c464ac15926f533ecdfd8a..a5515c1be23ed5b19c69acfaef887ec18ac0a05b 100644 --- a/substrate/client/finality-grandpa/src/voting_rule.rs +++ b/substrate/client/finality-grandpa/src/voting_rule.rs @@ -34,10 +34,11 @@ use sp_runtime::traits::{Block as BlockT, Header, NumberFor, One, Zero}; /// A future returned by a `VotingRule` to restrict a given vote, if any restriction is necessary. pub type VotingRuleResult<Block> = - Pin<Box<dyn Future<Output = Option<(<Block as BlockT>::Hash, NumberFor<Block>)>> + Send + Sync>>; + Pin<Box<dyn Future<Output = Option<(<Block as BlockT>::Hash, NumberFor<Block>)>> + Send>>; /// A trait for custom voting rules in GRANDPA. -pub trait VotingRule<Block, B>: DynClone + Send + Sync where +pub trait VotingRule<Block, B>: DynClone + Send + Sync +where Block: BlockT, B: HeaderBackend<Block>, { diff --git a/substrate/frame/grandpa/Cargo.toml b/substrate/frame/grandpa/Cargo.toml index c6cfa96f7da1b3ff447341065816201b52ef4875..5c3cac8f82182d8281d10a2efeafe0618c39c734 100644 --- a/substrate/frame/grandpa/Cargo.toml +++ b/substrate/frame/grandpa/Cargo.toml @@ -31,7 +31,7 @@ log = { version = "0.4.14", default-features = false } [dev-dependencies] frame-benchmarking = { version = "3.1.0", path = "../benchmarking" } -grandpa = { package = "finality-grandpa", version = "0.14.0", features = ["derive-codec"] } +grandpa = { package = "finality-grandpa", version = "0.14.1", features = ["derive-codec"] } sp-keyring = { version = "3.0.0", path = "../../primitives/keyring" } pallet-balances = { version = "3.0.0", path = "../balances" } pallet-offences = { version = "3.0.0", path = "../offences" } diff --git a/substrate/primitives/finality-grandpa/Cargo.toml b/substrate/primitives/finality-grandpa/Cargo.toml index 95aa65c930f7897d60cb1bc030542918870cd49c..ec9e89105d58106b2333adaa4adf0e7027881c91 100644 --- a/substrate/primitives/finality-grandpa/Cargo.toml +++ b/substrate/primitives/finality-grandpa/Cargo.toml @@ -16,7 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] } -grandpa = { package = "finality-grandpa", version = "0.14.0", default-features = false, features = ["derive-codec"] } +grandpa = { package = "finality-grandpa", version = "0.14.1", default-features = false, features = ["derive-codec"] } log = { version = "0.4.8", optional = true } serde = { version = "1.0.101", optional = true, features = ["derive"] } sp-api = { version = "3.0.0", default-features = false, path = "../api" }