Incorporate sc-peerset into sc-network (#14236)

This commit is contained in:
Dmitry Markin
2023-05-29 20:56:57 +03:00
committed by GitHub
parent b8bca85e9d
commit d4b2bf7394
40 changed files with 306 additions and 337 deletions
@@ -54,7 +54,7 @@ const MAX_BODY_BYTES: usize = 8 * 1024 * 1024;
const MAX_NUMBER_OF_SAME_REQUESTS_PER_PEER: usize = 2;
mod rep {
use sc_peerset::ReputationChange as Rep;
use sc_network::ReputationChange as Rep;
/// Reputation change when a peer sent us the same request multiple times.
pub const SAME_REQUEST: Rep = Rep::new_fatal("Same block request multiple times");
+3 -3
View File
@@ -40,7 +40,7 @@ use sc_network::{
FullNetworkConfiguration, NonDefaultSetConfig, ProtocolId, SyncMode as SyncOperationMode,
},
utils::LruHashSet,
NotificationsSink, ProtocolName,
NotificationsSink, ProtocolName, ReputationChange,
};
use sc_network_common::{
role::Roles,
@@ -94,7 +94,7 @@ const INACTIVITY_EVICT_THRESHOLD: Duration = Duration::from_secs(30);
const INITIAL_EVICTION_WAIT_PERIOD: Duration = Duration::from_secs(2 * 60);
mod rep {
use sc_peerset::ReputationChange as Rep;
use sc_network::ReputationChange as Rep;
/// Peer has different genesis.
pub const GENESIS_MISMATCH: Rep = Rep::new_fatal("Genesis mismatch");
/// Peer send us a block announcement that failed at validation.
@@ -719,7 +719,7 @@ where
.disconnect_peer(peer, self.block_announce_protocol_name.clone());
self.network_service.report_peer(
peer,
sc_peerset::ReputationChange::new_fatal("Invalid justification"),
ReputationChange::new_fatal("Invalid justification"),
);
}
},
+1 -1
View File
@@ -148,7 +148,7 @@ const MAX_BLOCK_ANNOUNCE_SIZE: u64 = 1024 * 1024;
pub(crate) const MAX_BLOCKS_IN_RESPONSE: usize = 128;
mod rep {
use sc_peerset::ReputationChange as Rep;
use sc_network::ReputationChange as Rep;
/// Reputation change when a peer sent us a message that led to a
/// database read error.
pub const BLOCKCHAIN_READ_ERROR: Rep = Rep::new(-(1 << 16), "DB Error");
@@ -25,9 +25,8 @@ use sc_network::{
request_responses::{IfDisconnected, RequestFailure},
types::ProtocolName,
NetworkNotification, NetworkPeers, NetworkRequest, NetworkSyncForkRequest,
NotificationSenderError, NotificationSenderT,
NotificationSenderError, NotificationSenderT, ReputationChange,
};
use sc_peerset::ReputationChange;
use sp_runtime::traits::{Block as BlockT, NumberFor};
use std::collections::HashSet;
@@ -22,9 +22,8 @@ use libp2p::PeerId;
use sc_network::{
request_responses::{IfDisconnected, RequestFailure},
types::ProtocolName,
NetworkNotification, NetworkPeers, NetworkRequest,
NetworkNotification, NetworkPeers, NetworkRequest, ReputationChange,
};
use sc_peerset::ReputationChange;
use sc_utils::mpsc::{tracing_unbounded, TracingUnboundedReceiver, TracingUnboundedSender};
use std::sync::Arc;
@@ -159,7 +158,7 @@ mod tests {
let peer = PeerId::random();
let proto = ProtocolName::from("test-protocol");
let proto_clone = proto.clone();
let change = sc_peerset::ReputationChange::new_fatal("test-change");
let change = sc_network::ReputationChange::new_fatal("test-change");
let mut mock_network = MockNetwork::new();
mock_network
@@ -45,7 +45,7 @@ const MAX_RESPONSE_BYTES: usize = 2 * 1024 * 1024; // Actual reponse may be bigg
const MAX_NUMBER_OF_SAME_REQUESTS_PER_PEER: usize = 2;
mod rep {
use sc_peerset::ReputationChange as Rep;
use sc_network::ReputationChange as Rep;
/// Reputation change when a peer sent us the same request multiple times.
pub const SAME_REQUEST: Rep = Rep::new(i32::MIN, "Same state request multiple times");