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
This commit is contained in:
Jeff Washington (jwash) 2021-04-30 16:19:20 -05:00 committed by GitHub
parent 763c04adf3
commit 01308cd890
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 10 deletions

View File

@ -3374,16 +3374,28 @@ impl Bank {
let mut account = self let mut account = self
.get_account_with_fixed_root(&pubkey) .get_account_with_fixed_root(&pubkey)
.unwrap_or_default(); .unwrap_or_default();
account.lamports += rent_to_be_paid; if account.checked_add_lamports(rent_to_be_paid).is_err() {
self.store_account(&pubkey, &account); // overflow adding lamports
rewards.push(( self.capitalization.fetch_sub(rent_to_be_paid, Relaxed);
pubkey, error!(
RewardInfo { "Burned {} rent lamports instead of sending to {}",
reward_type: RewardType::Rent, rent_to_be_paid, pubkey
lamports: rent_to_be_paid as i64, );
post_balance: account.lamports(), 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); self.rewards.write().unwrap().append(&mut rewards);