grandpa: cleanup sync bounds (#9127)

* grandpa: cleanup sync bounds

* grandpa: cleanup imports

* remove cargo patch
This commit is contained in:
André Silva
2021-06-16 13:51:09 +01:00
committed by GitHub
parent 5fa96f2ed2
commit ae5cd339b5
16 changed files with 189 additions and 149 deletions
+2 -2
View File
@@ -1679,9 +1679,9 @@ dependencies = [
[[package]] [[package]]
name = "finality-grandpa" name = "finality-grandpa"
version = "0.14.0" version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6447e2f8178843749e8c8003206def83ec124a7859475395777a28b5338647c" checksum = "74a1bfdcc776e63e49f741c7ce6116fa1b887e8ac2e3ccb14dd4aa113e54feb9"
dependencies = [ dependencies = [
"either", "either",
"futures 0.3.15", "futures 0.3.15",
@@ -28,7 +28,7 @@ sp-finality-grandpa = { version = "3.0.0", path = "../../primitives/finality-gra
sp-runtime = { version = "3.0.0", path = "../../primitives/runtime" } sp-runtime = { version = "3.0.0", path = "../../primitives/runtime" }
[dev-dependencies] [dev-dependencies]
finality-grandpa = { version = "0.14.0" } finality-grandpa = { version = "0.14.1" }
rand = "0.8" rand = "0.8"
sc-block-builder = { version = "0.9.0", path = "../block-builder" } sc-block-builder = { version = "0.9.0", path = "../block-builder" }
sp-consensus = { version = "0.9.0", path = "../../primitives/consensus/common" } sp-consensus = { version = "0.9.0", path = "../../primitives/consensus/common" }
@@ -40,7 +40,8 @@ pub fn request_response_config_for_chain<TBlock: BlockT, TBackend: Backend<TBloc
backend: Arc<TBackend>, backend: Arc<TBackend>,
authority_set: SharedAuthoritySet<TBlock::Hash, NumberFor<TBlock>>, authority_set: SharedAuthoritySet<TBlock::Hash, NumberFor<TBlock>>,
) -> RequestResponseConfig ) -> RequestResponseConfig
where NumberFor<TBlock>: sc_finality_grandpa::BlockNumberOps, where
NumberFor<TBlock>: sc_finality_grandpa::BlockNumberOps,
{ {
let protocol_id = config.protocol_id(); let protocol_id = config.protocol_id();
@@ -54,7 +55,7 @@ pub fn request_response_config_for_chain<TBlock: BlockT, TBackend: Backend<TBloc
backend.clone(), backend.clone(),
authority_set, authority_set,
); );
spawn_handle.spawn("grandpa_warp_sync_request_handler", handler.run()); spawn_handle.spawn("grandpa-warp-sync", handler.run());
request_response_config request_response_config
} }
} }
+2 -2
View File
@@ -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" } sp-finality-grandpa = { version = "3.0.0", path = "../../primitives/finality-grandpa" }
prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../utils/prometheus", version = "0.9.0"} prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../utils/prometheus", version = "0.9.0"}
sc-block-builder = { version = "0.9.0", path = "../block-builder" } 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" pin-project = "1.0.4"
linked-hash-map = "0.5.2" linked-hash-map = "0.5.2"
async-trait = "0.1.42" async-trait = "0.1.42"
@@ -52,7 +52,7 @@ wasm-timer = "0.2"
[dev-dependencies] [dev-dependencies]
assert_matches = "1.3.0" 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 = { version = "0.9.0", path = "../network" }
sc-network-test = { version = "0.8.0", path = "../network/test" } sc-network-test = { version = "0.8.0", path = "../network/test" }
sp-keyring = { version = "3.0.0", path = "../../primitives/keyring" } sp-keyring = { version = "3.0.0", path = "../../primitives/keyring" }
@@ -14,7 +14,7 @@ sc-rpc = { version = "3.0.0", path = "../../rpc" }
sp-blockchain = { version = "3.0.0", path = "../../../primitives/blockchain" } sp-blockchain = { version = "3.0.0", path = "../../../primitives/blockchain" }
sp-core = { version = "3.0.0", path = "../../../primitives/core" } sp-core = { version = "3.0.0", path = "../../../primitives/core" }
sp-runtime = { version = "3.0.0", path = "../../../primitives/runtime" } 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 = "15.1.0"
jsonrpc-core-client = "15.1.0" jsonrpc-core-client = "15.1.0"
jsonrpc-derive = "15.1.0" jsonrpc-derive = "15.1.0"
@@ -23,43 +23,42 @@ use std::pin::Pin;
use std::sync::Arc; use std::sync::Arc;
use std::time::Duration; use std::time::Duration;
use finality_grandpa::{
round::State as RoundState, voter, voter_set::VoterSet, BlockNumberOps, Error as GrandpaError,
};
use futures::prelude::*; use futures::prelude::*;
use futures_timer::Delay; use futures_timer::Delay;
use log::{debug, warn}; use log::{debug, warn};
use parity_scale_codec::{Decode, Encode}; use parity_scale_codec::{Decode, Encode};
use parking_lot::RwLock; 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 sc_client_api::{
use finality_grandpa::{ backend::{apply_aux, Backend},
BlockNumberOps, Error as GrandpaError, round::State as RoundState, utils::is_descendent_of,
voter, voter_set::VoterSet,
};
use sp_blockchain::HeaderMetadata;
use sp_runtime::generic::BlockId;
use sp_runtime::traits::{
Block as BlockT, Header as HeaderT, NumberFor, Zero,
}; };
use sc_telemetry::{telemetry, TelemetryHandle, CONSENSUS_DEBUG, CONSENSUS_INFO}; use sc_telemetry::{telemetry, TelemetryHandle, CONSENSUS_DEBUG, CONSENSUS_INFO};
use sp_blockchain::HeaderMetadata;
use sp_consensus::SelectChain;
use sp_finality_grandpa::{
AuthorityId, AuthoritySignature, Equivocation, EquivocationProof, GrandpaApi, RoundNumber,
SetId, GRANDPA_ENGINE_ID,
};
use sp_runtime::generic::BlockId;
use sp_runtime::traits::{Block as BlockT, Header as HeaderT, NumberFor, Zero};
use crate::{ 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, 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< type HistoricalVotes<Block> = finality_grandpa::HistoricalVotes<
<Block as BlockT>::Hash, <Block as BlockT>::Hash,
NumberFor<Block>, NumberFor<Block>,
@@ -480,10 +479,10 @@ impl<BE, Block, C, N, SC, VR> Environment<BE, Block, C, N, SC, VR>
where where
Block: BlockT, Block: BlockT,
BE: Backend<Block>, BE: Backend<Block>,
C: crate::ClientForGrandpa<Block, BE>, C: ClientForGrandpa<Block, BE>,
C::Api: GrandpaApi<Block>, C::Api: GrandpaApi<Block>,
N: NetworkT<Block>, N: NetworkT<Block>,
SC: SelectChain<Block> + 'static, SC: SelectChain<Block>,
{ {
/// Report the given equivocation to the GRANDPA runtime module. This method /// Report the given equivocation to the GRANDPA runtime module. This method
/// generates a session membership proof of the offender and then submits an /// 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> impl<BE, Block, C, N, SC, VR> finality_grandpa::Chain<Block::Hash, NumberFor<Block>>
finality_grandpa::Chain<Block::Hash, NumberFor<Block>>
for Environment<BE, Block, C, N, SC, VR> for Environment<BE, Block, C, N, SC, VR>
where where
Block: 'static, Block: BlockT,
BE: Backend<Block>, BE: Backend<Block>,
C: crate::ClientForGrandpa<Block, BE>, C: ClientForGrandpa<Block, BE>,
N: NetworkT<Block> + 'static + Send, N: NetworkT<Block>,
SC: SelectChain<Block> + 'static, SC: SelectChain<Block>,
VR: VotingRule<Block, C>, VR: VotingRule<Block, C>,
NumberFor<Block>: BlockNumberOps, 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) ancestry(&self.client, base, block)
} }
} }
pub(crate) fn ancestry<Block: BlockT, Client>( pub(crate) fn ancestry<Block: BlockT, Client>(
client: &Arc<Client>, client: &Arc<Client>,
base: Block::Hash, base: Block::Hash,
@@ -624,27 +625,31 @@ where
// skip one because our ancestry is meant to start from the parent of `block`, // skip one because our ancestry is meant to start from the parent of `block`,
// and `tree_route` includes it. // 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> for Environment<B, Block, C, N, SC, VR>
where where
Block: 'static, Block: BlockT,
B: Backend<Block>, B: Backend<Block>,
C: crate::ClientForGrandpa<Block, B> + 'static, C: ClientForGrandpa<Block, B> + 'static,
C::Api: GrandpaApi<Block>, C::Api: GrandpaApi<Block>,
N: NetworkT<Block> + 'static + Send + Sync, N: NetworkT<Block>,
SC: SelectChain<Block> + 'static, SC: SelectChain<Block>,
VR: VotingRule<Block, C>, VR: VotingRule<Block, C>,
NumberFor<Block>: BlockNumberOps, 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< type BestChain = Pin<
Box< Box<
dyn Future<Output = Result<Option<(Block::Hash, NumberFor<Block>)>, Self::Error>> dyn Future<Output = Result<Option<(Block::Hash, NumberFor<Block>)>, Self::Error>>
+ Send + Send,
+ Sync
>, >,
>; >;
@@ -652,13 +657,29 @@ where
type Signature = AuthoritySignature; type Signature = AuthoritySignature;
// regular round message streams // regular round message streams
type In = Pin<Box<dyn Stream< type In = Pin<
Item = Result<::finality_grandpa::SignedMessage<Block::Hash, NumberFor<Block>, Self::Signature, Self::Id>, Self::Error> Box<
> + Send + Sync>>; dyn Stream<
type Out = Pin<Box<dyn Sink< 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>>, ::finality_grandpa::Message<Block::Hash, NumberFor<Block>>,
Error = Self::Error, Error = Self::Error,
> + Send + Sync>>; > + Send,
>,
>;
type Error = CommandOrError<Block::Hash, NumberFor<Block>>; type Error = CommandOrError<Block::Hash, NumberFor<Block>>;
@@ -1223,7 +1244,7 @@ pub(crate) fn finalize_block<BE, Block, Client>(
where where
Block: BlockT, Block: BlockT,
BE: Backend<Block>, 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 // NOTE: lock must be held through writing to DB to avoid race. this lock
// also implicitly synchronizes the check for last finalized number // also implicitly synchronizes the check for last finalized number
@@ -62,9 +62,10 @@ pub struct FinalityProofProvider<BE, Block: BlockT> {
shared_authority_set: Option<SharedAuthoritySet<Block::Hash, NumberFor<Block>>>, shared_authority_set: Option<SharedAuthoritySet<Block::Hash, NumberFor<Block>>>,
} }
impl<B, Block: BlockT> FinalityProofProvider<B, Block> impl<B, Block> FinalityProofProvider<B, Block>
where where
B: Backend<Block> + Send + Sync + 'static, Block: BlockT,
B: Backend<Block>,
{ {
/// Create new finality proof provider using: /// Create new finality proof provider using:
/// ///
@@ -97,7 +98,7 @@ where
impl<B, Block> FinalityProofProvider<B, Block> impl<B, Block> FinalityProofProvider<B, Block>
where where
Block: BlockT, 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 /// Prove finality for the given block number by returning a Justification for the last block of
/// the authority set. /// the authority set.
+32 -31
View File
@@ -16,36 +16,33 @@
// 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 this program. If not, see <https://www.gnu.org/licenses/>. // 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 log::debug;
use parity_scale_codec::Encode; 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_client_api::{backend::Backend, utils::is_descendent_of};
use sc_consensus::shared_data::{SharedDataLocked, SharedDataLockedUpgradable};
use sc_telemetry::TelemetryHandle; use sc_telemetry::TelemetryHandle;
use sp_utils::mpsc::TracingUnboundedSender;
use sp_api::TransactionFor; use sp_api::TransactionFor;
use sc_consensus::shared_data::{SharedDataLockedUpgradable, SharedDataLocked}; use sp_blockchain::{well_known_cache_keys, BlockStatus};
use sp_consensus::{ use sp_consensus::{
BlockImport, Error as ConsensusError, BlockCheckParams, BlockImport, BlockImportParams, BlockOrigin, Error as ConsensusError,
BlockCheckParams, BlockImportParams, BlockOrigin, ImportResult, JustificationImport, ImportResult, JustificationImport, SelectChain,
SelectChain,
}; };
use sp_finality_grandpa::{ConsensusLog, ScheduledChange, SetId, GRANDPA_ENGINE_ID}; use sp_finality_grandpa::{ConsensusLog, ScheduledChange, SetId, GRANDPA_ENGINE_ID};
use sp_runtime::Justification;
use sp_runtime::generic::{BlockId, OpaqueDigestItemId}; use sp_runtime::generic::{BlockId, OpaqueDigestItemId};
use sp_runtime::traits::{ use sp_runtime::traits::{Block as BlockT, DigestFor, Header as HeaderT, NumberFor, Zero};
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::{
use crate::authorities::{AuthoritySet, SharedAuthoritySet, DelayKind, PendingChange}; authorities::{AuthoritySet, DelayKind, PendingChange, SharedAuthoritySet},
use crate::environment::finalize_block; environment::finalize_block,
use crate::justification::GrandpaJustification; justification::GrandpaJustification,
use crate::notification::GrandpaJustificationSender; notification::GrandpaJustificationSender,
use std::marker::PhantomData; ClientForGrandpa, CommandOrError, Error, NewAuthoritySet, VoterCommand,
};
/// A block-import handler for GRANDPA. /// A block-import handler for GRANDPA.
/// ///
@@ -67,8 +64,8 @@ pub struct GrandpaBlockImport<Backend, Block: BlockT, Client, SC> {
_phantom: PhantomData<Backend>, _phantom: PhantomData<Backend>,
} }
impl<Backend, Block: BlockT, Client, SC: Clone> Clone for impl<Backend, Block: BlockT, Client, SC: Clone> Clone
GrandpaBlockImport<Backend, Block, Client, SC> for GrandpaBlockImport<Backend, Block, Client, SC>
{ {
fn clone(&self) -> Self { fn clone(&self) -> Self {
GrandpaBlockImport { GrandpaBlockImport {
@@ -85,11 +82,12 @@ impl<Backend, Block: BlockT, Client, SC: Clone> Clone for
} }
impl<BE, Block: BlockT, Client, SC> JustificationImport<Block> impl<BE, Block: BlockT, Client, SC> JustificationImport<Block>
for GrandpaBlockImport<BE, Block, Client, SC> where for GrandpaBlockImport<BE, Block, Client, SC>
where
NumberFor<Block>: finality_grandpa::BlockNumberOps, NumberFor<Block>: finality_grandpa::BlockNumberOps,
DigestFor<Block>: Encode, DigestFor<Block>: Encode,
BE: Backend<Block>, BE: Backend<Block>,
Client: crate::ClientForGrandpa<Block, BE>, Client: ClientForGrandpa<Block, BE>,
SC: SelectChain<Block>, SC: SelectChain<Block>,
{ {
type Error = ConsensusError; 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)) header.digest().convert_first(|l| l.try_to(id).and_then(filter_log))
} }
impl<BE, Block: BlockT, Client, SC> impl<BE, Block: BlockT, Client, SC> GrandpaBlockImport<BE, Block, Client, SC>
GrandpaBlockImport<BE, Block, Client, SC>
where where
NumberFor<Block>: finality_grandpa::BlockNumberOps, NumberFor<Block>: finality_grandpa::BlockNumberOps,
DigestFor<Block>: Encode, DigestFor<Block>: Encode,
BE: Backend<Block>, BE: Backend<Block>,
Client: crate::ClientForGrandpa<Block, BE>, Client: ClientForGrandpa<Block, BE>,
{ {
// check for a new authority set change. // check for a new authority set change.
fn check_new_change( fn check_new_change(
@@ -416,20 +413,24 @@ where
let just_in_case = just_in_case.map(|(o, i)| (o, i.release_mutex())); 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] #[async_trait::async_trait]
impl<BE, Block: BlockT, Client, SC> BlockImport<Block> impl<BE, Block: BlockT, Client, SC> BlockImport<Block> for GrandpaBlockImport<BE, Block, Client, SC>
for GrandpaBlockImport<BE, Block, Client, SC> where where
NumberFor<Block>: finality_grandpa::BlockNumberOps, NumberFor<Block>: finality_grandpa::BlockNumberOps,
DigestFor<Block>: Encode, DigestFor<Block>: Encode,
BE: Backend<Block>, BE: Backend<Block>,
Client: crate::ClientForGrandpa<Block, BE>, Client: ClientForGrandpa<Block, BE>,
for<'a> &'a Client: for<'a> &'a Client:
BlockImport<Block, Error = ConsensusError, Transaction = TransactionFor<Client, Block>>, BlockImport<Block, Error = ConsensusError, Transaction = TransactionFor<Client, Block>>,
TransactionFor<Client, Block>: Send + 'static, TransactionFor<Client, Block>: 'static,
SC: Send, SC: Send,
{ {
type Error = ConsensusError; type Error = ConsensusError;
@@ -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> impl<BE, Block: BlockT, Client, SC> GrandpaBlockImport<BE, Block, Client, SC>
where where
BE: Backend<Block>, BE: Backend<Block>,
Client: crate::ClientForGrandpa<Block, BE>, Client: ClientForGrandpa<Block, BE>,
NumberFor<Block>: finality_grandpa::BlockNumberOps, NumberFor<Block>: finality_grandpa::BlockNumberOps,
{ {
/// Import a block justification and finalize the block. /// Import a block justification and finalize the block.
+9 -5
View File
@@ -627,13 +627,17 @@ fn global_communication<BE, Block: BlockT, C, N>(
metrics: Option<until_imported::Metrics>, metrics: Option<until_imported::Metrics>,
) -> ( ) -> (
impl Stream< 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< impl Sink<
CommunicationOutH<Block, Block::Hash>, CommunicationOutH<Block, Block::Hash>,
Error = CommandOrError<Block::Hash, NumberFor<Block>>, Error = CommandOrError<Block::Hash, NumberFor<Block>>,
> + Unpin, >,
) where )
where
BE: Backend<Block> + 'static, BE: Backend<Block> + 'static,
C: ClientForGrandpa<Block, BE> + 'static, C: ClientForGrandpa<Block, BE> + 'static,
N: NetworkT<Block>, 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`. /// block import worker that has already been instantiated with `block_import`.
pub fn run_grandpa_voter<Block: BlockT, BE: 'static, C, N, SC, VR>( pub fn run_grandpa_voter<Block: BlockT, BE: 'static, C, N, SC, VR>(
grandpa_params: GrandpaParams<Block, 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 where
Block::Hash: Ord, Block::Hash: Ord,
BE: Backend<Block> + 'static, BE: Backend<Block> + 'static,
N: NetworkT<Block> + Send + Sync + Clone + 'static, N: NetworkT<Block> + Sync + 'static,
SC: SelectChain<Block> + 'static, SC: SelectChain<Block> + 'static,
VR: VotingRule<Block, C> + Clone + 'static, VR: VotingRule<Block, C> + Clone + 'static,
NumberFor<Block>: BlockNumberOps, NumberFor<Block>: BlockNumberOps,
@@ -16,33 +16,33 @@
// 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 this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
use std::marker::{PhantomData, Unpin};
use std::pin::Pin; use std::pin::Pin;
use std::sync::Arc; use std::sync::Arc;
use std::task::{Context, Poll}; use std::task::{Context, Poll};
use finality_grandpa::{voter, voter_set::VoterSet, BlockNumberOps, Error as GrandpaError};
use futures::prelude::*; use futures::prelude::*;
use finality_grandpa::{
BlockNumberOps, Error as GrandpaError, voter, voter_set::VoterSet
};
use log::{debug, info, warn}; use log::{debug, info, warn};
use sp_keystore::SyncCryptoStorePtr;
use sp_consensus::SelectChain;
use sc_client_api::backend::Backend; use sc_client_api::backend::Backend;
use sc_telemetry::TelemetryHandle; use sc_telemetry::TelemetryHandle;
use sp_utils::mpsc::TracingUnboundedReceiver;
use sp_runtime::traits::{NumberFor, Block as BlockT};
use sp_blockchain::HeaderMetadata; 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::{ use crate::{
global_communication, CommandOrError, CommunicationIn, Config, environment, authorities::SharedAuthoritySet,
LinkHalf, Error, aux_schema::PersistentData, VoterCommand, VoterSetState, 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> { struct ObserverChain<'a, Block: BlockT, Client> {
client: &'a Arc<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>> impl<'a, Block, Client> finality_grandpa::Chain<Block::Hash, NumberFor<Block>>
for ObserverChain<'a, Block, Client> where for ObserverChain<'a, Block, Client>
where
Block: BlockT, Block: BlockT,
Client: HeaderMetadata<Block, Error = sp_blockchain::Error>, Client: HeaderMetadata<Block, Error = sp_blockchain::Error>,
NumberFor<Block>: BlockNumberOps, 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) environment::ancestry(&self.client, base, block)
} }
} }
@@ -75,7 +80,7 @@ where
S: Stream<Item = Result<CommunicationIn<Block>, CommandOrError<Block::Hash, NumberFor<Block>>>>, S: Stream<Item = Result<CommunicationIn<Block>, CommandOrError<Block::Hash, NumberFor<Block>>>>,
F: Fn(u64), F: Fn(u64),
BE: Backend<Block>, BE: Backend<Block>,
Client: crate::ClientForGrandpa<Block, BE>, Client: ClientForGrandpa<Block, BE>,
{ {
let authority_set = authority_set.clone(); let authority_set = authority_set.clone();
let client = client.clone(); let client = client.clone();
@@ -160,13 +165,13 @@ pub fn run_grandpa_observer<BE, Block: BlockT, Client, N, SC>(
config: Config, config: Config,
link: LinkHalf<Block, Client, SC>, link: LinkHalf<Block, Client, SC>,
network: N, network: N,
) -> sp_blockchain::Result<impl Future<Output = ()> + Unpin + Send + 'static> ) -> sp_blockchain::Result<impl Future<Output = ()> + Send>
where where
BE: Backend<Block> + Unpin + 'static, BE: Backend<Block> + Unpin + 'static,
N: NetworkT<Block> + Send + Clone + 'static, N: NetworkT<Block>,
SC: SelectChain<Block> + 'static, SC: SelectChain<Block>,
NumberFor<Block>: BlockNumberOps, NumberFor<Block>: BlockNumberOps,
Client: crate::ClientForGrandpa<Block, BE> + 'static, Client: ClientForGrandpa<Block, BE> + 'static,
{ {
let LinkHalf { let LinkHalf {
client, client,
@@ -223,7 +228,7 @@ impl<B, BE, Client, Network> ObserverWork<B, BE, Client, Network>
where where
B: BlockT, B: BlockT,
BE: Backend<B> + 'static, BE: Backend<B> + 'static,
Client: crate::ClientForGrandpa<B, BE> + 'static, Client: ClientForGrandpa<B, BE> + 'static,
Network: NetworkT<B>, Network: NetworkT<B>,
NumberFor<B>: BlockNumberOps, NumberFor<B>: BlockNumberOps,
{ {
@@ -236,7 +241,6 @@ where
justification_sender: Option<GrandpaJustificationSender<B>>, justification_sender: Option<GrandpaJustificationSender<B>>,
telemetry: Option<TelemetryHandle>, telemetry: Option<TelemetryHandle>,
) -> Self { ) -> Self {
let mut work = ObserverWork { let mut work = ObserverWork {
// `observer` is set to a temporary value and replaced below when // `observer` is set to a temporary value and replaced below when
// calling `rebuild_observer`. // calling `rebuild_observer`.
@@ -344,7 +348,7 @@ impl<B, BE, C, N> Future for ObserverWork<B, BE, C, N>
where where
B: BlockT, B: BlockT,
BE: Backend<B> + Unpin + 'static, BE: Backend<B> + Unpin + 'static,
C: crate::ClientForGrandpa<B, BE> + 'static, C: ClientForGrandpa<B, BE> + 'static,
N: NetworkT<B>, N: NetworkT<B>,
NumberFor<B>: BlockNumberOps, NumberFor<B>: BlockNumberOps,
{ {
@@ -1013,7 +1013,7 @@ fn voter_persists_its_votes() {
fn alice_voter2( fn alice_voter2(
peers: &[Ed25519Keyring], peers: &[Ed25519Keyring],
net: Arc<Mutex<GrandpaTestNet>>, net: Arc<Mutex<GrandpaTestNet>>,
) -> impl Future<Output = ()> + Unpin + Send + 'static { ) -> impl Future<Output = ()> + Send {
let (keystore, _) = create_keystore(peers[0]); let (keystore, _) = create_keystore(peers[0]);
let mut net = net.lock(); let mut net = net.lock();
@@ -136,12 +136,14 @@ impl Drop for Metrics {
fn drop(&mut self) { fn drop(&mut self) {
// Reduce the global counter by the amount of messages that were still left in the dropped // Reduce the global counter by the amount of messages that were still left in the dropped
// queue. // 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. /// 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, Block: BlockT,
I: Stream<Item = M::Blocked> + Unpin, I: Stream<Item = M::Blocked> + Unpin,
M: BlockUntilImported<Block>, M: BlockUntilImported<Block>,
@@ -152,7 +154,7 @@ pub(crate) struct UntilImported<Block, BlockStatus, BlockSyncRequester, I, M> wh
incoming_messages: Fuse<I>, incoming_messages: Fuse<I>,
ready: VecDeque<M::Blocked>, ready: VecDeque<M::Blocked>,
/// Interval at which to check status of each awaited block. /// 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 /// Mapping block hashes to their block number, the point in time it was
/// first encountered (Instant) and a list of GRANDPA messages referencing /// first encountered (Instant) and a list of GRANDPA messages referencing
/// the block hash. /// the block hash.
@@ -164,13 +166,18 @@ pub(crate) struct UntilImported<Block, BlockStatus, BlockSyncRequester, I, M> wh
metrics: Option<Metrics>, 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, Block: BlockT,
I: Stream<Item = M::Blocked> + Unpin, I: Stream<Item = M::Blocked> + Unpin,
M: BlockUntilImported<Block>, 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, Block: BlockT,
BlockStatus: BlockStatusT<Block>, BlockStatus: BlockStatusT<Block>,
BlockSyncRequester: BlockSyncRequesterT<Block>, BlockSyncRequester: BlockSyncRequesterT<Block>,
@@ -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. /// A future returned by a `VotingRule` to restrict a given vote, if any restriction is necessary.
pub type VotingRuleResult<Block> = 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. /// 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, Block: BlockT,
B: HeaderBackend<Block>, B: HeaderBackend<Block>,
{ {
+1 -1
View File
@@ -31,7 +31,7 @@ log = { version = "0.4.14", default-features = false }
[dev-dependencies] [dev-dependencies]
frame-benchmarking = { version = "3.1.0", path = "../benchmarking" } 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" } sp-keyring = { version = "3.0.0", path = "../../primitives/keyring" }
pallet-balances = { version = "3.0.0", path = "../balances" } pallet-balances = { version = "3.0.0", path = "../balances" }
pallet-offences = { version = "3.0.0", path = "../offences" } pallet-offences = { version = "3.0.0", path = "../offences" }
@@ -16,7 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies] [dependencies]
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] } 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 } log = { version = "0.4.8", optional = true }
serde = { version = "1.0.101", optional = true, features = ["derive"] } serde = { version = "1.0.101", optional = true, features = ["derive"] }
sp-api = { version = "3.0.0", default-features = false, path = "../api" } sp-api = { version = "3.0.0", default-features = false, path = "../api" }