Skip to content
Snippets Groups Projects
Unverified Commit 0d932484 authored by Dmitry Markin's avatar Dmitry Markin Committed by GitHub
Browse files

Fix `addresses_to_publish_respects_existing_p2p_protocol` test in sc-authority-discovery (#3895)

Fixes https://github.com/paritytech/polkadot-sdk/issues/3887.
parent 5638d1a8
No related merge requests found
Pipeline #460321 failed with stages
in 56 minutes and 39 seconds
......@@ -342,6 +342,7 @@ where
}
fn addresses_to_publish(&self) -> impl Iterator<Item = Multiaddr> {
let local_peer_id = self.network.local_peer_id();
let publish_non_global_ips = self.publish_non_global_ips;
let addresses = self
.public_addresses
......@@ -349,7 +350,15 @@ where
.into_iter()
.chain(self.network.external_addresses().into_iter().filter_map(|mut address| {
// Make sure the reported external address does not contain `/p2p/...` protocol.
if let Some(multiaddr::Protocol::P2p(_)) = address.iter().last() {
if let Some(multiaddr::Protocol::P2p(peer_id)) = address.iter().last() {
if peer_id != *local_peer_id.as_ref() {
error!(
target: LOG_TARGET,
"Network returned external address '{address}' with peer id \
not matching the local peer id '{local_peer_id}'.",
);
debug_assert!(false);
}
address.pop();
}
......@@ -375,15 +384,16 @@ where
})
.collect::<Vec<_>>();
let peer_id = self.network.local_peer_id();
debug!(
target: LOG_TARGET,
"Authority DHT record peer_id='{peer_id}' addresses='{addresses:?}'",
"Authority DHT record peer_id='{local_peer_id}' addresses='{addresses:?}'",
);
// The address must include the peer id.
let peer_id: Multihash = peer_id.into();
addresses.into_iter().map(move |a| a.with(multiaddr::Protocol::P2p(peer_id)))
// The address must include the local peer id.
let local_peer_id: Multihash = local_peer_id.into();
addresses
.into_iter()
.map(move |a| a.with(multiaddr::Protocol::P2p(local_peer_id)))
}
/// Publish own public addresses.
......
......@@ -716,12 +716,16 @@ fn addresses_to_publish_adds_p2p() {
#[test]
fn addresses_to_publish_respects_existing_p2p_protocol() {
let (_dht_event_tx, dht_event_rx) = channel(1000);
let identity = Keypair::generate_ed25519();
let peer_id = identity.public().to_peer_id();
let external_address = "/ip6/2001:db8::/tcp/30333"
.parse::<Multiaddr>()
.unwrap()
.with(multiaddr::Protocol::P2p(peer_id.into()));
let network: Arc<TestNetwork> = Arc::new(TestNetwork {
external_addresses: vec![
"/ip6/2001:db8::/tcp/30333/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC"
.parse()
.unwrap(),
],
peer_id,
identity,
external_addresses: vec![external_address],
..Default::default()
});
......
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