Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
6e38b7e
Move bootnodes from individual `SetConfig`s to `PeersetConfig`
dmitry-markin Jun 6, 2023
dae075d
Move `SetId` & `SetConfig` from `peerset` to `protocol_controller`
dmitry-markin Jun 6, 2023
5a4f6a4
Remove unused `DropReason`
dmitry-markin Jun 6, 2023
7acf0e3
Move `Message` & `IncomingIndex` from `peerset` to `protocol_controller`
dmitry-markin Jun 6, 2023
037ead4
Restore running fuzz test
dmitry-markin Jun 6, 2023
efba474
Get rid of `Peerset` in `fuzz` test
dmitry-markin Jun 6, 2023
911d26f
Spawn runners instead of manual polling in `fuzz` test
dmitry-markin Jun 7, 2023
25b63cd
Migrate `Protocol` from `Peerset` to `PeerStore` & `ProtocolController`
dmitry-markin Jun 7, 2023
1fbff99
Migrate `NetworkService` from `Peerset` to `PeerStore` & `ProtocolCon…
dmitry-markin Jun 7, 2023
8923fb5
Migrate `Notifications` from `Peerset` to `ProtocolController`s
dmitry-markin Jun 8, 2023
1350193
Migrate `Notifications` tests from `Peerset` to `ProtocolController`
dmitry-markin Jun 8, 2023
e0cae7e
Fix compilation of `NetworkService` & `Protocol`
dmitry-markin Jun 8, 2023
10ec8b4
Fix borrowing issues in `Notifications`
dmitry-markin Jun 8, 2023
b92ed07
Migrate `RequestResponse`from `Peerset` to `PeerStore`
dmitry-markin Jun 8, 2023
b265eb8
rustfmt
dmitry-markin Jun 8, 2023
5339b2e
Migrate request-response tests from `Peerset` to `PeerStore`
dmitry-markin Jun 8, 2023
71ca009
Migrate `reconnect_after_disconnect` test to `PeerStore` & `ProtocolC…
dmitry-markin Jun 8, 2023
8b64997
Fix `Notifications` tests
dmitry-markin Jun 8, 2023
eb2693e
Remove `Peerset` completely
dmitry-markin Jun 8, 2023
cb3b12c
Fix bug with counting sync peers in `Protocol`
dmitry-markin Jun 9, 2023
649b6c1
Eliminate indirect calls to `PeerStore` via `Protocol`
dmitry-markin Jun 9, 2023
094ffe5
Eliminate indirect calls to `ProtocolController` via `Protocol`
dmitry-markin Jun 9, 2023
dd77fba
Handle `Err` outcome from `remove_peers_from_reserved_set`
dmitry-markin Jun 9, 2023
5cddda0
Add note about disconnecting sync peers in `Protocol`
dmitry-markin Jun 9, 2023
84fb33d
minor: remove unneeded `clone()`
dmitry-markin Jun 9, 2023
7588e32
minor: extra comma removed
dmitry-markin Jun 9, 2023
7a84efc
minor: use `Stream` API of `from_protocol_controllers` channel
dmitry-markin Jun 9, 2023
7b39689
minor: remove TODO
dmitry-markin Jun 9, 2023
a9b65dc
minor: replace `.map().flatten()` with `.flat_map()`
dmitry-markin Jun 9, 2023
ac22673
minor: update `ProtocolController` docs
dmitry-markin Jun 9, 2023
c637260
rustfmt
dmitry-markin Jun 9, 2023
ab05cf0
Merge remote-tracking branch 'origin/master' into dm-get-rid-of-peers…
dmitry-markin Jun 12, 2023
6f17714
Apply suggestions from code review
dmitry-markin Jun 13, 2023
b5ec102
Extract `MockPeerStore` to `mock.rs`
dmitry-markin Jun 13, 2023
1e89b2a
Merge remote-tracking branch 'origin/master' into dm-get-rid-of-peers…
dmitry-markin Jun 14, 2023
0520230
Move `PeerStore` initialization to `build_network`
dmitry-markin Jun 14, 2023
e46fa49
minor: remove unused import
dmitry-markin Jun 14, 2023
2d336a5
Merge remote-tracking branch 'origin/master' into dm-get-rid-of-peers…
dmitry-markin Jun 19, 2023
02334a8
Merge remote-tracking branch 'origin/master' into dm-get-rid-of-peers…
dmitry-markin Jul 21, 2023
bbea1d4
minor: clarify error message
dmitry-markin Jul 24, 2023
c516194
Convert `syncs_header_only_forks` test into single-threaded
dmitry-markin Jul 24, 2023
3c37275
Merge remote-tracking branch 'origin/master' into dm-get-rid-of-peers…
dmitry-markin Jul 24, 2023
78f8884
Merge remote-tracking branch 'origin/master' into dm-get-rid-of-peers…
dmitry-markin Jul 26, 2023
70d5a11
Merge remote-tracking branch 'origin/master' into dm-get-rid-of-peers…
dmitry-markin Aug 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Extract MockPeerStore to mock.rs
  • Loading branch information
dmitry-markin committed Jun 13, 2023
commit b5ec10284993805a4561f4bf8cda3c2534df01d5
3 changes: 3 additions & 0 deletions client/network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ mod behaviour;
mod protocol;
mod service;

#[cfg(test)]
mod mock;

pub mod config;
pub mod discovery;
pub mod error;
Expand Down
55 changes: 55 additions & 0 deletions client/network/src/mock.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// This file is part of Substrate.

// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

//! Mocked components for tests.

use crate::{peer_store::PeerStoreProvider, protocol_controller::ProtocolHandle, ReputationChange};
use libp2p::PeerId;
use std::collections::HashSet;

/// No-op `PeerStore`.
#[derive(Debug)]
pub struct MockPeerStore {}

impl PeerStoreProvider for MockPeerStore {
fn is_banned(&self, _peer_id: &PeerId) -> bool {
// Make sure that the peer is not banned.
false
}

fn register_protocol(&self, _protocol_handle: ProtocolHandle) {
// Make sure not to fail.
}

fn report_disconnect(&mut self, _peer_id: PeerId) {
// Make sure not to fail.
}

fn report_peer(&mut self, _peer_id: PeerId, _change: ReputationChange) {
// Make sure not to fail.
}

fn peer_reputation(&self, _peer_id: &PeerId) -> i32 {
// Make sure that the peer is not banned.
0
}

fn outgoing_candidates(&self, _count: usize, _ignored: HashSet<&PeerId>) -> Vec<PeerId> {
unimplemented!()
}
}
34 changes: 2 additions & 32 deletions client/network/src/protocol/notifications/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2101,10 +2101,9 @@ impl NetworkBehaviour for Notifications {
mod tests {
use super::*;
use crate::{
peer_store::PeerStoreProvider,
mock::MockPeerStore,
protocol::notifications::handler::tests::*,
protocol_controller::{IncomingIndex, ProtoSetConfig, ProtocolController, ProtocolHandle},
ReputationChange,
protocol_controller::{IncomingIndex, ProtoSetConfig, ProtocolController},
};
use libp2p::swarm::AddressRecord;
use sc_utils::mpsc::tracing_unbounded;
Expand Down Expand Up @@ -2153,35 +2152,6 @@ mod tests {
}
}

#[derive(Debug)]
struct MockPeerStore {}

impl PeerStoreProvider for MockPeerStore {
fn is_banned(&self, _peer_id: &PeerId) -> bool {
unimplemented!()
}

fn register_protocol(&self, _protocol_handle: ProtocolHandle) {
// Not a real peer store, do nothing.
}

fn report_disconnect(&mut self, _peer_id: PeerId) {
unimplemented!()
}

fn report_peer(&mut self, _peer_id: PeerId, _change: ReputationChange) {
unimplemented!()
}

fn peer_reputation(&self, _peer_id: &PeerId) -> i32 {
unimplemented!()
}

fn outgoing_candidates(&self, _count: usize, _ignored: HashSet<&PeerId>) -> Vec<PeerId> {
unimplemented!()
}
}

fn development_notifs() -> (Notifications, ProtocolController) {
let (to_notifications, from_controller) =
tracing_unbounded("test_controller_to_notifications", 10_000);
Expand Down
4 changes: 2 additions & 2 deletions client/network/src/protocol_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ pub struct ProtoSetConfig {
/// Message that is sent by [`ProtocolController`] to `Notifications`.
#[derive(Debug, PartialEq)]
pub enum Message {
/// Request to open a connection to the given peer. From the point of view of the `ProtocolController`, we are
/// immediately connected.
/// Request to open a connection to the given peer. From the point of view of the
/// `ProtocolController`, we are immediately connected.
Connect {
/// Set id to connect on.
set_id: SetId,
Expand Down
50 changes: 11 additions & 39 deletions client/network/src/request_responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,13 +668,15 @@ impl NetworkBehaviour for RequestResponsesBehaviour {
// The `tx` created above can be dropped if we are not capable of
// processing this request, which is reflected as a
// `InboundFailure::Omission` event.
rx.await.map_or(None, |response| Some(RequestProcessingOutcome {
peer,
request_id,
protocol,
inner_channel: channel,
response,
}))
rx.await.map_or(None, |response| {
Some(RequestProcessingOutcome {
peer,
request_id,
protocol,
inner_channel: channel,
response,
})
})
}));

// This `continue` makes sure that `pending_responses` gets polled
Expand Down Expand Up @@ -963,7 +965,7 @@ impl Codec for GenericCodec {
mod tests {
use super::*;

use crate::{peer_store::PeerStoreProvider, protocol_controller::ProtocolHandle};
use crate::mock::MockPeerStore;
use futures::{channel::oneshot, executor::LocalPool, task::Spawn};
use libp2p::{
core::{
Expand All @@ -975,7 +977,7 @@ mod tests {
swarm::{Executor, Swarm, SwarmBuilder, SwarmEvent},
Multiaddr,
};
use std::{collections::HashSet, iter, time::Duration};
use std::{iter, time::Duration};

struct TokioExecutor(tokio::runtime::Runtime);
impl Executor for TokioExecutor {
Expand All @@ -984,36 +986,6 @@ mod tests {
}
}

#[derive(Debug)]
struct MockPeerStore {}

impl PeerStoreProvider for MockPeerStore {
fn is_banned(&self, _peer_id: &PeerId) -> bool {
unimplemented!()
}

fn register_protocol(&self, _protocol_handle: ProtocolHandle) {
unimplemented!()
}

fn report_disconnect(&mut self, _peer_id: PeerId) {
unimplemented!()
}

fn report_peer(&mut self, _peer_id: PeerId, _change: ReputationChange) {
unimplemented!()
}

fn peer_reputation(&self, _peer_id: &PeerId) -> i32 {
// We just need to make sure that the peer is not banned.
0
}

fn outgoing_candidates(&self, _count: usize, _ignored: HashSet<&PeerId>) -> Vec<PeerId> {
unimplemented!()
}
}

fn build_swarm(
list: impl Iterator<Item = ProtocolConfig>,
) -> (Swarm<RequestResponsesBehaviour>, Multiaddr) {
Expand Down