From 58ce19446f4f09ba43d293203d9e7b35c679227e Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" Date: Mon, 1 May 2023 12:42:05 -0500 Subject: [PATCH] replace tuple with `VoteReward` struct (#31408) --- runtime/src/bank.rs | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index b3e36ba307..ecad2a62bd 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -1081,7 +1081,14 @@ struct LoadVoteAndStakeAccountsResult { vote_accounts_cache_miss_count: usize, } -type VoteRewards = DashMap; +struct VoteReward { + vote_account: AccountSharedData, + commission: u8, + vote_rewards: u64, + vote_needs_store: bool, +} + +type VoteRewards = DashMap; type StakeRewards = Vec; #[derive(Debug, Default)] @@ -2920,8 +2927,15 @@ impl Bank { delegations, }, )| { - vote_account_rewards - .insert(vote_pubkey, (vote_account, vote_state.commission, 0, false)); + vote_account_rewards.insert( + vote_pubkey, + VoteReward { + vote_account, + commission: vote_state.commission, + vote_rewards: 0, + vote_needs_store: false, + }, + ); delegations .into_par_iter() .map(move |delegation| (vote_pubkey, Arc::clone(&vote_state), delegation)) @@ -2952,12 +2966,12 @@ impl Bank { ); if let Ok((stakers_reward, voters_reward)) = redeemed { // track voter rewards - if let Some(( - _vote_account, - _commission, - vote_rewards_sum, + if let Some(VoteReward { + vote_account: _, + commission: _, + vote_rewards: vote_rewards_sum, vote_needs_store, - )) = vote_account_rewards.get_mut(&vote_pubkey).as_deref_mut() + }) = vote_account_rewards.get_mut(&vote_pubkey).as_deref_mut() { *vote_needs_store = true; *vote_rewards_sum = vote_rewards_sum.saturating_add(voters_reward); @@ -3007,7 +3021,15 @@ impl Bank { let (vote_rewards, measure) = measure!(vote_account_rewards .into_iter() .filter_map( - |(vote_pubkey, (mut vote_account, commission, vote_rewards, vote_needs_store))| { + |( + vote_pubkey, + VoteReward { + mut vote_account, + commission, + vote_rewards, + vote_needs_store, + }, + )| { if let Err(err) = vote_account.checked_add_lamports(vote_rewards) { debug!("reward redemption failed for {}: {:?}", vote_pubkey, err); return None;