improved gossip topology (#3270)

* gossip-support: gossip topology

* some fixes

* handle view update for newly added gossip peers

* fix neighbors calculation

* fix test

* resolve TODOs

* typo

* guide updates

* spaces in the guide

* sneaky spaces

* hash randomness

* address some review nits

* use unbounded in bridge for subsystem msg
This commit is contained in:
Andronik Ordian
2021-06-18 21:30:35 +02:00
committed by GitHub
parent ae5b355754
commit ad9c02886d
21 changed files with 720 additions and 287 deletions
+9 -1
View File
@@ -22,7 +22,7 @@
//!
//! Subsystems' APIs are defined separately from their implementation, leading to easier mocking.
use std::{collections::btree_map::BTreeMap, sync::Arc};
use std::{collections::{BTreeMap, HashSet}, sync::Arc};
use futures::channel::{mpsc, oneshot};
use thiserror::Error;
@@ -304,6 +304,13 @@ pub enum NetworkBridgeMessage {
/// authority discovery has failed to resolve.
failed: oneshot::Sender<usize>,
},
/// Inform the distribution subsystems about the new
/// gossip network topology formed.
NewGossipTopology {
/// Ids of our neighbors in the new gossip topology.
/// We're not necessarily connected to all of them, but we should.
our_neighbors: HashSet<AuthorityDiscoveryId>,
}
}
impl NetworkBridgeMessage {
@@ -318,6 +325,7 @@ impl NetworkBridgeMessage {
Self::SendCollationMessages(_) => None,
Self::ConnectToValidators { .. } => None,
Self::SendRequests { .. } => None,
Self::NewGossipTopology { .. } => None,
}
}
}
@@ -15,6 +15,7 @@
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
use std::convert::TryFrom;
use std::collections::HashSet;
pub use sc_network::{ReputationChange, PeerId};
@@ -30,6 +31,15 @@ pub enum NetworkBridgeEvent<M> {
/// A peer has disconnected.
PeerDisconnected(PeerId),
/// Our neighbors in the new gossip topology.
/// We're not necessarily connected to all of them.
///
/// This message is issued only on the validation peer set.
///
/// Note, that the distribution subsystems need to handle the last
/// view update of the newly added gossip peers manually.
NewGossipTopology(HashSet<PeerId>),
/// Peer has sent a message.
PeerMessage(PeerId, M),
@@ -64,6 +74,8 @@ impl<M> NetworkBridgeEvent<M> {
=> NetworkBridgeEvent::PeerConnected(peer.clone(), role.clone(), authority_id.clone()),
NetworkBridgeEvent::PeerDisconnected(ref peer)
=> NetworkBridgeEvent::PeerDisconnected(peer.clone()),
NetworkBridgeEvent::NewGossipTopology(ref peers)
=> NetworkBridgeEvent::NewGossipTopology(peers.clone()),
NetworkBridgeEvent::PeerMessage(ref peer, ref msg)
=> NetworkBridgeEvent::PeerMessage(peer.clone(), <&'a T>::try_from(msg)?.clone()),
NetworkBridgeEvent::PeerViewChange(ref peer, ref view)