Skip to content
Merged
Changes from 2 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
7 changes: 5 additions & 2 deletions substrate/client/network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,11 @@ pub struct MultiaddrWithPeerId {
impl MultiaddrWithPeerId {
/// Concatenates the multiaddress and peer ID into one multiaddress containing both.
pub fn concat(&self) -> Multiaddr {
let proto = multiaddr::Protocol::P2p(From::from(self.peer_id));
self.multiaddr.clone().with(proto)
let mut addr = self.multiaddr.clone();
if matches!(addr.iter().last(), Some(multiaddr::Protocol::P2p(_))) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe worth adding a comment why we do it

addr.pop();
}
Comment on lines +175 to +177
Copy link
Copy Markdown
Contributor

@dmitry-markin dmitry-markin Feb 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be difficult to ensure that self.multiaddr never contains the peer ID in the first place?

We should investigate how peer IDs end up in the address that is supposed to be without a peer ID.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Litep2p appends the /p2p prefix on all listen addresses on initialization:

https://github.com/paritytech/litep2p/blob/5ec893959bc64a479545a3a6b6a5090fa84c796b/src/lib.rs#L334

I don't believe this will cause issues since we are dialing from the transport manager either way:

  • a different peer cannot trick us into dialing since we compare the addresses stripped of /p2p prefix
  • don't believe other protocols make use of this

I would still keep this one as a tiny defensive check for future proofing

addr.with(multiaddr::Protocol::P2p(From::from(self.peer_id)))
}
}

Expand Down
Loading