Skip to content

Commit

Permalink
Update sc-authority-discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-markin committed Jun 3, 2024
1 parent ddc8c58 commit 21da1ef
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion substrate/client/authority-discovery/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn get_addresses_and_authority_id() {
let remote_addr = "/ip6/2001:db8:0:0:0:0:0:2/tcp/30333"
.parse::<Multiaddr>()
.unwrap()
.with(Protocol::P2p(remote_peer_id));
.with(Protocol::P2p(remote_peer_id.into()));

let test_api = Arc::new(TestApi { authorities: vec![] });

Expand Down
13 changes: 5 additions & 8 deletions substrate/client/authority-discovery/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ use sc_network::{
event::DhtEvent, multiaddr, KademliaKey, Multiaddr, NetworkDHTProvider, NetworkSigner,
NetworkStateInfo,
};
use sc_network_types::{
multihash::{Code, Multihash},
PeerId,
};
use sc_network_types::{multihash::Code, PeerId};
use sp_api::{ApiError, ProvideRuntimeApi};
use sp_authority_discovery::{
AuthorityDiscoveryApi, AuthorityId, AuthorityPair, AuthoritySignature,
Expand Down Expand Up @@ -247,7 +244,7 @@ where
.into_iter()
.map(|mut address| {
if let Some(multiaddr::Protocol::P2p(peer_id)) = address.iter().last() {
if peer_id != local_peer_id {
if peer_id != *local_peer_id.as_ref() {
error!(
target: LOG_TARGET,
"Discarding invalid local peer ID in public address {address}.",
Expand Down Expand Up @@ -353,7 +350,7 @@ where
.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(peer_id)) = address.iter().last() {
if peer_id != local_peer_id {
if peer_id != *local_peer_id.as_ref() {
error!(
target: LOG_TARGET,
"Network returned external address '{address}' with peer id \
Expand Down Expand Up @@ -394,7 +391,7 @@ where
// The address must include the local peer id.
addresses
.into_iter()
.map(move |a| a.with(multiaddr::Protocol::P2p(local_peer_id)))
.map(move |a| a.with(multiaddr::Protocol::P2p(*local_peer_id.as_ref())))
}

/// Publish own public addresses.
Expand Down Expand Up @@ -619,7 +616,7 @@ where
.map_err(Error::ParsingMultiaddress)?;

let get_peer_id = |a: &Multiaddr| match a.iter().last() {
Some(multiaddr::Protocol::P2p(peer_id)) => Some(peer_id),
Some(multiaddr::Protocol::P2p(key)) => PeerId::from_multihash(key).ok(),
_ => None,
};

Expand Down
10 changes: 5 additions & 5 deletions substrate/client/authority-discovery/src/worker/addr_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ impl AddrCache {

fn peer_id_from_multiaddr(addr: &Multiaddr) -> Option<PeerId> {
addr.iter().last().and_then(|protocol| {
if let Protocol::P2p(peer_id) = protocol {
Some(peer_id)
if let Protocol::P2p(multihash) = protocol {
PeerId::from_multihash(multihash).ok()
} else {
None
}
Expand All @@ -177,7 +177,7 @@ mod tests {
use super::*;

use quickcheck::{Arbitrary, Gen, QuickCheck, TestResult};
use sc_network_types::multihash::Multihash;
use sc_network_types::multihash::{Code, Multihash};

use sp_authority_discovery::{AuthorityId, AuthorityPair};
use sp_core::crypto::Pair;
Expand All @@ -204,7 +204,7 @@ mod tests {
let multiaddr = "/ip6/2001:db8:0:0:0:0:0:2/tcp/30333"
.parse::<Multiaddr>()
.unwrap()
.with(Protocol::P2p(peer_id));
.with(Protocol::P2p(peer_id.into()));

TestMultiaddr(multiaddr)
}
Expand Down Expand Up @@ -363,7 +363,7 @@ mod tests {
let mut addr_cache = AddrCache::new();

let peer_id = PeerId::random();
let addr = Multiaddr::empty().with(Protocol::P2p(peer_id));
let addr = Multiaddr::empty().with(Protocol::P2p(peer_id.into()));

let authority_id0 = AuthorityPair::generate().0.public();
let authority_id1 = AuthorityPair::generate().0.public();
Expand Down
4 changes: 2 additions & 2 deletions substrate/client/authority-discovery/src/worker/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ impl DhtValueFoundTester {
let address: Multiaddr =
format!("/ip6/2001:db8:0:0:0:0:0:{:x}/tcp/30333", idx).parse().unwrap();

address.with(multiaddr::Protocol::P2p(peer_id))
address.with(multiaddr::Protocol::P2p(peer_id.into()))
}

fn process_value_found(
Expand Down Expand Up @@ -776,7 +776,7 @@ fn lookup_throttling() {
let peer_id = PeerId::random();
let address: Multiaddr = "/ip6/2001:db8:0:0:0:0:0:1/tcp/30333".parse().unwrap();

address.with(multiaddr::Protocol::P2p(peer_id))
address.with(multiaddr::Protocol::P2p(peer_id.into()))
};
let remote_key_store = MemoryKeystore::new();
let remote_public_keys: Vec<AuthorityId> = (0..20)
Expand Down

0 comments on commit 21da1ef

Please sign in to comment.