Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Incorporate sc-peerset into sc-network #14236

Merged
merged 4 commits into from
May 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 2 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ members = [
"client/network/sync",
"client/network/test",
"client/offchain",
"client/peerset",
"client/allocator",
"client/proposer-metrics",
"client/rpc",
Expand Down
1 change: 0 additions & 1 deletion client/network-gossip/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ tracing = "0.1.29"
prometheus-endpoint = { package = "substrate-prometheus-endpoint", version = "0.10.0-dev", path = "../../utils/prometheus" }
sc-network = { version = "0.10.0-dev", path = "../network/" }
sc-network-common = { version = "0.10.0-dev", path = "../network/common" }
sc-peerset = { version = "4.0.0-dev", path = "../peerset" }
sp-runtime = { version = "8.0.0", path = "../../primitives/runtime" }

[dev-dependencies]
Expand Down
3 changes: 1 addition & 2 deletions client/network-gossip/src/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ use crate::{
Network, Syncing, Validator,
};

use sc_network::{event::Event, types::ProtocolName};
use sc_network::{event::Event, types::ProtocolName, ReputationChange};
use sc_network_common::sync::SyncEvent;
use sc_peerset::ReputationChange;

use futures::{
channel::mpsc::{channel, Receiver, Sender},
Expand Down
5 changes: 2 additions & 3 deletions client/network-gossip/src/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const REBROADCAST_INTERVAL: time::Duration = time::Duration::from_millis(750);
pub(crate) const PERIODIC_MAINTENANCE_INTERVAL: time::Duration = time::Duration::from_millis(1100);

mod rep {
use sc_peerset::ReputationChange as Rep;
use sc_network::ReputationChange as Rep;
/// Reputation change when a peer sends us a gossip message that we didn't know about.
pub const GOSSIP_SUCCESS: Rep = Rep::new(1 << 4, "Successful gossip");
/// Reputation change when a peer sends us a gossip message that we already knew about.
Expand Down Expand Up @@ -529,9 +529,8 @@ mod tests {
use sc_network::{
config::MultiaddrWithPeerId, event::Event, NetworkBlock, NetworkEventStream,
NetworkNotification, NetworkPeers, NotificationSenderError,
NotificationSenderT as NotificationSender,
NotificationSenderT as NotificationSender, ReputationChange,
};
use sc_peerset::ReputationChange;
use sp_runtime::{
testing::{Block as RawBlock, ExtrinsicWrapper, H256},
traits::NumberFor,
Expand Down
4 changes: 3 additions & 1 deletion client/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ log = "0.4.17"
lru = "0.10.0"
mockall = "0.11.3"
parking_lot = "0.12.1"
partial_sort = "0.2.0"
pin-project = "1.0.12"
rand = "0.8.5"
serde = { version = "1.0.136", features = ["derive"] }
Expand All @@ -44,7 +45,6 @@ sc-block-builder = { version = "0.10.0-dev", path = "../block-builder" }
sc-client-api = { version = "4.0.0-dev", path = "../api" }
sc-consensus = { version = "0.10.0-dev", path = "../consensus/common" }
sc-network-common = { version = "0.10.0-dev", path = "./common" }
sc-peerset = { version = "4.0.0-dev", path = "../peerset" }
sc-utils = { version = "4.0.0-dev", path = "../utils" }
sp-arithmetic = { version = "7.0.0", path = "../../primitives/arithmetic" }
sp-blockchain = { version = "4.0.0-dev", path = "../../primitives/blockchain" }
Expand All @@ -55,9 +55,11 @@ sp-runtime = { version = "8.0.0", path = "../../primitives/runtime" }
#
# When libp2p also enforces this version, we can get rid off this extra dep here.
snow = "0.9.2"
wasm-timer = "0.2"

[dev-dependencies]
assert_matches = "1.3"
mockall = "0.11.3"
multistream-select = "0.12.1"
rand = "0.8.5"
tempfile = "3.1.0"
Expand Down
1 change: 0 additions & 1 deletion client/network/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ libp2p-identity = { version = "0.1.2", features = ["peerid"] }
prometheus-endpoint = { package = "substrate-prometheus-endpoint", version = "0.10.0-dev", path = "../../../utils/prometheus" }
smallvec = "1.8.0"
sc-consensus = { version = "0.10.0-dev", path = "../../consensus/common" }
sc-peerset = { version = "4.0.0-dev", path = "../../peerset" }
sc-utils = { version = "4.0.0-dev", path = "../../utils" }
serde = { version = "1.0.136", features = ["derive"] }
sp-consensus = { version = "0.10.0-dev", path = "../../../primitives/consensus/common" }
Expand Down
1 change: 1 addition & 0 deletions client/network/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
pub mod message;
pub mod role;
pub mod sync;
pub mod types;

/// Minimum Requirements for a Hash within Networking
pub trait ExHashT: std::hash::Hash + Eq + std::fmt::Debug + Clone + Send + Sync + 'static {}
Expand Down
4 changes: 2 additions & 2 deletions client/network/common/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub mod message;
pub mod metrics;
pub mod warp;

use crate::role::Roles;
use crate::{role::Roles, types::ReputationChange};
use futures::Stream;

use libp2p_identity::PeerId;
Expand Down Expand Up @@ -106,7 +106,7 @@ pub struct SyncStatus<Block: BlockT> {

/// A peer did not behave as expected and should be reported.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BadPeer(pub PeerId, pub sc_peerset::ReputationChange);
pub struct BadPeer(pub PeerId, pub ReputationChange);

impl fmt::Display for BadPeer {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down
38 changes: 38 additions & 0 deletions client/network/common/src/types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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/>.

/// Description of a reputation adjustment for a node.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ReputationChange {
/// Reputation delta.
pub value: i32,
/// Reason for reputation change.
pub reason: &'static str,
}

impl ReputationChange {
/// New reputation change with given delta and reason.
pub const fn new(value: i32, reason: &'static str) -> ReputationChange {
Self { value, reason }
}

/// New reputation change that forces minimum possible reputation.
pub const fn new_fatal(reason: &'static str) -> ReputationChange {
Self { value: i32::MIN, reason }
}
}
1 change: 0 additions & 1 deletion client/network/light/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ sp-blockchain = { version = "4.0.0-dev", path = "../../../primitives/blockchain"
sc-client-api = { version = "4.0.0-dev", path = "../../api" }
sc-network = { version = "0.10.0-dev", path = "../" }
sc-network-common = { version = "0.10.0-dev", path = "../common" }
sc-peerset = { version = "4.0.0-dev", path = "../../peerset" }
sp-core = { version = "8.0.0", path = "../../../primitives/core" }
sp-runtime = { version = "8.0.0", path = "../../../primitives/runtime" }
thiserror = "1.0"
2 changes: 1 addition & 1 deletion client/network/light/src/light_client_requests/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ use sc_client_api::{BlockBackend, ProofProvider};
use sc_network::{
config::ProtocolId,
request_responses::{IncomingRequest, OutgoingResponse, ProtocolConfig},
ReputationChange,
};
use sc_peerset::ReputationChange;
use sp_core::{
hexdisplay::HexDisplay,
storage::{ChildInfo, ChildType, PrefixedStorageKey},
Expand Down
3 changes: 2 additions & 1 deletion client/network/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ use crate::{
discovery::{DiscoveryBehaviour, DiscoveryConfig, DiscoveryOut},
event::DhtEvent,
peer_info,
peerset::PeersetHandle,
protocol::{CustomMessageOutcome, NotificationsSink, Protocol},
request_responses::{self, IfDisconnected, ProtocolConfig, RequestFailure},
types::ProtocolName,
ReputationChange,
};

use bytes::Bytes;
Expand All @@ -33,7 +35,6 @@ use libp2p::{
};

use sc_network_common::role::{ObservedRole, Roles};
use sc_peerset::{PeersetHandle, ReputationChange};
use sp_runtime::traits::Block as BlockT;
use std::{collections::HashSet, time::Duration};

Expand Down
6 changes: 4 additions & 2 deletions client/network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,10 @@
//! More precise usage details are still being worked on and will likely change in the future.

mod behaviour;
mod peer_store;
mod peerset;
mod protocol;
mod protocol_controller;
mod service;

pub mod config;
Expand All @@ -267,6 +270,7 @@ pub use sc_network_common::{
warp::{WarpSyncPhase, WarpSyncProgress},
ExtendedPeerInfo, StateDownloadProgress, SyncEventStream, SyncState, SyncStatusProvider,
},
types::ReputationChange,
};
pub use service::{
signature::Signature,
Expand All @@ -281,8 +285,6 @@ pub use service::{
};
pub use types::ProtocolName;

pub use sc_peerset::ReputationChange;

/// The maximum allowed number of established connections per peer.
///
/// Typically, and by design of the network behaviours in this crate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use libp2p_identity::PeerId;
use libp2p::PeerId;
use log::trace;
use parking_lot::Mutex;
use partial_sort::PartialSort;
use sc_network_common::types::ReputationChange;
use std::{
cmp::{Ord, Ordering, PartialOrd},
collections::{hash_map::Entry, HashMap, HashSet},
Expand All @@ -29,7 +30,10 @@ use std::{
};
use wasm_timer::Delay;

use crate::{protocol_controller::ProtocolHandle, ReputationChange, LOG_TARGET};
use crate::protocol_controller::ProtocolHandle;

/// Log target for this file.
pub const LOG_TARGET: &str = "peerset";

/// We don't accept nodes whose reputation is under this value.
pub const BANNED_THRESHOLD: i32 = 82 * (i32::MIN / 100);
Expand Down
Loading