Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

grandpa: cleanup sync bounds #9127

Merged
3 commits merged into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/finality-grandpa-warp-sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
5 changes: 3 additions & 2 deletions client/finality-grandpa-warp-sync/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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
}
}
Expand Down
4 changes: 2 additions & 2 deletions client/finality-grandpa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ 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"
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" }
Expand Down
2 changes: 1 addition & 1 deletion client/finality-grandpa/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion client/finality-grandpa/src/communication/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl LocalIdKeystore {
}

/// Returns a reference to the keystore.
fn keystore(&self) -> SyncCryptoStorePtr{
fn keystore(&self) -> SyncCryptoStorePtr {
(self.0).1.clone()
}
}
Expand Down
123 changes: 72 additions & 51 deletions client/finality-grandpa/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -624,41 +625,61 @@ 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,
>,
>;

type Id = AuthorityId;
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>>;

Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions client/finality-grandpa/src/finality_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
///
Expand Down Expand Up @@ -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.
Expand Down
Loading