rent collector improvments (#6888)

* avoid account copying + pre-empt rent

* adding support for base rent
This commit is contained in:
Parth
2019-11-14 10:56:49 +05:30
committed by GitHub
parent c96b8c8d68
commit 7b05b3dbb3
5 changed files with 56 additions and 19 deletions

View File

@ -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);

View File

@ -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
}
}
}