mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-01 06:37:56 +00:00
gossip: choose a random subset on send instead of limiting connections (#2776)
* gossip: choose random subset on send * naming bikeshed
This commit is contained in:
@@ -52,6 +52,7 @@ use thiserror::Error;
|
||||
|
||||
pub mod validator_discovery;
|
||||
pub use metered_channel as metered;
|
||||
pub use polkadot_node_network_protocol::MIN_GOSSIP_PEERS;
|
||||
|
||||
/// These reexports are required so that external crates can use the `delegated_subsystem` macro properly.
|
||||
pub mod reexports {
|
||||
@@ -267,6 +268,18 @@ pub async fn signing_key(validators: &[ValidatorId], keystore: SyncCryptoStorePt
|
||||
None
|
||||
}
|
||||
|
||||
/// Chooses a random subset of sqrt(v.len()), but at least `min` elements.
|
||||
pub fn choose_random_sqrt_subset<T>(mut v: Vec<T>, min: usize) -> Vec<T> {
|
||||
use rand::seq::SliceRandom as _;
|
||||
let mut rng = rand::thread_rng();
|
||||
v.shuffle(&mut rng);
|
||||
|
||||
let len_sqrt = (v.len() as f64).sqrt() as usize;
|
||||
let len = std::cmp::max(min, len_sqrt);
|
||||
v.truncate(len);
|
||||
v
|
||||
}
|
||||
|
||||
/// Local validator information
|
||||
///
|
||||
/// It can be created if the local node is a validator in the context of a particular
|
||||
|
||||
Reference in New Issue
Block a user