pub(crate) fn refresh_push_active_set(
        &self,
        crds: &RwLock<Crds>,
        stakes: &HashMap<Pubkey, u64>,
        gossip_validators: Option<&HashSet<Pubkey>>,
        self_id: &Pubkey,
        self_shred_version: u16,
        network_size: usize,
        ratio: usize,
        socket_addr_space: &SocketAddrSpace,
    ) {
        const BLOOM_FALSE_RATE: f64 = 0.1;
        const BLOOM_MAX_BITS: usize = 1024 * 8 * 4;
        #[cfg(debug_assertions)]
        const MIN_NUM_BLOOM_ITEMS: usize = 512;
        #[cfg(not(debug_assertions))]
        const MIN_NUM_BLOOM_ITEMS: usize = CRDS_UNIQUE_PUBKEY_CAPACITY;
        let mut rng = rand::thread_rng();
        let mut new_items = HashMap::new();
        let (weights, peers): (Vec<_>, Vec<_>) = {
            self.push_options(
                crds,
                self_id,
                self_shred_version,
                stakes,
                gossip_validators,
                socket_addr_space,
            )
            .into_iter()
            .unzip()
        };
        if peers.is_empty() {
            return;
        }
        let num_bloom_items = MIN_NUM_BLOOM_ITEMS.max(network_size);
        let shuffle = WeightedShuffle::new(&mut rng, &weights).unwrap();
        let mut active_set = self.active_set.write().unwrap();
        let need = Self::compute_need(self.num_active, active_set.len(), ratio);
        for peer in shuffle.map(|i| peers[i]) {
            if new_items.len() >= need {
                break;
            }
            if active_set.contains_key(&peer) || new_items.contains_key(&peer) {
                continue;
            }
            let bloom = AtomicBloom::from(Bloom::random(
                num_bloom_items,
                BLOOM_FALSE_RATE,
                BLOOM_MAX_BITS,
            ));
            bloom.add(&peer);
            new_items.insert(peer, bloom);
        }
        let mut keys: Vec<Pubkey> = active_set.keys().cloned().collect();
        keys.shuffle(&mut rng);
        let num = keys.len() / ratio;
        for k in &keys[..num] {
            active_set.swap_remove(k);
        }
        for (k, v) in new_items {
            active_set.insert(k, v);
        }
    }
/// Refresh the push active set.
///
/// # Arguments
///
/// * ratio - active_set.len()/ratio is the number of actives to rotate
Refresh the push active set.
Refresh the push active set .
pub(crate) fn refresh_push_active_set(
        &self,
        crds: &RwLock<Crds>,
        stakes: &HashMap<Pubkey, u64>,
        gossip_validators: Option<&HashSet<Pubkey>>,
        self_id: &Pubkey,
        self_shred_version: u16,
        network_size: usize,
        ratio: usize,
        socket_addr_space: &SocketAddrSpace,
    ) {
        const BLOOM_FALSE_RATE: f64 = 0.1;
        const BLOOM_MAX_BITS: usize = 1024 * 8 * 4;
        #[cfg(debug_assertions)]
        const MIN_NUM_BLOOM_ITEMS: usize = 512;
        #[cfg(not(debug_assertions))]
        const MIN_NUM_BLOOM_ITEMS: usize = CRDS_UNIQUE_PUBKEY_CAPACITY;
        let mut rng = rand::thread_rng();
        let mut new_items = HashMap::new();
        let (weights, peers): (Vec<_>, Vec<_>) = {
            self.push_options(
                crds,
                self_id,
                self_shred_version,
                stakes,
                gossip_validators,
                socket_addr_space,
            )
            .into_iter()
            .unzip()
        };
        if peers.is_empty() {
            return;
        }
        let num_bloom_items = MIN_NUM_BLOOM_ITEMS.max(network_size);
        let shuffle = WeightedShuffle::new(&mut rng, &weights).unwrap();
        let mut active_set = self.active_set.write().unwrap();
        let need = Self::compute_need(self.num_active, active_set.len(), ratio);
        for peer in shuffle.map(|i| peers[i]) {
            if new_items.len() >= need {
                break;
            }
            if active_set.contains_key(&peer) || new_items.contains_key(&peer) {
                continue;
            }
            let bloom = AtomicBloom::from(Bloom::random(
                num_bloom_items,
                BLOOM_FALSE_RATE,
                BLOOM_MAX_BITS,
            ));
            bloom.add(&peer);
            new_items.insert(peer, bloom);
        }
        let mut keys: Vec<Pubkey> = active_set.keys().cloned().collect();
        keys.shuffle(&mut rng);
        let num = keys.len() / ratio;
        for k in &keys[..num] {
            active_set.swap_remove(k);
        }
        for (k, v) in new_items {
            active_set.insert(k, v);
        }
    }
pub ( crate ) fn refresh_push_active_set ( & self , crds : & RwLock < Crds > , stakes : & HashMap < Pubkey , u64 > , gossip_validators : Option < & HashSet < Pubkey > > , self_id : & Pubkey , self_shred_version : u16 , network_size : usize , ratio : usize , socket_addr_space : & SocketAddrSpace , ) { const BLOOM_FALSE_RATE : f64 = 0.1 ; const BLOOM_MAX_BITS : usize = 1024 * 8 * 4 ; # [ cfg ( debug_assertions ) ] const MIN_NUM_BLOOM_ITEMS : usize = 512 ; # [ cfg ( not ( debug_assertions ) ) ] const MIN_NUM_BLOOM_ITEMS : usize = CRDS_UNIQUE_PUBKEY_CAPACITY ; let mut rng = rand :: thread_rng ( ) ; let mut new_items = HashMap :: new ( ) ; let ( weights , peers ) : ( Vec < _ > , Vec < _ > ) = { self . push_options ( crds , self_id , self_shred_version , stakes , gossip_validators , socket_addr_space , ) . into_iter ( ) . unzip ( ) } ; if peers . is_empty ( ) { return ; } let num_bloom_items = MIN_NUM_BLOOM_ITEMS . max ( network_size ) ; let shuffle = WeightedShuffle :: new ( & mut rng , & weights ) . unwrap ( ) ; let mut active_set = self . active_set . write ( ) . unwrap ( ) ; let need = Self :: compute_need ( self . num_active , active_set . len ( ) , ratio ) ; for peer in shuffle . map ( | i | peers [ i ] ) { if new_items . len ( ) >= need { break ; } if active_set . contains_key ( & peer ) || new_items . contains_key ( & peer ) { continue ; } let bloom = AtomicBloom :: from ( Bloom :: random ( num_bloom_items , BLOOM_FALSE_RATE , BLOOM_MAX_BITS , ) ) ; bloom . add ( & peer ) ; new_items . insert ( peer , bloom ) ; } let mut keys : Vec < Pubkey > = active_set . keys ( ) . cloned ( ) . collect ( ) ; keys . shuffle ( & mut rng ) ; let num = keys . len ( ) / ratio ; for k in & keys [ .. num ] { active_set . swap_remove ( k ) ; } for ( k , v ) in new_items { active_set . insert ( k , v ) ; } }
Refresh the push active set.
Refresh the push active set .
&self
crds
&RwLock<Crds>
stakes
&HashMap<Pubkey, u64>
gossip_validators
Option<&HashSet<Pubkey>>
self_id
&Pubkey
self_shred_version
u16
network_size
usize
ratio
usize
socket_addr_space
&SocketAddrSpace