mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 05:11:09 +00:00
client/authority-discovery: Don't add own address to priority group (#6370)
* client/authority-discovery: Don't add own address to priority group
In the scenario of a validator publishing the address of its sentry node
to the DHT, said sentry node should not add its own Multiaddr to the
peerset "authority" priority group.
Related to 273f31b.
* client/authority-discovery: Remove unused import PeerId
* client/authority-discovery/tests: Add tcp protocol to multiaddresses
This commit is contained in:
@@ -58,19 +58,26 @@ use futures::task::{Context, Poll};
|
||||
use futures::{Future, FutureExt, ready, Stream, StreamExt};
|
||||
use futures_timer::Delay;
|
||||
|
||||
use addr_cache::AddrCache;
|
||||
use codec::Decode;
|
||||
use error::{Error, Result};
|
||||
use libp2p::core::multiaddr;
|
||||
use log::{debug, error, log_enabled};
|
||||
use prometheus_endpoint::{Counter, CounterVec, Gauge, Opts, U64, register};
|
||||
use prost::Message;
|
||||
use sc_client_api::blockchain::HeaderBackend;
|
||||
use sc_network::{Multiaddr, config::MultiaddrWithPeerId, DhtEvent, ExHashT, NetworkStateInfo};
|
||||
use sc_network::{
|
||||
config::MultiaddrWithPeerId,
|
||||
DhtEvent,
|
||||
ExHashT,
|
||||
Multiaddr,
|
||||
NetworkStateInfo,
|
||||
};
|
||||
use sp_authority_discovery::{AuthorityDiscoveryApi, AuthorityId, AuthoritySignature, AuthorityPair};
|
||||
use sp_core::crypto::{key_types, Pair};
|
||||
use sp_core::traits::BareCryptoStorePtr;
|
||||
use sp_runtime::{traits::Block as BlockT, generic::BlockId};
|
||||
use sp_api::ProvideRuntimeApi;
|
||||
use addr_cache::AddrCache;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
@@ -233,7 +240,7 @@ where
|
||||
.collect(),
|
||||
None => self.network.external_addresses()
|
||||
.into_iter()
|
||||
.map(|a| a.with(libp2p::core::multiaddr::Protocol::P2p(
|
||||
.map(|a| a.with(multiaddr::Protocol::P2p(
|
||||
self.network.local_peer_id().into(),
|
||||
)))
|
||||
.map(|a| a.to_vec())
|
||||
@@ -423,6 +430,8 @@ where
|
||||
.get(&remote_key)
|
||||
.ok_or(Error::MatchingHashedAuthorityIdWithAuthorityId)?;
|
||||
|
||||
let local_peer_id = multiaddr::Protocol::P2p(self.network.local_peer_id().into());
|
||||
|
||||
let remote_addresses: Vec<Multiaddr> = values.into_iter()
|
||||
.map(|(_k, v)| {
|
||||
let schema::SignedAuthorityAddresses { signature, addresses } =
|
||||
@@ -447,7 +456,13 @@ where
|
||||
Ok(addresses)
|
||||
})
|
||||
.collect::<Result<Vec<Vec<Multiaddr>>>>()?
|
||||
.into_iter().flatten().collect();
|
||||
.into_iter()
|
||||
.flatten()
|
||||
// Ignore own addresses.
|
||||
.filter(|addr| !addr.iter().any(|protocol|
|
||||
protocol == local_peer_id
|
||||
))
|
||||
.collect();
|
||||
|
||||
if !remote_addresses.is_empty() {
|
||||
self.addr_cache.insert(authority_id.clone(), remote_addresses);
|
||||
|
||||
Reference in New Issue
Block a user