removes legacy compatibility turbine peers shuffle code
This commit is contained in:
@ -1,12 +1,13 @@
|
||||
#![allow(clippy::integer_arithmetic)]
|
||||
use {
|
||||
crossbeam_channel::{unbounded, Receiver, Sender, TryRecvError},
|
||||
itertools::Itertools,
|
||||
rayon::{iter::ParallelIterator, prelude::*},
|
||||
serial_test::serial,
|
||||
solana_gossip::{
|
||||
cluster_info::{compute_retransmit_peers, ClusterInfo},
|
||||
contact_info::ContactInfo,
|
||||
deprecated::{shuffle_peers_and_index, sorted_retransmit_peers_and_stakes},
|
||||
weighted_shuffle::weighted_shuffle,
|
||||
},
|
||||
solana_sdk::{pubkey::Pubkey, signer::keypair::Keypair},
|
||||
solana_streamer::socket::SocketAddrSpace,
|
||||
@ -32,6 +33,75 @@ fn find_insert_shred(id: &Pubkey, shred: i32, batches: &mut [Nodes]) {
|
||||
});
|
||||
}
|
||||
|
||||
fn sorted_retransmit_peers_and_stakes(
|
||||
cluster_info: &ClusterInfo,
|
||||
stakes: Option<&HashMap<Pubkey, u64>>,
|
||||
) -> (Vec<ContactInfo>, Vec<(u64, usize)>) {
|
||||
let mut peers = cluster_info.tvu_peers();
|
||||
// insert "self" into this list for the layer and neighborhood computation
|
||||
peers.push(cluster_info.my_contact_info());
|
||||
let stakes_and_index = sorted_stakes_with_index(&peers, stakes);
|
||||
(peers, stakes_and_index)
|
||||
}
|
||||
|
||||
fn sorted_stakes_with_index(
|
||||
peers: &[ContactInfo],
|
||||
stakes: Option<&HashMap<Pubkey, u64>>,
|
||||
) -> Vec<(u64, usize)> {
|
||||
let stakes_and_index: Vec<_> = peers
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, c)| {
|
||||
// For stake weighted shuffle a valid weight is atleast 1. Weight 0 is
|
||||
// assumed to be missing entry. So let's make sure stake weights are atleast 1
|
||||
let stake = 1.max(
|
||||
stakes
|
||||
.as_ref()
|
||||
.map_or(1, |stakes| *stakes.get(&c.id).unwrap_or(&1)),
|
||||
);
|
||||
(stake, i)
|
||||
})
|
||||
.sorted_by(|(l_stake, l_info), (r_stake, r_info)| {
|
||||
if r_stake == l_stake {
|
||||
peers[*r_info].id.cmp(&peers[*l_info].id)
|
||||
} else {
|
||||
r_stake.cmp(l_stake)
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
stakes_and_index
|
||||
}
|
||||
|
||||
fn shuffle_peers_and_index(
|
||||
id: &Pubkey,
|
||||
peers: &[ContactInfo],
|
||||
stakes_and_index: &[(u64, usize)],
|
||||
seed: [u8; 32],
|
||||
) -> (usize, Vec<(u64, usize)>) {
|
||||
let shuffled_stakes_and_index = stake_weighted_shuffle(stakes_and_index, seed);
|
||||
let self_index = shuffled_stakes_and_index
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find_map(|(i, (_stake, index))| {
|
||||
if peers[*index].id == *id {
|
||||
Some(i)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.unwrap();
|
||||
(self_index, shuffled_stakes_and_index)
|
||||
}
|
||||
|
||||
fn stake_weighted_shuffle(stakes_and_index: &[(u64, usize)], seed: [u8; 32]) -> Vec<(u64, usize)> {
|
||||
let stake_weights = stakes_and_index.iter().map(|(w, _)| *w);
|
||||
|
||||
let shuffle = weighted_shuffle(stake_weights, seed);
|
||||
|
||||
shuffle.iter().map(|x| stakes_and_index[*x]).collect()
|
||||
}
|
||||
|
||||
fn retransmit(
|
||||
mut shuffled_nodes: Vec<ContactInfo>,
|
||||
senders: &HashMap<Pubkey, Sender<(i32, bool)>>,
|
||||
|
Reference in New Issue
Block a user