rent collector improvments (#6888)
* avoid account copying + pre-empt rent * adding support for base rent
This commit is contained in:
@ -114,7 +114,10 @@ impl Accounts {
|
||||
.filter(|key| !message.program_ids().contains(key))
|
||||
{
|
||||
let (account, rent) = AccountsDB::load(storage, ancestors, accounts_index, key)
|
||||
.and_then(|(account, _)| rent_collector.update(account))
|
||||
.and_then(|(mut account, _)| {
|
||||
let rent_due = rent_collector.update(&mut account);
|
||||
Some((account, rent_due))
|
||||
})
|
||||
.unwrap_or_default();
|
||||
|
||||
accounts.push(account);
|
||||
|
@ -33,9 +33,9 @@ impl RentCollector {
|
||||
// updates this account's lamports and status and returns
|
||||
// the account rent collected, if any
|
||||
//
|
||||
pub fn update(&self, mut account: Account) -> Option<(Account, u64)> {
|
||||
if account.data.is_empty() || account.rent_epoch > self.epoch {
|
||||
Some((account, 0))
|
||||
pub fn update(&self, account: &mut Account) -> u64 {
|
||||
if account.rent_epoch > self.epoch {
|
||||
0
|
||||
} else {
|
||||
let slots_elapsed: u64 = (account.rent_epoch..=self.epoch)
|
||||
.map(|epoch| self.epoch_schedule.get_slots_in_epoch(epoch + 1))
|
||||
@ -51,13 +51,15 @@ impl RentCollector {
|
||||
if account.lamports > rent_due {
|
||||
account.rent_epoch = self.epoch + 1;
|
||||
account.lamports -= rent_due;
|
||||
Some((account, rent_due))
|
||||
rent_due
|
||||
} else {
|
||||
None
|
||||
let rent_charged = account.lamports;
|
||||
*account = Account::default();
|
||||
rent_charged
|
||||
}
|
||||
} else {
|
||||
// maybe collect rent later, leave account alone
|
||||
Some((account, 0))
|
||||
0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user