mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 12:17:58 +00:00
Get rid of Peerset compatibility layer (#14337)
* Move bootnodes from individual `SetConfig`s to `PeersetConfig` * Move `SetId` & `SetConfig` from `peerset` to `protocol_controller` * Remove unused `DropReason` * Move `Message` & `IncomingIndex` from `peerset` to `protocol_controller` * Restore running fuzz test * Get rid of `Peerset` in `fuzz` test * Spawn runners instead of manual polling in `fuzz` test * Migrate `Protocol` from `Peerset` to `PeerStore` & `ProtocolController` * Migrate `NetworkService` from `Peerset` to `PeerStore` & `ProtocolController` * Migrate `Notifications` from `Peerset` to `ProtocolController`s * Migrate `Notifications` tests from `Peerset` to `ProtocolController` * Fix compilation of `NetworkService` & `Protocol` * Fix borrowing issues in `Notifications` * Migrate `RequestResponse`from `Peerset` to `PeerStore` * rustfmt * Migrate request-response tests from `Peerset` to `PeerStore` * Migrate `reconnect_after_disconnect` test to `PeerStore` & `ProtocolController` * Fix `Notifications` tests * Remove `Peerset` completely * Fix bug with counting sync peers in `Protocol` * Eliminate indirect calls to `PeerStore` via `Protocol` * Eliminate indirect calls to `ProtocolController` via `Protocol` * Handle `Err` outcome from `remove_peers_from_reserved_set` * Add note about disconnecting sync peers in `Protocol` * minor: remove unneeded `clone()` * minor: extra comma removed * minor: use `Stream` API of `from_protocol_controllers` channel * minor: remove TODO * minor: replace `.map().flatten()` with `.flat_map()` * minor: update `ProtocolController` docs * rustfmt * Apply suggestions from code review Co-authored-by: Aaro Altonen <48052676+altonen@users.noreply.github.com> * Extract `MockPeerStore` to `mock.rs` * Move `PeerStore` initialization to `build_network` * minor: remove unused import * minor: clarify error message * Convert `syncs_header_only_forks` test into single-threaded --------- Co-authored-by: Aaro Altonen <48052676+altonen@users.noreply.github.com>
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -18,9 +18,13 @@
|
||||
|
||||
#![cfg(test)]
|
||||
|
||||
use crate::protocol::notifications::{Notifications, NotificationsOut, ProtocolConfig};
|
||||
use crate::{
|
||||
peer_store::PeerStore,
|
||||
protocol::notifications::{Notifications, NotificationsOut, ProtocolConfig},
|
||||
protocol_controller::{ProtoSetConfig, ProtocolController, SetId},
|
||||
};
|
||||
|
||||
use futures::prelude::*;
|
||||
use futures::{future::BoxFuture, prelude::*};
|
||||
use libp2p::{
|
||||
core::{transport::MemoryTransport, upgrade, Endpoint},
|
||||
identity, noise,
|
||||
@@ -31,6 +35,7 @@ use libp2p::{
|
||||
},
|
||||
yamux, Multiaddr, PeerId, Transport,
|
||||
};
|
||||
use sc_utils::mpsc::tracing_unbounded;
|
||||
use std::{
|
||||
iter,
|
||||
pin::Pin,
|
||||
@@ -65,28 +70,31 @@ fn build_nodes() -> (Swarm<CustomProtoWithAddr>, Swarm<CustomProtoWithAddr>) {
|
||||
.timeout(Duration::from_secs(20))
|
||||
.boxed();
|
||||
|
||||
let (peerset, handle) =
|
||||
crate::peerset::Peerset::from_config(crate::peerset::PeersetConfig {
|
||||
sets: vec![crate::peerset::SetConfig {
|
||||
in_peers: 25,
|
||||
out_peers: 25,
|
||||
bootnodes: if index == 0 {
|
||||
keypairs
|
||||
.iter()
|
||||
.skip(1)
|
||||
.map(|keypair| keypair.public().to_peer_id())
|
||||
.collect()
|
||||
} else {
|
||||
vec![]
|
||||
},
|
||||
reserved_nodes: Default::default(),
|
||||
reserved_only: false,
|
||||
}],
|
||||
});
|
||||
let peer_store = PeerStore::new(if index == 0 {
|
||||
keypairs.iter().skip(1).map(|keypair| keypair.public().to_peer_id()).collect()
|
||||
} else {
|
||||
vec![]
|
||||
});
|
||||
|
||||
let (to_notifications, from_controller) =
|
||||
tracing_unbounded("test_protocol_controller_to_notifications", 10_000);
|
||||
|
||||
let (controller_handle, controller) = ProtocolController::new(
|
||||
SetId::from(0),
|
||||
ProtoSetConfig {
|
||||
in_peers: 25,
|
||||
out_peers: 25,
|
||||
reserved_nodes: Default::default(),
|
||||
reserved_only: false,
|
||||
},
|
||||
to_notifications,
|
||||
Box::new(peer_store.handle()),
|
||||
);
|
||||
|
||||
let behaviour = CustomProtoWithAddr {
|
||||
inner: Notifications::new(
|
||||
peerset,
|
||||
vec![controller_handle],
|
||||
from_controller,
|
||||
iter::once(ProtocolConfig {
|
||||
name: "/foo".into(),
|
||||
fallback_names: Vec::new(),
|
||||
@@ -94,7 +102,8 @@ fn build_nodes() -> (Swarm<CustomProtoWithAddr>, Swarm<CustomProtoWithAddr>) {
|
||||
max_notification_size: 1024 * 1024,
|
||||
}),
|
||||
),
|
||||
_peerset_handle: handle,
|
||||
peer_store_future: peer_store.run().boxed(),
|
||||
protocol_controller_future: controller.run().boxed(),
|
||||
addrs: addrs
|
||||
.iter()
|
||||
.enumerate()
|
||||
@@ -130,8 +139,8 @@ fn build_nodes() -> (Swarm<CustomProtoWithAddr>, Swarm<CustomProtoWithAddr>) {
|
||||
/// Wraps around the `CustomBehaviour` network behaviour, and adds hardcoded node addresses to it.
|
||||
struct CustomProtoWithAddr {
|
||||
inner: Notifications,
|
||||
// We need to keep `PeersetHandle` for `Peerset` not to shut down.
|
||||
_peerset_handle: crate::peerset::PeersetHandle,
|
||||
peer_store_future: BoxFuture<'static, ()>,
|
||||
protocol_controller_future: BoxFuture<'static, ()>,
|
||||
addrs: Vec<(PeerId, Multiaddr)>,
|
||||
}
|
||||
|
||||
@@ -230,6 +239,9 @@ impl NetworkBehaviour for CustomProtoWithAddr {
|
||||
cx: &mut Context,
|
||||
params: &mut impl PollParameters,
|
||||
) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
|
||||
let _ = self.peer_store_future.poll_unpin(cx);
|
||||
let _ = self.protocol_controller_future.poll_unpin(cx);
|
||||
|
||||
self.inner.poll(cx, params)
|
||||
}
|
||||
}
|
||||
@@ -272,10 +284,9 @@ fn reconnect_after_disconnect() {
|
||||
ServiceState::NotConnected => {
|
||||
service1_state = ServiceState::FirstConnec;
|
||||
if service2_state == ServiceState::FirstConnec {
|
||||
service1.behaviour_mut().disconnect_peer(
|
||||
Swarm::local_peer_id(&service2),
|
||||
crate::peerset::SetId::from(0),
|
||||
);
|
||||
service1
|
||||
.behaviour_mut()
|
||||
.disconnect_peer(Swarm::local_peer_id(&service2), SetId::from(0));
|
||||
}
|
||||
},
|
||||
ServiceState::Disconnected => service1_state = ServiceState::ConnectedAgain,
|
||||
@@ -295,10 +306,9 @@ fn reconnect_after_disconnect() {
|
||||
ServiceState::NotConnected => {
|
||||
service2_state = ServiceState::FirstConnec;
|
||||
if service1_state == ServiceState::FirstConnec {
|
||||
service1.behaviour_mut().disconnect_peer(
|
||||
Swarm::local_peer_id(&service2),
|
||||
crate::peerset::SetId::from(0),
|
||||
);
|
||||
service1
|
||||
.behaviour_mut()
|
||||
.disconnect_peer(Swarm::local_peer_id(&service2), SetId::from(0));
|
||||
}
|
||||
},
|
||||
ServiceState::Disconnected => service2_state = ServiceState::ConnectedAgain,
|
||||
|
||||
Reference in New Issue
Block a user