mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 15:47:58 +00:00
Introduce PerPeerSet utility that allows to segrate based on PeerSet (#2420)
* Introduce PerPeerSet utility that allows to segrate based on PeerSet * Remove `repr(usize)` from PeerSet
This commit is contained in:
@@ -17,18 +17,17 @@
|
||||
//! All peersets and protocols used for parachains.
|
||||
|
||||
use sc_network::config::{NonDefaultSetConfig, SetConfig};
|
||||
use std::borrow::Cow;
|
||||
use std::{borrow::Cow, ops::{Index, IndexMut}};
|
||||
use strum::{EnumIter, IntoEnumIterator};
|
||||
|
||||
/// The peer-sets and thus the protocols which are used for the network.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EnumIter)]
|
||||
#[repr(usize)]
|
||||
pub enum PeerSet {
|
||||
/// The validation peer-set is responsible for all messages related to candidate validation and
|
||||
/// communication among validators.
|
||||
Validation = 0,
|
||||
Validation,
|
||||
/// The collation peer-set is used for validator<>collator communication.
|
||||
Collation = 1,
|
||||
Collation,
|
||||
}
|
||||
|
||||
impl PeerSet {
|
||||
@@ -89,6 +88,32 @@ impl PeerSet {
|
||||
}
|
||||
}
|
||||
|
||||
/// A small and nifty collection that allows to store data pertaining to each peer set.
|
||||
#[derive(Debug, Default)]
|
||||
pub struct PerPeerSet<T> {
|
||||
validation: T,
|
||||
collation: T,
|
||||
}
|
||||
|
||||
impl<T> Index<PeerSet> for PerPeerSet<T> {
|
||||
type Output = T;
|
||||
fn index(&self, index: PeerSet) -> &T {
|
||||
match index {
|
||||
PeerSet::Validation => &self.validation,
|
||||
PeerSet::Collation => &self.collation,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> IndexMut<PeerSet> for PerPeerSet<T> {
|
||||
fn index_mut(&mut self, index: PeerSet) -> &mut T {
|
||||
match index {
|
||||
PeerSet::Validation => &mut self.validation,
|
||||
PeerSet::Collation => &mut self.collation,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Get `NonDefaultSetConfig`s for all available peer sets.
|
||||
///
|
||||
/// Should be used during network configuration (added to [`NetworkConfiguration::extra_sets`])
|
||||
|
||||
Reference in New Issue
Block a user