Skip to content

Commit

Permalink
Remove more old rewards logic: StakesCache helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
CriesofCarrots committed Dec 19, 2024
1 parent db82c35 commit 94d2251
Showing 1 changed file with 1 addition and 74 deletions.
75 changes: 1 addition & 74 deletions runtime/src/stakes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
//! node stakes
use {
crate::{stake_account, stake_history::StakeHistory},
dashmap::DashMap,
im::HashMap as ImHashMap,
log::error,
num_derive::ToPrimitive,
num_traits::ToPrimitive,
rayon::{prelude::*, ThreadPool},
solana_accounts_db::stake_rewards::StakeReward,
solana_sdk::{
account::{AccountSharedData, ReadableAccount},
clock::{Epoch, Slot},
clock::Epoch,
pubkey::Pubkey,
stake::state::{Delegation, StakeActivationStatus},
vote::state::VoteStateVersions,
Expand Down Expand Up @@ -150,43 +147,6 @@ impl StakesCache {
let mut stakes = self.0.write().unwrap();
stakes.activate_epoch(next_epoch, thread_pool, new_rate_activation_epoch)
}

pub(crate) fn update_stake_accounts(
&self,
thread_pool: &ThreadPool,
stake_rewards: &[StakeReward],
new_rate_activation_epoch: Option<Epoch>,
) {
self.0.write().unwrap().update_stake_accounts(
thread_pool,
stake_rewards,
new_rate_activation_epoch,
)
}

pub(crate) fn handle_invalid_keys(
&self,
invalid_vote_keys: DashMap<Pubkey, InvalidCacheEntryReason>,
current_slot: Slot,
) {
if invalid_vote_keys.is_empty() {
return;
}

// Prune invalid stake delegations and vote accounts that were
// not properly evicted in normal operation.
let mut stakes = self.0.write().unwrap();

for (vote_pubkey, reason) in invalid_vote_keys {
stakes.remove_vote_account(&vote_pubkey);
datapoint_warn!(
"bank-stake_delegation_accounts-invalid-account",
("slot", current_slot as i64, i64),
("vote-address", format!("{vote_pubkey:?}"), String),
("reason", reason.to_i64().unwrap_or_default(), i64),
);
}
}
}

/// The generic type T is either Delegation or StakeAccount.
Expand Down Expand Up @@ -464,39 +424,6 @@ impl Stakes<StakeAccount> {
}
}

fn update_stake_accounts(
&mut self,
thread_pool: &ThreadPool,
stake_rewards: &[StakeReward],
new_rate_activation_epoch: Option<Epoch>,
) {
let stake_delegations: Vec<_> = thread_pool.install(|| {
stake_rewards
.into_par_iter()
.filter_map(|stake_reward| {
let stake_account = StakeAccount::try_from(stake_reward.stake_account.clone());
Some((stake_reward.stake_pubkey, stake_account.ok()?))
})
.collect()
});
self.stake_delegations = std::mem::take(&mut self.stake_delegations)
.into_iter()
.chain(stake_delegations)
.collect::<HashMap<Pubkey, StakeAccount>>()
.into_iter()
.filter(|(_, account)| account.lamports() != 0u64)
.collect();
let stake_delegations: Vec<_> = self.stake_delegations.values().collect();
self.vote_accounts = refresh_vote_accounts(
thread_pool,
self.epoch,
&self.vote_accounts,
&stake_delegations,
&self.stake_history,
new_rate_activation_epoch,
);
}

pub(crate) fn stake_delegations(&self) -> &ImHashMap<Pubkey, StakeAccount> {
&self.stake_delegations
}
Expand Down

0 comments on commit 94d2251

Please sign in to comment.