Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

req-resp/litep2p: Reject inbound requests from banned peers #7158

Merged
merged 5 commits into from
Jan 15, 2025
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
12 changes: 12 additions & 0 deletions prdoc/pr_7158.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
title: Reject litep2p inbound requests from banned peers

doc:
- audience: Node Dev
description: |
This PR rejects inbound requests from banned peers (reputation is below the banned threshold).
This mirrors the request-response implementation from the libp2p side.
While at it, have registered a new inbound failure metric to have visibility into this.

crates:
- name: sc-network
bump: patch
25 changes: 19 additions & 6 deletions substrate/client/network/src/litep2p/shim/request_response/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,13 @@ impl RequestResponseProtocol {
request_id: RequestId,
request: Vec<u8>,
) {
log::trace!(
target: LOG_TARGET,
"{}: request received from {peer:?} ({fallback:?} {request_id:?}), request size {:?}",
self.protocol,
request.len(),
);

let Some(inbound_queue) = &self.inbound_queue else {
log::trace!(
target: LOG_TARGET,
Expand All @@ -284,12 +291,18 @@ impl RequestResponseProtocol {
return;
};

log::trace!(
target: LOG_TARGET,
"{}: request received from {peer:?} ({fallback:?} {request_id:?}), request size {:?}",
self.protocol,
request.len(),
);
if self.peerstore_handle.is_banned(&peer.into()) {
log::trace!(
target: LOG_TARGET,
"{}: rejecting inbound request from banned {peer:?} ({request_id:?})",
self.protocol,
);

self.handle.reject_request(request_id);
self.metrics.register_inbound_request_failure("banned-peer");
return;
}

let (tx, rx) = oneshot::channel();

match inbound_queue.try_send(IncomingRequest {
Expand Down
Loading