mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-28 13:17:28 +00:00
Reputation changes requires reason (#4277)
This commit is contained in:
committed by
Gavin Wood
parent
5edc4350b4
commit
5ec0923285
@@ -33,6 +33,7 @@ use crate::message::{self, BlockAttributes, Direction, FromBlock, RequestId};
|
||||
use libp2p::PeerId;
|
||||
use crate::config::Roles;
|
||||
use sp_runtime::traits::{Block as BlockT, Header as HeaderT, NumberFor};
|
||||
use peerset::ReputationChange;
|
||||
|
||||
/// Remote request timeout.
|
||||
const REQUEST_TIMEOUT: Duration = Duration::from_secs(15);
|
||||
@@ -44,7 +45,7 @@ const TIMEOUT_REPUTATION_CHANGE: i32 = -(1 << 8);
|
||||
/// Trait used by the `LightDispatch` service to communicate messages back to the network.
|
||||
pub trait LightDispatchNetwork<B: BlockT> {
|
||||
/// Adjusts the reputation of the given peer.
|
||||
fn report_peer(&mut self, who: &PeerId, reputation_change: i32);
|
||||
fn report_peer(&mut self, who: &PeerId, reputation_change: ReputationChange);
|
||||
|
||||
/// Disconnect from the given peer. Used in case of misbehaviour.
|
||||
fn disconnect_peer(&mut self, who: &PeerId);
|
||||
@@ -267,7 +268,7 @@ impl<B: BlockT> LightDispatch<B> where
|
||||
Some(request) => request,
|
||||
None => {
|
||||
info!("Invalid remote {} response from peer {}", rtype, peer);
|
||||
network.report_peer(&peer, i32::min_value());
|
||||
network.report_peer(&peer, ReputationChange::new_fatal("Invalid remote response"));
|
||||
network.disconnect_peer(&peer);
|
||||
self.remove_peer(peer);
|
||||
return;
|
||||
@@ -279,7 +280,7 @@ impl<B: BlockT> LightDispatch<B> where
|
||||
Accept::Ok => (retry_count, None),
|
||||
Accept::CheckFailed(error, retry_request_data) => {
|
||||
info!("Failed to check remote {} response from peer {}: {}", rtype, peer, error);
|
||||
network.report_peer(&peer, i32::min_value());
|
||||
network.report_peer(&peer, ReputationChange::new_fatal("Failed remote response check"));
|
||||
network.disconnect_peer(&peer);
|
||||
self.remove_peer(peer);
|
||||
|
||||
@@ -293,7 +294,7 @@ impl<B: BlockT> LightDispatch<B> where
|
||||
},
|
||||
Accept::Unexpected(retry_request_data) => {
|
||||
info!("Unexpected response to remote {} from peer", rtype);
|
||||
network.report_peer(&peer, i32::min_value());
|
||||
network.report_peer(&peer, ReputationChange::new_fatal("Unexpected remote response"));
|
||||
network.disconnect_peer(&peer);
|
||||
self.remove_peer(peer);
|
||||
|
||||
@@ -350,7 +351,7 @@ impl<B: BlockT> LightDispatch<B> where
|
||||
|
||||
let (bad_peer, request) = self.active_peers.pop_front().expect("front() is Some as checked above");
|
||||
self.pending_requests.push_front(request);
|
||||
network.report_peer(&bad_peer, TIMEOUT_REPUTATION_CHANGE);
|
||||
network.report_peer(&bad_peer, ReputationChange::new(TIMEOUT_REPUTATION_CHANGE, "Light request timeout"));
|
||||
network.disconnect_peer(&bad_peer);
|
||||
}
|
||||
|
||||
@@ -800,7 +801,7 @@ pub mod tests {
|
||||
}
|
||||
|
||||
impl<'a, B: BlockT> LightDispatchNetwork<B> for &'a mut DummyNetwork {
|
||||
fn report_peer(&mut self, _: &PeerId, _: i32) {}
|
||||
fn report_peer(&mut self, _: &PeerId, _: crate::ReputationChange) {}
|
||||
fn disconnect_peer(&mut self, who: &PeerId) {
|
||||
self.disconnected_peers.insert(who.clone());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user