mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 01:11:10 +00:00
Prepare for network protocol version upgrades (#5084)
* explicitly tag network requests with version * fmt * make PeerSet more aware of versioning * some generalization of the network bridge to support upgrades * walk back some renaming * walk back some version stuff * extract version from fallback * remove V1 from NetworkBridgeUpdate * add accidentally-removed timer * implement focusing for versioned messages * fmt * fix up network bridge & tests * remove inaccurate version check in bridge * remove some TODO [now]s * fix fallout in statement distribution * fmt * fallout in gossip-support * fix fallout in collator-protocol * fix fallout in bitfield-distribution * fix fallout in approval-distribution * fmt * use never! * fmt
This commit is contained in:
@@ -29,7 +29,7 @@ use thiserror::Error;
|
||||
pub use sc_network::IfDisconnected;
|
||||
|
||||
use polkadot_node_network_protocol::{
|
||||
peer_set::PeerSet, request_response::Requests, v1 as protocol_v1, PeerId,
|
||||
self as net_protocol, peer_set::PeerSet, request_response::Requests, PeerId,
|
||||
UnifiedReputationChange,
|
||||
};
|
||||
use polkadot_node_primitives::{
|
||||
@@ -201,7 +201,7 @@ pub enum CollatorProtocolMessage {
|
||||
ReportCollator(CollatorId),
|
||||
/// Get a network bridge update.
|
||||
#[from]
|
||||
NetworkBridgeUpdateV1(NetworkBridgeEvent<protocol_v1::CollatorProtocolMessage>),
|
||||
NetworkBridgeUpdate(NetworkBridgeEvent<net_protocol::CollatorProtocolMessage>),
|
||||
/// We recommended a particular candidate to be seconded, but it was invalid; penalize the collator.
|
||||
///
|
||||
/// The hash is the relay parent.
|
||||
@@ -328,20 +328,20 @@ pub enum NetworkBridgeMessage {
|
||||
DisconnectPeer(PeerId, PeerSet),
|
||||
|
||||
/// Send a message to one or more peers on the validation peer-set.
|
||||
SendValidationMessage(Vec<PeerId>, protocol_v1::ValidationProtocol),
|
||||
SendValidationMessage(Vec<PeerId>, net_protocol::VersionedValidationProtocol),
|
||||
|
||||
/// Send a message to one or more peers on the collation peer-set.
|
||||
SendCollationMessage(Vec<PeerId>, protocol_v1::CollationProtocol),
|
||||
SendCollationMessage(Vec<PeerId>, net_protocol::VersionedCollationProtocol),
|
||||
|
||||
/// Send a batch of validation messages.
|
||||
///
|
||||
/// NOTE: Messages will be processed in order (at least statement distribution relies on this).
|
||||
SendValidationMessages(Vec<(Vec<PeerId>, protocol_v1::ValidationProtocol)>),
|
||||
SendValidationMessages(Vec<(Vec<PeerId>, net_protocol::VersionedValidationProtocol)>),
|
||||
|
||||
/// Send a batch of collation messages.
|
||||
///
|
||||
/// NOTE: Messages will be processed in order.
|
||||
SendCollationMessages(Vec<(Vec<PeerId>, protocol_v1::CollationProtocol)>),
|
||||
SendCollationMessages(Vec<(Vec<PeerId>, net_protocol::VersionedCollationProtocol)>),
|
||||
|
||||
/// Send requests via substrate request/response.
|
||||
/// Second parameter, tells what to do if we are not yet connected to the peer.
|
||||
@@ -455,7 +455,7 @@ pub enum BitfieldDistributionMessage {
|
||||
|
||||
/// Event from the network bridge.
|
||||
#[from]
|
||||
NetworkBridgeUpdateV1(NetworkBridgeEvent<protocol_v1::BitfieldDistributionMessage>),
|
||||
NetworkBridgeUpdate(NetworkBridgeEvent<net_protocol::BitfieldDistributionMessage>),
|
||||
}
|
||||
|
||||
impl BitfieldDistributionMessage {
|
||||
@@ -463,7 +463,7 @@ impl BitfieldDistributionMessage {
|
||||
pub fn relay_parent(&self) -> Option<Hash> {
|
||||
match self {
|
||||
Self::DistributeBitfield(hash, _) => Some(*hash),
|
||||
Self::NetworkBridgeUpdateV1(_) => None,
|
||||
Self::NetworkBridgeUpdate(_) => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -719,7 +719,7 @@ pub enum StatementDistributionMessage {
|
||||
Share(Hash, SignedFullStatement),
|
||||
/// Event from the network bridge.
|
||||
#[from]
|
||||
NetworkBridgeUpdateV1(NetworkBridgeEvent<protocol_v1::StatementDistributionMessage>),
|
||||
NetworkBridgeUpdate(NetworkBridgeEvent<net_protocol::StatementDistributionMessage>),
|
||||
}
|
||||
|
||||
/// This data becomes intrinsics or extrinsics which should be included in a future relay chain block.
|
||||
@@ -913,7 +913,7 @@ pub enum ApprovalDistributionMessage {
|
||||
DistributeApproval(IndirectSignedApprovalVote),
|
||||
/// An update from the network bridge.
|
||||
#[from]
|
||||
NetworkBridgeUpdateV1(NetworkBridgeEvent<protocol_v1::ApprovalDistributionMessage>),
|
||||
NetworkBridgeUpdate(NetworkBridgeEvent<net_protocol::ApprovalDistributionMessage>),
|
||||
}
|
||||
|
||||
/// Message to the Gossip Support subsystem.
|
||||
@@ -921,7 +921,7 @@ pub enum ApprovalDistributionMessage {
|
||||
pub enum GossipSupportMessage {
|
||||
/// Dummy constructor, so we can receive networking events.
|
||||
#[from]
|
||||
NetworkBridgeUpdateV1(NetworkBridgeEvent<protocol_v1::GossipSuppportNetworkMessage>),
|
||||
NetworkBridgeUpdate(NetworkBridgeEvent<net_protocol::GossipSupportNetworkMessage>),
|
||||
}
|
||||
|
||||
/// PVF checker message.
|
||||
|
||||
@@ -21,7 +21,7 @@ use std::{
|
||||
|
||||
pub use sc_network::{PeerId, ReputationChange};
|
||||
|
||||
use polkadot_node_network_protocol::{ObservedRole, OurView, View, WrongVariant};
|
||||
use polkadot_node_network_protocol::{ObservedRole, OurView, ProtocolVersion, View, WrongVariant};
|
||||
use polkadot_primitives::v2::{AuthorityDiscoveryId, SessionIndex, ValidatorIndex};
|
||||
|
||||
/// Information about a peer in the gossip topology for a session.
|
||||
@@ -49,7 +49,7 @@ pub struct NewGossipTopology {
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum NetworkBridgeEvent<M> {
|
||||
/// A peer has connected.
|
||||
PeerConnected(PeerId, ObservedRole, Option<HashSet<AuthorityDiscoveryId>>),
|
||||
PeerConnected(PeerId, ObservedRole, ProtocolVersion, Option<HashSet<AuthorityDiscoveryId>>),
|
||||
|
||||
/// A peer has disconnected.
|
||||
PeerDisconnected(PeerId),
|
||||
@@ -92,13 +92,22 @@ impl<M> NetworkBridgeEvent<M> {
|
||||
pub fn focus<'a, T>(&'a self) -> Result<NetworkBridgeEvent<T>, WrongVariant>
|
||||
where
|
||||
T: 'a + Clone,
|
||||
&'a T: TryFrom<&'a M, Error = WrongVariant>,
|
||||
T: TryFrom<&'a M, Error = WrongVariant>,
|
||||
{
|
||||
Ok(match *self {
|
||||
NetworkBridgeEvent::PeerMessage(ref peer, ref msg) =>
|
||||
NetworkBridgeEvent::PeerMessage(peer.clone(), <&'a T>::try_from(msg)?.clone()),
|
||||
NetworkBridgeEvent::PeerConnected(ref peer, ref role, ref authority_id) =>
|
||||
NetworkBridgeEvent::PeerConnected(peer.clone(), role.clone(), authority_id.clone()),
|
||||
NetworkBridgeEvent::PeerMessage(peer.clone(), T::try_from(msg)?),
|
||||
NetworkBridgeEvent::PeerConnected(
|
||||
ref peer,
|
||||
ref role,
|
||||
ref version,
|
||||
ref authority_id,
|
||||
) => NetworkBridgeEvent::PeerConnected(
|
||||
peer.clone(),
|
||||
role.clone(),
|
||||
*version,
|
||||
authority_id.clone(),
|
||||
),
|
||||
NetworkBridgeEvent::PeerDisconnected(ref peer) =>
|
||||
NetworkBridgeEvent::PeerDisconnected(peer.clone()),
|
||||
NetworkBridgeEvent::NewGossipTopology(ref topology) =>
|
||||
|
||||
Reference in New Issue
Block a user