Skip to content

Commit b2950c2

Browse files
paritytech-release-backport-bot[bot]lexnvgithub-actions[bot]EgorPopelyaev
authored
[stable2506] Backport #9281 (#9329)
Backport #9281 into `stable2506` from lexnv. See the [documentation](https://github.com/paritytech/polkadot-sdk/blob/master/docs/BACKPORT.md) on how to use this bot. <!-- # To be used by other automation, do not modify: original-pr-number: #${pull_number} --> Signed-off-by: Alexandru Vasile <[email protected]> Co-authored-by: Alexandru Vasile <[email protected]> Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Egor_P <[email protected]>
1 parent f15a424 commit b2950c2

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

prdoc/pr_9281.prdoc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
title: 'litep2p/discovery: Ensure non-global addresses are not reported as external'
2+
doc:
3+
- audience: Node Dev
4+
description: "This PR ensures that external addresses discovered by the identify\
5+
\ protocol are not propagated to the litep2p backend if they are not global. This\
6+
\ leads to a healthier DHT over time, since nodes will not advertise loopback\
7+
\ / non-global addresses.\n\nWe have seen various cases were loopback addresses\
8+
\ were reported as external:\n\n```\n2025-07-16 16:18:39.765 TRACE tokio-runtime-worker\
9+
\ sub-libp2p::discovery: verify new external address: /ip4/127.0.0.1/tcp/30310/p2p/12D3KooWNw19ScMjzNGLnYYLQxWcM9EK9VYPbCq241araUGgbdLM\n\
10+
\n2025-07-16 16:18:39.765 INFO tokio-runtime-worker sub-libp2p: \U0001F50D Discovered\
11+
\ new external address for our node: /ip4/127.0.0.1/tcp/30310/p2p/12D3KooWNw19ScMjzNGLnYYLQxWcM9EK9VYPbCq241araUGgbdLM\n\
12+
```\n\nThis PR takes into account the network config for `allow_non_global_addresses`.\n\
13+
\nCloses: https://github.com/paritytech/polkadot-sdk/issues/9261\n\ncc @paritytech/networking"
14+
crates:
15+
- name: sc-network
16+
bump: patch

substrate/client/network/src/litep2p/discovery.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,15 @@ impl Discovery {
493493
) -> (bool, Option<Multiaddr>) {
494494
log::trace!(target: LOG_TARGET, "verify new external address: {address}");
495495

496+
if !self.allow_non_global_addresses && !Discovery::can_add_to_dht(&address) {
497+
log::trace!(
498+
target: LOG_TARGET,
499+
"ignoring externally reported non-global address {address} from {peer}."
500+
);
501+
502+
return (false, None);
503+
}
504+
496505
// is the address one of our known addresses
497506
if self
498507
.listen_addresses

0 commit comments

Comments
 (0)