mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 16:57:58 +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:
@@ -89,36 +89,6 @@ impl Into<sc_network::ObservedRole> for ObservedRole {
|
||||
}
|
||||
}
|
||||
|
||||
/// Implement `TryFrom` for one enum variant into the inner type.
|
||||
/// `$m_ty::$variant(inner) -> Ok(inner)`
|
||||
macro_rules! impl_try_from {
|
||||
($m_ty:ident, $variant:ident, $out:ty) => {
|
||||
impl TryFrom<$m_ty> for $out {
|
||||
type Error = crate::WrongVariant;
|
||||
|
||||
fn try_from(x: $m_ty) -> Result<$out, Self::Error> {
|
||||
#[allow(unreachable_patterns)] // when there is only one variant
|
||||
match x {
|
||||
$m_ty::$variant(y) => Ok(y),
|
||||
_ => Err(crate::WrongVariant),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<&'a $m_ty> for &'a $out {
|
||||
type Error = crate::WrongVariant;
|
||||
|
||||
fn try_from(x: &'a $m_ty) -> Result<&'a $out, Self::Error> {
|
||||
#[allow(unreachable_patterns)] // when there is only one variant
|
||||
match *x {
|
||||
$m_ty::$variant(ref y) => Ok(y),
|
||||
_ => Err(crate::WrongVariant),
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// Specialized wrapper around [`View`].
|
||||
///
|
||||
/// Besides the access to the view itself, it also gives access to the [`jaeger::Span`] per leave/head.
|
||||
@@ -279,7 +249,152 @@ impl View {
|
||||
}
|
||||
}
|
||||
|
||||
/// v1 protocol types.
|
||||
/// A protocol-versioned type.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum Versioned<V1> {
|
||||
/// V1 type.
|
||||
V1(V1),
|
||||
}
|
||||
|
||||
impl<V1: Clone> Versioned<&'_ V1> {
|
||||
/// Convert to a fully-owned version of the message.
|
||||
pub fn clone_inner(&self) -> Versioned<V1> {
|
||||
match *self {
|
||||
Versioned::V1(inner) => Versioned::V1(inner.clone()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// All supported versions of the validation protocol message.
|
||||
pub type VersionedValidationProtocol = Versioned<v1::ValidationProtocol>;
|
||||
|
||||
impl From<v1::ValidationProtocol> for VersionedValidationProtocol {
|
||||
fn from(v1: v1::ValidationProtocol) -> Self {
|
||||
VersionedValidationProtocol::V1(v1)
|
||||
}
|
||||
}
|
||||
|
||||
/// All supported versions of the collation protocol message.
|
||||
pub type VersionedCollationProtocol = Versioned<v1::CollationProtocol>;
|
||||
|
||||
impl From<v1::CollationProtocol> for VersionedCollationProtocol {
|
||||
fn from(v1: v1::CollationProtocol) -> Self {
|
||||
VersionedCollationProtocol::V1(v1)
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! impl_versioned_full_protocol_from {
|
||||
($from:ty, $out:ty, $variant:ident) => {
|
||||
impl From<$from> for $out {
|
||||
fn from(versioned_from: $from) -> $out {
|
||||
match versioned_from {
|
||||
Versioned::V1(x) => Versioned::V1(x.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// Implement `TryFrom` for one versioned enum variant into the inner type.
|
||||
/// `$m_ty::$variant(inner) -> Ok(inner)`
|
||||
macro_rules! impl_versioned_try_from {
|
||||
($from:ty, $out:ty, $v1_pat:pat => $v1_out:expr) => {
|
||||
impl TryFrom<$from> for $out {
|
||||
type Error = crate::WrongVariant;
|
||||
|
||||
fn try_from(x: $from) -> Result<$out, Self::Error> {
|
||||
#[allow(unreachable_patterns)] // when there is only one variant
|
||||
match x {
|
||||
Versioned::V1($v1_pat) => Ok(Versioned::V1($v1_out)),
|
||||
_ => Err(crate::WrongVariant),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<&'a $from> for $out {
|
||||
type Error = crate::WrongVariant;
|
||||
|
||||
fn try_from(x: &'a $from) -> Result<$out, Self::Error> {
|
||||
#[allow(unreachable_patterns)] // when there is only one variant
|
||||
match x {
|
||||
Versioned::V1($v1_pat) => Ok(Versioned::V1($v1_out.clone())),
|
||||
_ => Err(crate::WrongVariant),
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// Version-annotated messages used by the bitfield distribution subsystem.
|
||||
pub type BitfieldDistributionMessage = Versioned<v1::BitfieldDistributionMessage>;
|
||||
impl_versioned_full_protocol_from!(
|
||||
BitfieldDistributionMessage,
|
||||
VersionedValidationProtocol,
|
||||
BitfieldDistribution
|
||||
);
|
||||
impl_versioned_try_from!(
|
||||
VersionedValidationProtocol,
|
||||
BitfieldDistributionMessage,
|
||||
v1::ValidationProtocol::BitfieldDistribution(x) => x
|
||||
);
|
||||
|
||||
/// Version-annotated messages used by the statement distribution subsystem.
|
||||
pub type StatementDistributionMessage = Versioned<v1::StatementDistributionMessage>;
|
||||
impl_versioned_full_protocol_from!(
|
||||
StatementDistributionMessage,
|
||||
VersionedValidationProtocol,
|
||||
StatementDistribution
|
||||
);
|
||||
impl_versioned_try_from!(
|
||||
VersionedValidationProtocol,
|
||||
StatementDistributionMessage,
|
||||
v1::ValidationProtocol::StatementDistribution(x) => x
|
||||
);
|
||||
|
||||
/// Version-annotated messages used by the approval distribution subsystem.
|
||||
pub type ApprovalDistributionMessage = Versioned<v1::ApprovalDistributionMessage>;
|
||||
impl_versioned_full_protocol_from!(
|
||||
ApprovalDistributionMessage,
|
||||
VersionedValidationProtocol,
|
||||
ApprovalDistribution
|
||||
);
|
||||
impl_versioned_try_from!(
|
||||
VersionedValidationProtocol,
|
||||
ApprovalDistributionMessage,
|
||||
v1::ValidationProtocol::ApprovalDistribution(x) => x
|
||||
);
|
||||
|
||||
/// Version-annotated messages used by the gossip-support subsystem (this is void).
|
||||
pub type GossipSupportNetworkMessage = Versioned<v1::GossipSupportNetworkMessage>;
|
||||
// This is a void enum placeholder, so never gets sent over the wire.
|
||||
impl TryFrom<VersionedValidationProtocol> for GossipSupportNetworkMessage {
|
||||
type Error = WrongVariant;
|
||||
fn try_from(_: VersionedValidationProtocol) -> Result<Self, Self::Error> {
|
||||
Err(WrongVariant)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<&'a VersionedValidationProtocol> for GossipSupportNetworkMessage {
|
||||
type Error = WrongVariant;
|
||||
fn try_from(_: &'a VersionedValidationProtocol) -> Result<Self, Self::Error> {
|
||||
Err(WrongVariant)
|
||||
}
|
||||
}
|
||||
|
||||
/// Version-annotated messages used by the bitfield distribution subsystem.
|
||||
pub type CollatorProtocolMessage = Versioned<v1::CollatorProtocolMessage>;
|
||||
impl_versioned_full_protocol_from!(
|
||||
CollatorProtocolMessage,
|
||||
VersionedCollationProtocol,
|
||||
CollatorProtocol
|
||||
);
|
||||
impl_versioned_try_from!(
|
||||
VersionedCollationProtocol,
|
||||
CollatorProtocolMessage,
|
||||
v1::CollationProtocol::CollatorProtocol(x) => x
|
||||
);
|
||||
|
||||
/// v1 notification protocol types.
|
||||
pub mod v1 {
|
||||
use parity_scale_codec::{Decode, Encode};
|
||||
|
||||
@@ -293,8 +408,6 @@ pub mod v1 {
|
||||
UncheckedSignedFullStatement,
|
||||
};
|
||||
|
||||
use crate::WrongVariant;
|
||||
|
||||
/// Network messages used by the bitfield distribution subsystem.
|
||||
#[derive(Debug, Clone, Encode, Decode, PartialEq, Eq)]
|
||||
pub enum BitfieldDistributionMessage {
|
||||
@@ -384,7 +497,7 @@ pub mod v1 {
|
||||
|
||||
/// Dummy network message type, so we will receive connect/disconnect events.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum GossipSuppportNetworkMessage {}
|
||||
pub enum GossipSupportNetworkMessage {}
|
||||
|
||||
/// Network messages used by the collator protocol subsystem
|
||||
#[derive(Debug, Clone, Encode, Decode, PartialEq, Eq)]
|
||||
@@ -403,47 +516,31 @@ pub mod v1 {
|
||||
}
|
||||
|
||||
/// All network messages on the validation peer-set.
|
||||
#[derive(Debug, Clone, Encode, Decode, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, Encode, Decode, PartialEq, Eq, derive_more::From)]
|
||||
pub enum ValidationProtocol {
|
||||
/// Bitfield distribution messages
|
||||
#[codec(index = 1)]
|
||||
#[from]
|
||||
BitfieldDistribution(BitfieldDistributionMessage),
|
||||
/// Statement distribution messages
|
||||
#[codec(index = 3)]
|
||||
#[from]
|
||||
StatementDistribution(StatementDistributionMessage),
|
||||
/// Approval distribution messages
|
||||
#[codec(index = 4)]
|
||||
#[from]
|
||||
ApprovalDistribution(ApprovalDistributionMessage),
|
||||
}
|
||||
|
||||
impl_try_from!(ValidationProtocol, BitfieldDistribution, BitfieldDistributionMessage);
|
||||
impl_try_from!(ValidationProtocol, StatementDistribution, StatementDistributionMessage);
|
||||
impl_try_from!(ValidationProtocol, ApprovalDistribution, ApprovalDistributionMessage);
|
||||
|
||||
impl TryFrom<ValidationProtocol> for GossipSuppportNetworkMessage {
|
||||
type Error = WrongVariant;
|
||||
fn try_from(_: ValidationProtocol) -> Result<Self, Self::Error> {
|
||||
Err(WrongVariant)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<&'a ValidationProtocol> for &'a GossipSuppportNetworkMessage {
|
||||
type Error = WrongVariant;
|
||||
fn try_from(_: &'a ValidationProtocol) -> Result<Self, Self::Error> {
|
||||
Err(WrongVariant)
|
||||
}
|
||||
}
|
||||
|
||||
/// All network messages on the collation peer-set.
|
||||
#[derive(Debug, Clone, Encode, Decode, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, Encode, Decode, PartialEq, Eq, derive_more::From)]
|
||||
pub enum CollationProtocol {
|
||||
/// Collator protocol messages
|
||||
#[codec(index = 0)]
|
||||
#[from]
|
||||
CollatorProtocol(CollatorProtocolMessage),
|
||||
}
|
||||
|
||||
impl_try_from!(CollationProtocol, CollatorProtocol, CollatorProtocolMessage);
|
||||
|
||||
/// Get the payload that should be signed and included in a `Declare` message.
|
||||
///
|
||||
/// The payload is the local peer id of the node, which serves to prove that it
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
//! All peersets and protocols used for parachains.
|
||||
|
||||
use super::ProtocolVersion;
|
||||
use sc_network::config::{NonDefaultSetConfig, SetConfig};
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
@@ -23,6 +24,16 @@ use std::{
|
||||
};
|
||||
use strum::{EnumIter, IntoEnumIterator};
|
||||
|
||||
// Only supported protocol versions should be defined here.
|
||||
const VALIDATION_PROTOCOL_V1: &str = "/polkadot/validation/1";
|
||||
const COLLATION_PROTOCOL_V1: &str = "/polkadot/collation/1";
|
||||
|
||||
/// The default validation protocol version.
|
||||
pub const DEFAULT_VALIDATION_PROTOCOL_VERSION: ProtocolVersion = 1;
|
||||
|
||||
/// The default collation protocol version.
|
||||
pub const DEFAULT_COLLATION_PROTOCOL_VERSION: ProtocolVersion = 1;
|
||||
|
||||
/// The peer-sets and thus the protocols which are used for the network.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EnumIter)]
|
||||
pub enum PeerSet {
|
||||
@@ -45,12 +56,15 @@ pub enum IsAuthority {
|
||||
}
|
||||
|
||||
impl PeerSet {
|
||||
/// Get `sc_network` peer set configurations for each peerset.
|
||||
/// Get `sc_network` peer set configurations for each peerset on the default version.
|
||||
///
|
||||
/// Those should be used in the network configuration to register the protocols with the
|
||||
/// network service.
|
||||
pub fn get_info(self, is_authority: IsAuthority) -> NonDefaultSetConfig {
|
||||
let protocol = self.into_protocol_name();
|
||||
let version = self.get_default_version();
|
||||
let protocol = self
|
||||
.into_protocol_name(version)
|
||||
.expect("default version always has protocol name; qed");
|
||||
let max_notification_size = 100 * 1024;
|
||||
|
||||
match self {
|
||||
@@ -88,24 +102,50 @@ impl PeerSet {
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the protocol name associated with each peer set as static str.
|
||||
pub const fn get_protocol_name_static(self) -> &'static str {
|
||||
/// Get the default protocol version for this peer set.
|
||||
pub const fn get_default_version(self) -> ProtocolVersion {
|
||||
match self {
|
||||
PeerSet::Validation => "/polkadot/validation/1",
|
||||
PeerSet::Collation => "/polkadot/collation/1",
|
||||
PeerSet::Validation => DEFAULT_VALIDATION_PROTOCOL_VERSION,
|
||||
PeerSet::Collation => DEFAULT_COLLATION_PROTOCOL_VERSION,
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert a peer set into a protocol name as understood by Substrate.
|
||||
pub fn into_protocol_name(self) -> Cow<'static, str> {
|
||||
self.get_protocol_name_static().into()
|
||||
/// Get the default protocol name as a static str.
|
||||
pub const fn get_default_protocol_name(self) -> &'static str {
|
||||
match self {
|
||||
PeerSet::Validation => VALIDATION_PROTOCOL_V1,
|
||||
PeerSet::Collation => COLLATION_PROTOCOL_V1,
|
||||
}
|
||||
}
|
||||
|
||||
/// Try parsing a protocol name into a peer set.
|
||||
pub fn try_from_protocol_name(name: &Cow<'static, str>) -> Option<PeerSet> {
|
||||
/// Get the protocol name associated with each peer set
|
||||
/// and the given version, if any, as static str.
|
||||
pub const fn get_protocol_name_static(self, version: ProtocolVersion) -> Option<&'static str> {
|
||||
match (self, version) {
|
||||
(PeerSet::Validation, 1) => Some(VALIDATION_PROTOCOL_V1),
|
||||
(PeerSet::Collation, 1) => Some(COLLATION_PROTOCOL_V1),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the protocol name associated with each peer set as understood by Substrate.
|
||||
pub fn into_default_protocol_name(self) -> Cow<'static, str> {
|
||||
self.get_default_protocol_name().into()
|
||||
}
|
||||
|
||||
/// Convert a peer set and the given version into a protocol name, if any,
|
||||
/// as understood by Substrate.
|
||||
pub fn into_protocol_name(self, version: ProtocolVersion) -> Option<Cow<'static, str>> {
|
||||
self.get_protocol_name_static(version).map(|n| n.into())
|
||||
}
|
||||
|
||||
/// Try parsing a protocol name into a peer set and protocol version.
|
||||
///
|
||||
/// This only succeeds on supported versions.
|
||||
pub fn try_from_protocol_name(name: &Cow<'static, str>) -> Option<(PeerSet, ProtocolVersion)> {
|
||||
match name {
|
||||
n if n == &PeerSet::Validation.into_protocol_name() => Some(PeerSet::Validation),
|
||||
n if n == &PeerSet::Collation.into_protocol_name() => Some(PeerSet::Collation),
|
||||
n if n == VALIDATION_PROTOCOL_V1 => Some((PeerSet::Validation, 1)),
|
||||
n if n == COLLATION_PROTOCOL_V1 => Some((PeerSet::Collation, 1)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -137,7 +177,7 @@ impl<T> IndexMut<PeerSet> for PerPeerSet<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Get `NonDefaultSetConfig`s for all available peer sets.
|
||||
/// Get `NonDefaultSetConfig`s for all available peer sets, at their default versions.
|
||||
///
|
||||
/// Should be used during network configuration (added to [`NetworkConfiguration::extra_sets`])
|
||||
/// or shortly after startup to register the protocols with the network service.
|
||||
|
||||
@@ -60,17 +60,17 @@ pub mod v1;
|
||||
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, EnumIter)]
|
||||
pub enum Protocol {
|
||||
/// Protocol for chunk fetching, used by availability distribution and availability recovery.
|
||||
ChunkFetching,
|
||||
ChunkFetchingV1,
|
||||
/// Protocol for fetching collations from collators.
|
||||
CollationFetching,
|
||||
CollationFetchingV1,
|
||||
/// Protocol for fetching seconded PoVs from validators of the same group.
|
||||
PoVFetching,
|
||||
PoVFetchingV1,
|
||||
/// Protocol for fetching available data.
|
||||
AvailableDataFetching,
|
||||
AvailableDataFetchingV1,
|
||||
/// Fetching of statements that are too large for gossip.
|
||||
StatementFetching,
|
||||
StatementFetchingV1,
|
||||
/// Sending of dispute statements with application level confirmations.
|
||||
DisputeSending,
|
||||
DisputeSendingV1,
|
||||
}
|
||||
|
||||
/// Minimum bandwidth we expect for validators - 500Mbit/s is the recommendation, so approximately
|
||||
@@ -111,12 +111,12 @@ pub const MAX_PARALLEL_STATEMENT_REQUESTS: u32 = 3;
|
||||
/// Response size limit for responses of POV like data.
|
||||
///
|
||||
/// This is larger than `MAX_POV_SIZE` to account for protocol overhead and for additional data in
|
||||
/// `CollationFetching` or `AvailableDataFetching` for example. We try to err on larger limits here
|
||||
/// `CollationFetchingV1` or `AvailableDataFetchingV1` for example. We try to err on larger limits here
|
||||
/// as a too large limit only allows an attacker to waste our bandwidth some more, a too low limit
|
||||
/// might have more severe effects.
|
||||
const POV_RESPONSE_SIZE: u64 = MAX_POV_SIZE as u64 + 10_000;
|
||||
|
||||
/// Maximum response sizes for `StatementFetching`.
|
||||
/// Maximum response sizes for `StatementFetchingV1`.
|
||||
///
|
||||
/// This is `MAX_CODE_SIZE` plus some additional space for protocol overhead.
|
||||
const STATEMENT_RESPONSE_SIZE: u64 = MAX_CODE_SIZE as u64 + 10_000;
|
||||
@@ -130,7 +130,7 @@ impl Protocol {
|
||||
let p_name = self.into_protocol_name();
|
||||
let (tx, rx) = mpsc::channel(self.get_channel_size());
|
||||
let cfg = match self {
|
||||
Protocol::ChunkFetching => RequestResponseConfig {
|
||||
Protocol::ChunkFetchingV1 => RequestResponseConfig {
|
||||
name: p_name,
|
||||
max_request_size: 1_000,
|
||||
max_response_size: POV_RESPONSE_SIZE as u64 * 3,
|
||||
@@ -138,7 +138,7 @@ impl Protocol {
|
||||
request_timeout: CHUNK_REQUEST_TIMEOUT,
|
||||
inbound_queue: Some(tx),
|
||||
},
|
||||
Protocol::CollationFetching => RequestResponseConfig {
|
||||
Protocol::CollationFetchingV1 => RequestResponseConfig {
|
||||
name: p_name,
|
||||
max_request_size: 1_000,
|
||||
max_response_size: POV_RESPONSE_SIZE,
|
||||
@@ -146,14 +146,14 @@ impl Protocol {
|
||||
request_timeout: POV_REQUEST_TIMEOUT_CONNECTED,
|
||||
inbound_queue: Some(tx),
|
||||
},
|
||||
Protocol::PoVFetching => RequestResponseConfig {
|
||||
Protocol::PoVFetchingV1 => RequestResponseConfig {
|
||||
name: p_name,
|
||||
max_request_size: 1_000,
|
||||
max_response_size: POV_RESPONSE_SIZE,
|
||||
request_timeout: POV_REQUEST_TIMEOUT_CONNECTED,
|
||||
inbound_queue: Some(tx),
|
||||
},
|
||||
Protocol::AvailableDataFetching => RequestResponseConfig {
|
||||
Protocol::AvailableDataFetchingV1 => RequestResponseConfig {
|
||||
name: p_name,
|
||||
max_request_size: 1_000,
|
||||
// Available data size is dominated by the PoV size.
|
||||
@@ -161,7 +161,7 @@ impl Protocol {
|
||||
request_timeout: POV_REQUEST_TIMEOUT_CONNECTED,
|
||||
inbound_queue: Some(tx),
|
||||
},
|
||||
Protocol::StatementFetching => RequestResponseConfig {
|
||||
Protocol::StatementFetchingV1 => RequestResponseConfig {
|
||||
name: p_name,
|
||||
max_request_size: 1_000,
|
||||
// Available data size is dominated code size.
|
||||
@@ -178,7 +178,7 @@ impl Protocol {
|
||||
request_timeout: Duration::from_secs(1),
|
||||
inbound_queue: Some(tx),
|
||||
},
|
||||
Protocol::DisputeSending => RequestResponseConfig {
|
||||
Protocol::DisputeSendingV1 => RequestResponseConfig {
|
||||
name: p_name,
|
||||
max_request_size: 1_000,
|
||||
/// Responses are just confirmation, in essence not even a bit. So 100 seems
|
||||
@@ -201,18 +201,18 @@ impl Protocol {
|
||||
// times (due to network delays), 100 seems big enough to accomodate for "bursts",
|
||||
// assuming we can service requests relatively quickly, which would need to be measured
|
||||
// as well.
|
||||
Protocol::ChunkFetching => 100,
|
||||
Protocol::ChunkFetchingV1 => 100,
|
||||
// 10 seems reasonable, considering group sizes of max 10 validators.
|
||||
Protocol::CollationFetching => 10,
|
||||
Protocol::CollationFetchingV1 => 10,
|
||||
// 10 seems reasonable, considering group sizes of max 10 validators.
|
||||
Protocol::PoVFetching => 10,
|
||||
Protocol::PoVFetchingV1 => 10,
|
||||
// Validators are constantly self-selecting to request available data which may lead
|
||||
// to constant load and occasional burstiness.
|
||||
Protocol::AvailableDataFetching => 100,
|
||||
Protocol::AvailableDataFetchingV1 => 100,
|
||||
// Our queue size approximation is how many blocks of the size of
|
||||
// a runtime we can transfer within a statements timeout, minus the requests we handle
|
||||
// in parallel.
|
||||
Protocol::StatementFetching => {
|
||||
Protocol::StatementFetchingV1 => {
|
||||
// We assume we can utilize up to 70% of the available bandwidth for statements.
|
||||
// This is just a guess/estimate, with the following considerations: If we are
|
||||
// faster than that, queue size will stay low anyway, even if not - requesters will
|
||||
@@ -233,7 +233,7 @@ impl Protocol {
|
||||
// Incoming requests can get bursty, we should also be able to handle them fast on
|
||||
// average, so something in the ballpark of 100 should be fine. Nodes will retry on
|
||||
// failure, so having a good value here is mostly about performance tuning.
|
||||
Protocol::DisputeSending => 100,
|
||||
Protocol::DisputeSendingV1 => 100,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,12 +245,12 @@ impl Protocol {
|
||||
/// Get the protocol name associated with each peer set as static str.
|
||||
pub const fn get_protocol_name_static(self) -> &'static str {
|
||||
match self {
|
||||
Protocol::ChunkFetching => "/polkadot/req_chunk/1",
|
||||
Protocol::CollationFetching => "/polkadot/req_collation/1",
|
||||
Protocol::PoVFetching => "/polkadot/req_pov/1",
|
||||
Protocol::AvailableDataFetching => "/polkadot/req_available_data/1",
|
||||
Protocol::StatementFetching => "/polkadot/req_statement/1",
|
||||
Protocol::DisputeSending => "/polkadot/send_dispute/1",
|
||||
Protocol::ChunkFetchingV1 => "/polkadot/req_chunk/1",
|
||||
Protocol::CollationFetchingV1 => "/polkadot/req_collation/1",
|
||||
Protocol::PoVFetchingV1 => "/polkadot/req_pov/1",
|
||||
Protocol::AvailableDataFetchingV1 => "/polkadot/req_available_data/1",
|
||||
Protocol::StatementFetchingV1 => "/polkadot/req_statement/1",
|
||||
Protocol::DisputeSendingV1 => "/polkadot/send_dispute/1",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,29 +29,29 @@ use super::{v1, IsRequest, Protocol};
|
||||
#[derive(Debug)]
|
||||
pub enum Requests {
|
||||
/// Request an availability chunk from a node.
|
||||
ChunkFetching(OutgoingRequest<v1::ChunkFetchingRequest>),
|
||||
ChunkFetchingV1(OutgoingRequest<v1::ChunkFetchingRequest>),
|
||||
/// Fetch a collation from a collator which previously announced it.
|
||||
CollationFetching(OutgoingRequest<v1::CollationFetchingRequest>),
|
||||
CollationFetchingV1(OutgoingRequest<v1::CollationFetchingRequest>),
|
||||
/// Fetch a PoV from a validator which previously sent out a seconded statement.
|
||||
PoVFetching(OutgoingRequest<v1::PoVFetchingRequest>),
|
||||
PoVFetchingV1(OutgoingRequest<v1::PoVFetchingRequest>),
|
||||
/// Request full available data from a node.
|
||||
AvailableDataFetching(OutgoingRequest<v1::AvailableDataFetchingRequest>),
|
||||
AvailableDataFetchingV1(OutgoingRequest<v1::AvailableDataFetchingRequest>),
|
||||
/// Requests for fetching large statements as part of statement distribution.
|
||||
StatementFetching(OutgoingRequest<v1::StatementFetchingRequest>),
|
||||
StatementFetchingV1(OutgoingRequest<v1::StatementFetchingRequest>),
|
||||
/// Requests for notifying about an ongoing dispute.
|
||||
DisputeSending(OutgoingRequest<v1::DisputeRequest>),
|
||||
DisputeSendingV1(OutgoingRequest<v1::DisputeRequest>),
|
||||
}
|
||||
|
||||
impl Requests {
|
||||
/// Get the protocol this request conforms to.
|
||||
pub fn get_protocol(&self) -> Protocol {
|
||||
match self {
|
||||
Self::ChunkFetching(_) => Protocol::ChunkFetching,
|
||||
Self::CollationFetching(_) => Protocol::CollationFetching,
|
||||
Self::PoVFetching(_) => Protocol::PoVFetching,
|
||||
Self::AvailableDataFetching(_) => Protocol::AvailableDataFetching,
|
||||
Self::StatementFetching(_) => Protocol::StatementFetching,
|
||||
Self::DisputeSending(_) => Protocol::DisputeSending,
|
||||
Self::ChunkFetchingV1(_) => Protocol::ChunkFetchingV1,
|
||||
Self::CollationFetchingV1(_) => Protocol::CollationFetchingV1,
|
||||
Self::PoVFetchingV1(_) => Protocol::PoVFetchingV1,
|
||||
Self::AvailableDataFetchingV1(_) => Protocol::AvailableDataFetchingV1,
|
||||
Self::StatementFetchingV1(_) => Protocol::StatementFetchingV1,
|
||||
Self::DisputeSendingV1(_) => Protocol::DisputeSendingV1,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,12 +64,12 @@ impl Requests {
|
||||
/// contained in the `enum`.
|
||||
pub fn encode_request(self) -> (Protocol, OutgoingRequest<Vec<u8>>) {
|
||||
match self {
|
||||
Self::ChunkFetching(r) => r.encode_request(),
|
||||
Self::CollationFetching(r) => r.encode_request(),
|
||||
Self::PoVFetching(r) => r.encode_request(),
|
||||
Self::AvailableDataFetching(r) => r.encode_request(),
|
||||
Self::StatementFetching(r) => r.encode_request(),
|
||||
Self::DisputeSending(r) => r.encode_request(),
|
||||
Self::ChunkFetchingV1(r) => r.encode_request(),
|
||||
Self::CollationFetchingV1(r) => r.encode_request(),
|
||||
Self::PoVFetchingV1(r) => r.encode_request(),
|
||||
Self::AvailableDataFetchingV1(r) => r.encode_request(),
|
||||
Self::StatementFetchingV1(r) => r.encode_request(),
|
||||
Self::DisputeSendingV1(r) => r.encode_request(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ impl ChunkResponse {
|
||||
|
||||
impl IsRequest for ChunkFetchingRequest {
|
||||
type Response = ChunkFetchingResponse;
|
||||
const PROTOCOL: Protocol = Protocol::ChunkFetching;
|
||||
const PROTOCOL: Protocol = Protocol::ChunkFetchingV1;
|
||||
}
|
||||
|
||||
/// Request the advertised collation at that relay-parent.
|
||||
@@ -107,7 +107,7 @@ pub enum CollationFetchingResponse {
|
||||
|
||||
impl IsRequest for CollationFetchingRequest {
|
||||
type Response = CollationFetchingResponse;
|
||||
const PROTOCOL: Protocol = Protocol::CollationFetching;
|
||||
const PROTOCOL: Protocol = Protocol::CollationFetchingV1;
|
||||
}
|
||||
|
||||
/// Request the advertised collation at that relay-parent.
|
||||
@@ -130,7 +130,7 @@ pub enum PoVFetchingResponse {
|
||||
|
||||
impl IsRequest for PoVFetchingRequest {
|
||||
type Response = PoVFetchingResponse;
|
||||
const PROTOCOL: Protocol = Protocol::PoVFetching;
|
||||
const PROTOCOL: Protocol = Protocol::PoVFetchingV1;
|
||||
}
|
||||
|
||||
/// Request the entire available data for a candidate.
|
||||
@@ -162,7 +162,7 @@ impl From<Option<AvailableData>> for AvailableDataFetchingResponse {
|
||||
|
||||
impl IsRequest for AvailableDataFetchingRequest {
|
||||
type Response = AvailableDataFetchingResponse;
|
||||
const PROTOCOL: Protocol = Protocol::AvailableDataFetching;
|
||||
const PROTOCOL: Protocol = Protocol::AvailableDataFetchingV1;
|
||||
}
|
||||
|
||||
/// Request for fetching a large statement via request/response.
|
||||
@@ -188,7 +188,7 @@ pub enum StatementFetchingResponse {
|
||||
|
||||
impl IsRequest for StatementFetchingRequest {
|
||||
type Response = StatementFetchingResponse;
|
||||
const PROTOCOL: Protocol = Protocol::StatementFetching;
|
||||
const PROTOCOL: Protocol = Protocol::StatementFetchingV1;
|
||||
}
|
||||
|
||||
/// A dispute request.
|
||||
@@ -213,5 +213,5 @@ pub enum DisputeResponse {
|
||||
|
||||
impl IsRequest for DisputeRequest {
|
||||
type Response = DisputeResponse;
|
||||
const PROTOCOL: Protocol = Protocol::DisputeSending;
|
||||
const PROTOCOL: Protocol = Protocol::DisputeSendingV1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user