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

Fix addresses_to_publish_respects_existing_p2p_protocol test in sc-authority-discovery #3895

Merged
merged 1 commit into from
Mar 29, 2024
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
22 changes: 16 additions & 6 deletions substrate/client/authority-discovery/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,14 +342,23 @@ 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
.clone()
.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();
}

Expand All @@ -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.
Expand Down
14 changes: 9 additions & 5 deletions substrate/client/authority-discovery/src/worker/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
});

Expand Down
Loading