Fix stake split rent-exempt adjustment (#13357)

* Add failing tests

* Fix stake split

* Calculate split rent-exempt-reserve and use

* Add comment in rent.rs

* Add tests for edge cases when splitting to larger accounts, and reject overflow splits

* Reframe InsufficientFunds checks in terms of lamports var

* Test hardening review comments
This commit is contained in:
Tyera Eulberg
2020-11-06 13:32:05 -07:00
committed by GitHub
parent 0ea795caa8
commit 4c5f345798
2 changed files with 694 additions and 26 deletions

View File

@ -46,6 +46,10 @@ impl Rent {
(burned_portion, rent_collected - burned_portion)
}
/// minimum balance due for a given size Account::data.len()
///
/// Note: a stripped-down version of this calculation is used in
/// calculate_split_rent_exempt_reserve in the stake program. When this function is updated, --
/// eg. when making rent variable -- the stake program will need to be refactored
pub fn minimum_balance(&self, data_len: usize) -> u64 {
let bytes = data_len as u64;
(((ACCOUNT_STORAGE_OVERHEAD + bytes) * self.lamports_per_byte_year) as f64