-
Notifications
You must be signed in to change notification settings - Fork 2.7k
client/finality-grandpa: Reintegrate periodic neighbor packet worker #4631
Changes from 1 commit
030f26f
799356e
5ff36e6
a72797b
01d8d4e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -27,13 +27,18 @@ | |||||
| //! In the future, there will be a fallback for allowing sending the same message | ||||||
| //! under certain conditions that are used to un-stick the protocol. | ||||||
|
|
||||||
| use std::sync::Arc; | ||||||
|
|
||||||
| use futures::{prelude::*, future::Executor as _, sync::mpsc}; | ||||||
| use futures03::{compat::Compat, stream::StreamExt, future::FutureExt as _, future::TryFutureExt as _}; | ||||||
| use futures03::{ | ||||||
| compat::Compat, | ||||||
| stream::StreamExt, | ||||||
| future::{Future as Future03, FutureExt as _, TryFutureExt as _}, | ||||||
| }; | ||||||
| use log::{debug, trace}; | ||||||
| use parking_lot::Mutex; | ||||||
| use std::{pin::Pin, sync::Arc, task::{Context, Poll as Poll03}}; | ||||||
|
|
||||||
| use finality_grandpa::Message::{Prevote, Precommit, PrimaryPropose}; | ||||||
| use finality_grandpa::{voter, voter_set::VoterSet}; | ||||||
| use log::{debug, trace}; | ||||||
| use sc_network::{NetworkService, ReputationChange}; | ||||||
| use sc_network_gossip::{GossipEngine, Network as GossipNetwork}; | ||||||
| use parity_scale_codec::{Encode, Decode}; | ||||||
|
|
@@ -134,7 +139,18 @@ pub(crate) struct NetworkBridge<B: BlockT, N: Network<B>> { | |||||
| service: N, | ||||||
| gossip_engine: GossipEngine<B>, | ||||||
| validator: Arc<GossipValidator<B>>, | ||||||
|
|
||||||
| /// Sender side of the neighbor packet channel. | ||||||
| /// | ||||||
| /// Packets send into this channel are processed by the `NeighborPacketWorker` and passed on to | ||||||
| /// the underlying `GossipEngine`. | ||||||
| neighbor_sender: periodic::NeighborPacketSender<B>, | ||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Happy to do this change, but rather as a follow up to reduce the noise within this pull request. |
||||||
|
|
||||||
| /// `NeighborPacketWorker` processing packets send through the `NeighborPacketSender`. | ||||||
mxinden marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| // | ||||||
| // NetworkBridge is required to be clonable, thus one needs to be able to clone its children, | ||||||
| // thus one has to wrap neighor_packet_worker with an Arc Mutex. | ||||||
| neighbor_packet_worker: Arc<Mutex<periodic::NeighborPacketWorker<B>>>, | ||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, in order to reduce the amount of |
||||||
| } | ||||||
|
|
||||||
| impl<B: BlockT, N: Network<B>> NetworkBridge<B, N> { | ||||||
|
|
@@ -195,14 +211,18 @@ impl<B: BlockT, N: Network<B>> NetworkBridge<B, N> { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| let (rebroadcast_job, neighbor_sender) = periodic::neighbor_packet_worker(gossip_engine.clone()); | ||||||
| let (neighbor_packet_worker, neighbor_packet_sender) = periodic::NeighborPacketWorker::new(); | ||||||
| let reporting_job = report_stream.consume(gossip_engine.clone()); | ||||||
|
|
||||||
| let bridge = NetworkBridge { service, gossip_engine, validator, neighbor_sender }; | ||||||
| let bridge = NetworkBridge { | ||||||
| service, | ||||||
| gossip_engine, | ||||||
| validator, | ||||||
| neighbor_sender: neighbor_packet_sender, | ||||||
| neighbor_packet_worker: Arc::new(Mutex::new(neighbor_packet_worker)), | ||||||
| }; | ||||||
|
|
||||||
| let executor = Compat::new(executor); | ||||||
| executor.execute(Box::new(rebroadcast_job.select(on_exit.clone().map(Ok).compat()).then(|_| Ok(())))) | ||||||
| .expect("failed to spawn grandpa rebroadcast job task"); | ||||||
| executor.execute(Box::new(reporting_job.select(on_exit.clone().map(Ok).compat()).then(|_| Ok(())))) | ||||||
| .expect("failed to spawn grandpa reporting job task"); | ||||||
|
|
||||||
|
|
@@ -391,6 +411,24 @@ impl<B: BlockT, N: Network<B>> NetworkBridge<B, N> { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| impl<B: BlockT, N: Network<B>> Future03 for NetworkBridge<B, N> | ||||||
| where | ||||||
| NumberFor<B>: Unpin, | ||||||
|
||||||
| NumberFor<B>: Unpin, |
You probably have to add impl<B, N> Unpin for NetworkBridge<B, N> {} somewhere instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, thank you and thank you @tomaka ❤️
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -16,21 +16,16 @@ | |||
|
|
||||
| //! Periodic rebroadcast of neighbor packets. | ||||
|
|
||||
| use std::time::{Instant, Duration}; | ||||
|
|
||||
| use parity_scale_codec::Encode; | ||||
| use futures::prelude::*; | ||||
| use futures::sync::mpsc; | ||||
| use futures_timer::Delay; | ||||
| use futures03::future::{FutureExt as _, TryFutureExt as _}; | ||||
| use log::{debug, warn}; | ||||
| use futures03::{channel::mpsc, future::{FutureExt as _}, prelude::*, ready, stream::Stream}; | ||||
| use log::debug; | ||||
| use std::{pin::Pin, task::{Context, Poll}, time::{Instant, Duration}}; | ||||
|
|
||||
| use sc_network::PeerId; | ||||
| use sc_network_gossip::GossipEngine; | ||||
| use sp_runtime::traits::{NumberFor, Block as BlockT}; | ||||
| use super::gossip::{NeighborPacket, GossipMessage}; | ||||
|
|
||||
| // how often to rebroadcast, if no other | ||||
| // How often to rebroadcast, in cases where no new packets are created. | ||||
| const REBROADCAST_AFTER: Duration = Duration::from_secs(2 * 60); | ||||
|
|
||||
| fn rebroadcast_instant() -> Instant { | ||||
|
|
@@ -56,56 +51,62 @@ impl<B: BlockT> NeighborPacketSender<B> { | |||
| } | ||||
| } | ||||
|
|
||||
| /// Does the work of sending neighbor packets, asynchronously. | ||||
| /// | ||||
| /// It may rebroadcast the last neighbor packet periodically when no | ||||
| /// progress is made. | ||||
| pub(super) fn neighbor_packet_worker<B>(net: GossipEngine<B>) -> ( | ||||
| impl Future<Item = (), Error = ()> + Send + 'static, | ||||
| NeighborPacketSender<B>, | ||||
| ) where | ||||
| B: BlockT, | ||||
| pub(super) struct NeighborPacketWorker<B: BlockT> { | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could use a doc-string |
||||
| last: Option<(Vec<PeerId>, NeighborPacket<NumberFor<B>>)>, | ||||
| delay: Delay, | ||||
| rx: mpsc::UnboundedReceiver<(Vec<PeerId>, NeighborPacket<NumberFor<B>>)>, | ||||
| } | ||||
|
|
||||
| impl<B: BlockT> NeighborPacketWorker<B> { | ||||
| pub(super) fn new() -> (Self, NeighborPacketSender<B>){ | ||||
| let (tx, rx) = mpsc::unbounded::<(Vec<PeerId>, NeighborPacket<NumberFor<B>>)>(); | ||||
| let delay = Delay::new(REBROADCAST_AFTER); | ||||
|
|
||||
| (NeighborPacketWorker { | ||||
| last: None, | ||||
| delay, | ||||
| rx, | ||||
| }, NeighborPacketSender(tx)) | ||||
| } | ||||
| } | ||||
|
|
||||
| impl <B: BlockT> Stream for NeighborPacketWorker<B> | ||||
| where | ||||
| NumberFor<B>: Unpin, | ||||
|
||||
| NumberFor<B>: Unpin, |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -551,10 +551,10 @@ pub fn run_grandpa_voter<B, E, Block: BlockT, N, RA, SC, VR, X, Sp>( | |||||
| Block::Hash: Ord, | ||||||
| B: Backend<Block> + 'static, | ||||||
| E: CallExecutor<Block> + Send + Sync + 'static, | ||||||
| N: NetworkT<Block> + Send + Sync + Clone + 'static, | ||||||
| N: NetworkT<Block> + Send + Sync + Clone + Unpin + 'static, | ||||||
|
||||||
| SC: SelectChain<Block> + 'static, | ||||||
| VR: VotingRule<Block, Client<B, E, Block, RA>> + Clone + 'static, | ||||||
| NumberFor<Block>: BlockNumberOps, | ||||||
| NumberFor<Block>: BlockNumberOps + Unpin, | ||||||
|
||||||
| NumberFor<Block>: BlockNumberOps + Unpin, | |
| NumberFor<Block>: BlockNumberOps, |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, you get the idea
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong
Uh oh!
There was an error while loading. Please reload this page.