mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-20 05:51:02 +00:00
client/authority-discovery: Limit the amount of sentries per authority (#4302)
When receiving more addresses for a given authority than a defined threshold (5), the authority discovery drops the remaining in order to prevent a single authority to fill all priority group slots.
This commit is contained in:
Generated
+1
@@ -4814,6 +4814,7 @@ version = "2.0.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
"bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"derive_more 0.99.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"derive_more 0.99.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"futures-timer 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"futures-timer 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"libp2p 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libp2p 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ serde_json = "1.0.41"
|
|||||||
sp-runtime = { path = "../../primitives/sr-primitives" }
|
sp-runtime = { path = "../../primitives/sr-primitives" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
env_logger = "0.7.0"
|
||||||
parking_lot = "0.9.0"
|
parking_lot = "0.9.0"
|
||||||
peerset = { package = "sc-peerset", path = "../peerset" }
|
peerset = { package = "sc-peerset", path = "../peerset" }
|
||||||
test-client = { package = "substrate-test-runtime-client", path = "../../test/utils/runtime/client" }
|
test-client = { package = "substrate-test-runtime-client", path = "../../test/utils/runtime/client" }
|
||||||
|
|||||||
@@ -86,6 +86,12 @@ const LIBP2P_KADEMLIA_BOOTSTRAP_TIME: Duration = Duration::from_secs(30);
|
|||||||
/// discovery module.
|
/// discovery module.
|
||||||
const AUTHORITIES_PRIORITY_GROUP_NAME: &'static str = "authorities";
|
const AUTHORITIES_PRIORITY_GROUP_NAME: &'static str = "authorities";
|
||||||
|
|
||||||
|
/// The maximum number of sentry node public addresses that we accept per authority.
|
||||||
|
///
|
||||||
|
/// Everything above this threshold should be dropped to prevent a single authority from filling up
|
||||||
|
/// our peer set priority group.
|
||||||
|
const MAX_NUM_SENTRY_ADDRESSES_PER_AUTHORITY: usize = 5;
|
||||||
|
|
||||||
/// An `AuthorityDiscovery` makes a given authority discoverable and discovers other authorities.
|
/// An `AuthorityDiscovery` makes a given authority discoverable and discovers other authorities.
|
||||||
pub struct AuthorityDiscovery<Client, Network, Block>
|
pub struct AuthorityDiscovery<Client, Network, Block>
|
||||||
where
|
where
|
||||||
@@ -316,7 +322,7 @@ where
|
|||||||
return Err(Error::VerifyingDhtPayload);
|
return Err(Error::VerifyingDhtPayload);
|
||||||
}
|
}
|
||||||
|
|
||||||
let addresses: Vec<libp2p::Multiaddr> = schema::AuthorityAddresses::decode(addresses)
|
let mut addresses: Vec<libp2p::Multiaddr> = schema::AuthorityAddresses::decode(addresses)
|
||||||
.map(|a| a.addresses)
|
.map(|a| a.addresses)
|
||||||
.map_err(Error::DecodingProto)?
|
.map_err(Error::DecodingProto)?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@@ -324,6 +330,18 @@ where
|
|||||||
.collect::<std::result::Result<_, _>>()
|
.collect::<std::result::Result<_, _>>()
|
||||||
.map_err(Error::ParsingMultiaddress)?;
|
.map_err(Error::ParsingMultiaddress)?;
|
||||||
|
|
||||||
|
if addresses.len() > MAX_NUM_SENTRY_ADDRESSES_PER_AUTHORITY {
|
||||||
|
warn!(
|
||||||
|
target: "sub-authority-discovery",
|
||||||
|
"Got more than MAX_NUM_SENTRY_ADDRESSES_PER_AUTHORITY ({:?}) for Authority
|
||||||
|
'{:?}' from DHT, dropping the remainder.",
|
||||||
|
MAX_NUM_SENTRY_ADDRESSES_PER_AUTHORITY, authority_id,
|
||||||
|
);
|
||||||
|
addresses = addresses.into_iter()
|
||||||
|
.take(MAX_NUM_SENTRY_ADDRESSES_PER_AUTHORITY)
|
||||||
|
.collect();
|
||||||
|
}
|
||||||
|
|
||||||
self.address_cache.insert(authority_id.clone(), addresses);
|
self.address_cache.insert(authority_id.clone(), addresses);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -800,6 +818,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn handle_dht_events_with_value_found_should_call_set_priority_group() {
|
fn handle_dht_events_with_value_found_should_call_set_priority_group() {
|
||||||
|
let _ = ::env_logger::try_init();
|
||||||
// Create authority discovery.
|
// Create authority discovery.
|
||||||
|
|
||||||
let (mut dht_event_tx, dht_event_rx) = channel(1000);
|
let (mut dht_event_tx, dht_event_rx) = channel(1000);
|
||||||
|
|||||||
Reference in New Issue
Block a user