Skip to content
Snippets Groups Projects
Commit cbfbad6f authored by Max Inden's avatar Max Inden Committed by GitHub
Browse files

client/authority-discovery: Compare PeerIds and not Multihashes (#6414)

In order to tell whether an address is the local nodes address the
authority discovery module previously compared the Multihash within the
`p2p` Multiaddr protocol.

rust-libp2p recently switched to a new PeerId representation (see [1]).
Multihashes of the same PeerId in the new and the old format don't
equal.

Instead of comparing the Multihashes, this patch ensures the module
compares the PeerIds

[1] https://github.com/libp2p/rust-libp2p/issues/555
parent 7858828d
Branches
No related merge requests found
...@@ -72,6 +72,7 @@ use sc_network::{ ...@@ -72,6 +72,7 @@ use sc_network::{
ExHashT, ExHashT,
Multiaddr, Multiaddr,
NetworkStateInfo, NetworkStateInfo,
PeerId,
}; };
use sp_authority_discovery::{AuthorityDiscoveryApi, AuthorityId, AuthoritySignature, AuthorityPair}; use sp_authority_discovery::{AuthorityDiscoveryApi, AuthorityId, AuthoritySignature, AuthorityPair};
use sp_core::crypto::{key_types, Pair}; use sp_core::crypto::{key_types, Pair};
...@@ -430,7 +431,7 @@ where ...@@ -430,7 +431,7 @@ where
.get(&remote_key) .get(&remote_key)
.ok_or(Error::MatchingHashedAuthorityIdWithAuthorityId)?; .ok_or(Error::MatchingHashedAuthorityIdWithAuthorityId)?;
let local_peer_id = multiaddr::Protocol::P2p(self.network.local_peer_id().into()); let local_peer_id = self.network.local_peer_id();
let remote_addresses: Vec<Multiaddr> = values.into_iter() let remote_addresses: Vec<Multiaddr> = values.into_iter()
.map(|(_k, v)| { .map(|(_k, v)| {
...@@ -459,9 +460,23 @@ where ...@@ -459,9 +460,23 @@ where
.into_iter() .into_iter()
.flatten() .flatten()
// Ignore own addresses. // Ignore own addresses.
.filter(|addr| !addr.iter().any(|protocol| .filter(|addr| !addr.iter().any(|protocol| {
protocol == local_peer_id // Parse to PeerId first as Multihashes of old and new PeerId
)) // representation don't equal.
//
// See https://github.com/libp2p/rust-libp2p/issues/555 for
// details.
if let multiaddr::Protocol::P2p(hash) = protocol {
let peer_id = match PeerId::from_multihash(hash) {
Ok(peer_id) => peer_id,
Err(_) => return true, // Discard address.
};
return peer_id == local_peer_id;
}
false // Multiaddr does not contain a PeerId.
}))
.collect(); .collect();
if !remote_addresses.is_empty() { if !remote_addresses.is_empty() {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment