From bac529779bbf9083c446bd70d6f9fa4f5ebc24f8 Mon Sep 17 00:00:00 2001 From: HaoranYi Date: Sun, 21 Aug 2022 16:20:51 -0500 Subject: [PATCH] Refactor epoch reward 3 (#27259) * refactor: extract store_stake_accounts fn * refactor: extract store_vote_account fn * refactor: extract reward history update fn * clippy: slice * clippy: slice Co-authored-by: haoran --- runtime/src/bank.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index ff989f44135ef8..14e1d42d896abc 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -3295,6 +3295,21 @@ impl Bank { >>>>>>> c17f15a34f (Refactor epoch reward 2 (#27257)) } + fn update_reward_history( + &self, + stake_rewards: Vec, + mut vote_rewards: Vec<(Pubkey, RewardInfo)>, + ) { + let additional_reserve = stake_rewards.len() + vote_rewards.len(); + let mut rewards = self.rewards.write().unwrap(); + rewards.reserve(additional_reserve); + rewards.append(&mut vote_rewards); + stake_rewards + .into_iter() + .filter(|x| x.get_stake_reward() > 0) + .for_each(|x| rewards.push((x.stake_pubkey, x.stake_reward_info))); + } + fn update_recent_blockhashes_locked(&self, locked_blockhash_queue: &BlockhashQueue) { #[allow(deprecated)] self.update_sysvar_account(&sysvar::recent_blockhashes::id(), |account| {