From 01308cd890701131d87116385405dc5a8db41bfb Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" <75863576+jeffwashington@users.noreply.github.com> Date: Fri, 30 Apr 2021 16:19:20 -0500 Subject: [PATCH] distribute_rent_to_validators checked_add_lamports unwrap (#16847) * distribute_rent_to_validators checked_add_lamports unwrap * make rent disappear on add failure * add pubkey to message * update message text * don't store account that we failed to transfer to * format --- runtime/src/bank.rs | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 7ec107845c..afea2db4b7 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -3374,16 +3374,28 @@ impl Bank { let mut account = self .get_account_with_fixed_root(&pubkey) .unwrap_or_default(); - account.lamports += rent_to_be_paid; - self.store_account(&pubkey, &account); - rewards.push(( - pubkey, - RewardInfo { - reward_type: RewardType::Rent, - lamports: rent_to_be_paid as i64, - post_balance: account.lamports(), - }, - )); + if account.checked_add_lamports(rent_to_be_paid).is_err() { + // overflow adding lamports + self.capitalization.fetch_sub(rent_to_be_paid, Relaxed); + error!( + "Burned {} rent lamports instead of sending to {}", + rent_to_be_paid, pubkey + ); + inc_new_counter_error!( + "bank-burned_rent_lamports", + rent_to_be_paid as usize + ); + } else { + self.store_account(&pubkey, &account); + rewards.push(( + pubkey, + RewardInfo { + reward_type: RewardType::Rent, + lamports: rent_to_be_paid as i64, + post_balance: account.lamports(), + }, + )); + } } }); self.rewards.write().unwrap().append(&mut rewards);