Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
afdc964
core/finality-grandpa: Pass Grandpa msg sender up to UntilImported
mxinden Oct 8, 2019
61ac9dd
core/finality-grandpa: Track senders to maybe later request blocks
mxinden Oct 8, 2019
ce9db3f
core/finality-grandpa: Make BlockStatus pub only within crate
mxinden Oct 10, 2019
3cd6de0
core/finality-grandpa: Abstract NetworkBridge with BlockSyncRequester
mxinden Oct 10, 2019
fd4800d
core/finality-grandpa: Pass BlockSyncRequester to UntilImported
mxinden Oct 10, 2019
0f82795
core/finality-grandpa: Track block number of pending within UntilImpo…
mxinden Oct 10, 2019
a2f6684
core/finality-grandpa: Request block sync on long wait
mxinden Oct 10, 2019
9f9e15f
core/finality-grandpa: Adjust unit tests to previous changes
mxinden Oct 11, 2019
126c35e
core/finality-grandpa: Fix line length
mxinden Oct 11, 2019
72516c0
core/finality-grandpa: Add comment explaining in & out vote combination
mxinden Oct 15, 2019
3b4adca
core/finality-grandpa: Log after, not before, timeout expired
mxinden Oct 17, 2019
74d6637
core/finality-grandpa: Collect senders as HashSet for deduplication
mxinden Oct 18, 2019
c138cfb
Merge remote-tracking branch 'paritytech/master' into sync_request_in…
mxinden Oct 21, 2019
6a1eec8
Revert "core/finality-grandpa: Track senders to maybe later request b…
mxinden Oct 22, 2019
8e7663c
Revert "core/finality-grandpa: Pass Grandpa msg sender up to UntilImp…
mxinden Oct 22, 2019
0805651
core/network/sync: Ask for block from all peers if none provided
mxinden Oct 22, 2019
6fda6a6
core/network/sync: Request specific fork sync from peers ahead or on par
mxinden Oct 23, 2019
2c5422f
Merge remote-tracking branch 'paritytech/master' into sync_request_in…
mxinden Oct 23, 2019
411e101
grandpa: fix tests
andresilva Oct 23, 2019
6d695d1
grandpa: fix warnings
andresilva Oct 23, 2019
202bced
grandpa: add test for block sync request on until_imported
andresilva Oct 23, 2019
284ad34
grandpa: rename Environment field inner to client
andresilva Oct 23, 2019
f030ec6
grandpa: fix minor nits
andresilva Oct 23, 2019
10790e7
grandpa: minor nits in until_imported
andresilva Oct 23, 2019
3705a2c
grandpa: copy docs for set_sync_fork_request
andresilva Oct 23, 2019
d668931
grandpa: remove stale TODO on UntilImported
andresilva Oct 23, 2019
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
15 changes: 14 additions & 1 deletion core/finality-grandpa/src/communication/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use network::{consensus_gossip as network_gossip, NetworkService};
use network_gossip::ConsensusMessage;
use codec::{Encode, Decode};
use primitives::Pair;
use sr_primitives::traits::{Block as BlockT, Hash as HashT, Header as HeaderT};
use sr_primitives::traits::{Block as BlockT, Hash as HashT, Header as HeaderT, NumberFor};
use substrate_telemetry::{telemetry, CONSENSUS_DEBUG, CONSENSUS_INFO};
use tokio_executor::Executor;

Expand Down Expand Up @@ -128,6 +128,9 @@ pub trait Network<Block: BlockT>: Clone + Send + 'static {

/// Inform peers that a block with given hash should be downloaded.
fn announce(&self, block: Block::Hash, associated_data: Vec<u8>);

/// Configure an explicit fork sync request.
fn set_sync_fork_request(&self, peers: Vec<network::PeerId>, hash: Block::Hash, number: NumberFor<Block>);
}

/// Create a unique topic for a round and set-id combo.
Expand Down Expand Up @@ -209,6 +212,10 @@ impl<B, S, H> Network<B> for Arc<NetworkService<B, S, H>> where
fn announce(&self, block: B::Hash, associated_data: Vec<u8>) {
self.announce_block(block, associated_data)
}

fn set_sync_fork_request(&self, peers: Vec<network::PeerId>, hash: B::Hash, number: NumberFor<B>) {
NetworkService::set_sync_fork_request(self, peers, hash, number)
}
}

/// A stream used by NetworkBridge in its implementation of Network. Given a oneshot that eventually returns a channel
Expand Down Expand Up @@ -458,6 +465,8 @@ impl<B: BlockT, N: Network<B>> NetworkBridge<B, N> {
format!("Failed to receive on unbounded receiver for round {}", round.0)
));

// Combine incoming votes from external Grandpa nodes with outgoing votes from our own Grandpa voter to have a
// single vote-import-pipeline.
let incoming = incoming.select(out_rx);

(incoming, outgoing)
Expand Down Expand Up @@ -504,6 +513,10 @@ impl<B: BlockT, N: Network<B>> NetworkBridge<B, N> {

(incoming, outgoing)
}

pub(crate) fn set_sync_fork_request(&self, peers: Vec<network::PeerId>, hash: B::Hash, number: NumberFor<B>){
self.service.set_sync_fork_request(peers, hash, number)
}
}

fn incoming_global<B: BlockT, N: Network<B>>(
Expand Down
7 changes: 5 additions & 2 deletions core/finality-grandpa/src/communication/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use tokio::runtime::current_thread;
use std::sync::Arc;
use keyring::Ed25519Keyring;
use codec::Encode;
use sr_primitives::traits::NumberFor;

use crate::environment::SharedVoterSetState;
use super::gossip::{self, GossipValidator};
Expand Down Expand Up @@ -91,6 +92,8 @@ impl super::Network<Block> for TestNetwork {
fn announce(&self, block: Hash, _associated_data: Vec<u8>) {
let _ = self.sender.unbounded_send(Event::Announce(block));
}

fn set_sync_fork_request(&self, peers: Vec<network::PeerId>, hash: Hash, number: NumberFor<Block>) {}
}

impl network_gossip::ValidatorContext<Block> for TestNetwork {
Expand Down Expand Up @@ -296,7 +299,7 @@ fn good_commit_leads_to_relay() {
// when the commit comes in, we'll tell the callback it was good.
let handle_commit = commits_in.into_future()
.map(|(item, _)| {
match item.unwrap() {
match item.unwrap().1 {
grandpa::voter::CommunicationIn::Commit(_, _, mut callback) => {
callback.run(grandpa::voter::CommitProcessingOutcome::good());
},
Expand Down Expand Up @@ -411,7 +414,7 @@ fn bad_commit_leads_to_report() {
// when the commit comes in, we'll tell the callback it was good.
let handle_commit = commits_in.into_future()
.map(|(item, _)| {
match item.unwrap() {
match item.unwrap().1 {
grandpa::voter::CommunicationIn::Commit(_, _, mut callback) => {
callback.run(grandpa::voter::CommitProcessingOutcome::bad());
},
Expand Down
3 changes: 3 additions & 0 deletions core/finality-grandpa/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@ impl<Block: BlockT> SharedVoterSetState<Block> {

/// The environment we run GRANDPA in.
pub(crate) struct Environment<B, E, Block: BlockT, N: Network<Block>, RA, SC, VR> {
// TODO: As far as I can tell this does not follow the pattern of having an outer struct protecting an inner struct
// via a lock in order to be Sync. How about renaming this to `client` like we do in many other places?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I did the rename.

pub(crate) inner: Arc<Client<B, E, Block, RA>>,
pub(crate) select_chain: SC,
pub(crate) voters: Arc<VoterSet<AuthorityId>>,
Expand Down Expand Up @@ -602,6 +604,7 @@ where
// corresponding blocks are imported.
let incoming = Box::new(UntilVoteTargetImported::new(
self.inner.import_notification_stream(),
self.network.clone(),
self.inner.clone(),
incoming,
"round",
Expand Down
27 changes: 21 additions & 6 deletions core/finality-grandpa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
//!
//! # Usage
//!
//! First, create a block-import wrapper with the `block_import` function.
//! The GRANDPA worker needs to be linked together with this block import object,
//! so a `LinkHalf` is returned as well. All blocks imported (from network or consensus or otherwise)
//! must pass through this wrapper, otherwise consensus is likely to break in
//! unexpected ways.
//! First, create a block-import wrapper with the `block_import` function. The
//! GRANDPA worker needs to be linked together with this block import object, so
//! a `LinkHalf` is returned as well. All blocks imported (from network or
//! consensus or otherwise) must pass through this wrapper, otherwise consensus
//! is likely to break in unexpected ways.
//!
//! Next, use the `LinkHalf` and a local configuration to `run_grandpa_voter`.
//! This requires a `Network` implementation. The returned future should be
Expand Down Expand Up @@ -242,7 +242,7 @@ impl From<ClientError> for Error {
}

/// Something which can determine if a block is known.
pub trait BlockStatus<Block: BlockT> {
pub(crate) trait BlockStatus<Block: BlockT> {
/// Return `Ok(Some(number))` or `Ok(None)` depending on whether the block
/// is definitely known and has been imported.
/// If an unexpected error occurs, return that.
Expand All @@ -261,6 +261,20 @@ impl<B, E, Block: BlockT<Hash=H256>, RA> BlockStatus<Block> for Arc<Client<B, E,
}
}

/// Something that one can ask to do a block sync request.
pub(crate) trait BlockSyncRequester<Block: BlockT> {
fn set_sync_fork_request(&self, peers: Vec<network::PeerId>, hash: Block::Hash, number: NumberFor<Block>);
}

impl<Block, N> BlockSyncRequester<Block> for NetworkBridge<Block, N> where
Block: BlockT,
N: communication::Network<Block>,
{
fn set_sync_fork_request(&self, peers: Vec<network::PeerId>, hash: Block::Hash, number: NumberFor<Block>){
NetworkBridge::set_sync_fork_request(self, peers, hash, number)
}
}

/// A new authority set along with the canonical block it changed at.
#[derive(Debug)]
pub(crate) struct NewAuthoritySet<H, N> {
Expand Down Expand Up @@ -429,6 +443,7 @@ fn global_communication<Block: BlockT<Hash=H256>, B, E, N, RA>(
// block commit and catch up messages until relevant blocks are imported.
let global_in = UntilGlobalMessageBlocksImported::new(
client.import_notification_stream(),
network.clone(),
client.clone(),
global_in,
"global",
Expand Down
6 changes: 3 additions & 3 deletions core/finality-grandpa/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ fn voter_persists_its_votes() {
runtime.spawn(round_rx.for_each(move |signed| {
if state.compare_and_swap(0, 1, Ordering::SeqCst) == 0 {
// the first message we receive should be a prevote from alice.
let prevote = match signed.message {
let prevote = match signed.1.message {
grandpa::Message::Prevote(prevote) => prevote,
_ => panic!("voter should prevote."),
};
Expand Down Expand Up @@ -1225,7 +1225,7 @@ fn voter_persists_its_votes() {

} else if state.compare_and_swap(1, 2, Ordering::SeqCst) == 1 {
// the next message we receive should be our own prevote
let prevote = match signed.message {
let prevote = match signed.1.message {
grandpa::Message::Prevote(prevote) => prevote,
_ => panic!("We should receive our own prevote."),
};
Expand All @@ -1242,7 +1242,7 @@ fn voter_persists_its_votes() {
} else if state.compare_and_swap(2, 3, Ordering::SeqCst) == 2 {
// we then receive a precommit from alice for block 15
// even though we casted a prevote for block 30
let precommit = match signed.message {
let precommit = match signed.1.message {
grandpa::Message::Precommit(precommit) => precommit,
_ => panic!("voter should precommit."),
};
Expand Down
Loading