Skip to content

Commit

Permalink
pr feedback: rename missed pubkey -> vote_pubkey
Browse files Browse the repository at this point in the history
  • Loading branch information
AshwinSekar committed Oct 3, 2024
1 parent 8171af5 commit eb5cb40
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions core/src/banking_stage/latest_unprocessed_votes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@ impl LatestUnprocessedVotes {
fn weighted_random_order_by_stake(&self) -> impl Iterator<Item = Pubkey> {
// Efraimidis and Spirakis algo for weighted random sample without replacement
let epoch_stakes = self.cached_epoch_stakes.read().unwrap();
let latest_votes_per_pubkey = self.latest_vote_per_vote_pubkey.read().unwrap();
let mut pubkey_with_weight: Vec<(f64, Pubkey)> = latest_votes_per_pubkey
let latest_vote_per_vote_pubkey = self.latest_vote_per_vote_pubkey.read().unwrap();
let mut pubkey_with_weight: Vec<(f64, Pubkey)> = latest_vote_per_vote_pubkey
.keys()
.filter_map(|&pubkey| {
let stake = epoch_stakes.vote_account_stake(&pubkey);
Expand Down Expand Up @@ -380,9 +380,9 @@ impl LatestUnprocessedVotes {

// Evict any now unstaked pubkeys
let epoch_stakes = self.cached_epoch_stakes.read().unwrap();
let mut latest_votes_per_pubkey = self.latest_vote_per_vote_pubkey.write().unwrap();
let mut latest_vote_per_vote_pubkey = self.latest_vote_per_vote_pubkey.write().unwrap();
let mut unstaked_votes = 0;
latest_votes_per_pubkey.retain(|vote_pubkey, vote| {
latest_vote_per_vote_pubkey.retain(|vote_pubkey, vote| {
let is_present = !vote.read().unwrap().is_vote_taken();
let should_evict = epoch_stakes.vote_account_stake(vote_pubkey) == 0;
if is_present && should_evict {
Expand Down Expand Up @@ -943,19 +943,21 @@ mod tests {
.update_latest_vote(vote, false /* should replenish */);
if i % 214 == 0 {
// Simulate draining and processing packets
let latest_votes_per_pubkey = latest_unprocessed_votes_tpu
let latest_vote_per_vote_pubkey = latest_unprocessed_votes_tpu
.latest_vote_per_vote_pubkey
.read()
.unwrap();
latest_votes_per_pubkey.iter().for_each(|(_pubkey, lock)| {
let mut latest_vote = lock.write().unwrap();
if !latest_vote.is_vote_taken() {
latest_vote.take_vote();
latest_unprocessed_votes_tpu
.num_unprocessed_votes
.fetch_sub(1, Ordering::Relaxed);
}
});
latest_vote_per_vote_pubkey
.iter()
.for_each(|(_pubkey, lock)| {
let mut latest_vote = lock.write().unwrap();
if !latest_vote.is_vote_taken() {
latest_vote.take_vote();
latest_unprocessed_votes_tpu
.num_unprocessed_votes
.fetch_sub(1, Ordering::Relaxed);
}
});
}
}
})
Expand Down

0 comments on commit eb5cb40

Please sign in to comment.