Rent tangential stuff (#5910)

* rename rent.rs to rent_calculator.rs

* add rent sysvar

* integrate rent_calculator with bank

* rent_calculator integration with genesis

* add test for rent sysvar
This commit is contained in:
Parth
2019-09-17 17:12:55 +05:30
committed by GitHub
parent b31d334ef4
commit d63518a835
11 changed files with 157 additions and 30 deletions

View File

@ -41,7 +41,7 @@ use solana_sdk::{
signature::{Keypair, Signature},
system_transaction,
sysvar::{
clock, fees, rewards,
clock, fees, rent, rewards,
slot_hashes::{self, SlotHashes},
stake_history,
},
@ -354,6 +354,7 @@ impl Bank {
new.update_stake_history(Some(parent.epoch()));
new.update_clock();
new.update_fees();
new.update_rent();
new
}
@ -426,6 +427,13 @@ impl Bank {
self.store_account(&fees::id(), &fees::create_account(1, &self.fee_calculator));
}
fn update_rent(&self) {
self.store_account(
&rent::id(),
&rent::create_account(1, &self.rent_collector.rent_calculator),
);
}
fn update_stake_history(&self, epoch: Option<Epoch>) {
if epoch == Some(self.epoch()) {
return;
@ -620,6 +628,14 @@ impl Bank {
self.inflation = genesis_block.inflation;
let rent_calculator = genesis_block.rent_calculator;
self.rent_collector = RentCollector::new(
self.epoch,
&self.epoch_schedule,
self.slots_per_year,
&rent_calculator,
);
// Add additional native programs specified in the genesis block
for (name, program_id) in &genesis_block.native_instruction_processors {
self.register_native_instruction_processor(name, program_id);

View File

@ -1,13 +1,13 @@
//! calculate and collect rent from Accounts
use crate::epoch_schedule::EpochSchedule;
use solana_sdk::{account::Account, clock::Epoch, rent::Rent};
use solana_sdk::{account::Account, clock::Epoch, rent_calculator::RentCalculator};
#[derive(Default, Serialize, Deserialize, Clone)]
pub struct RentCollector {
pub epoch: Epoch,
pub epoch_schedule: EpochSchedule,
pub slots_per_year: f64,
pub rent: Rent,
pub rent_calculator: RentCalculator,
}
impl RentCollector {
@ -15,13 +15,13 @@ impl RentCollector {
epoch: Epoch,
epoch_schedule: &EpochSchedule,
slots_per_year: f64,
rent: &Rent,
rent_calculator: &RentCalculator,
) -> Self {
Self {
epoch,
epoch_schedule: *epoch_schedule,
slots_per_year,
rent: *rent,
rent_calculator: *rent_calculator,
}
}
@ -42,7 +42,7 @@ impl RentCollector {
.map(|epoch| self.epoch_schedule.get_slots_in_epoch(epoch + 1))
.sum();
let (rent_due, exempt) = self.rent.due(
let (rent_due, exempt) = self.rent_calculator.due(
account.lamports,
account.data.len(),
slots_elapsed as f64 / self.slots_per_year,