kill rent calculator (#6625)

This commit is contained in:
Rob Walker
2019-10-30 16:25:12 -07:00
committed by GitHub
parent d2d78a073f
commit fa12a5f70b
14 changed files with 74 additions and 86 deletions

View File

@ -473,7 +473,7 @@ impl Bank {
fn update_rent(&self) {
self.store_account(
&sysvar::rent::id(),
&sysvar::rent::create_account(1, &self.rent_collector.rent_calculator),
&sysvar::rent::create_account(1, &self.rent_collector.rent),
);
}
@ -679,12 +679,11 @@ 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,
&genesis_block.rent,
);
// Add additional native programs specified in the genesis block
@ -705,9 +704,7 @@ impl Bank {
}
pub fn get_minimum_balance_for_rent_exemption(&self, data_len: usize) -> u64 {
self.rent_collector
.rent_calculator
.minimum_balance(data_len)
self.rent_collector.rent.minimum_balance(data_len)
}
pub fn last_blockhash_with_fee_calculator(&self) -> (Hash, FeeCalculator) {
@ -1641,7 +1638,7 @@ mod tests {
hash,
instruction::InstructionError,
poh_config::PohConfig,
rent_calculator::RentCalculator,
rent::Rent,
signature::{Keypair, KeypairUtil},
system_instruction, system_transaction,
sysvar::{fees::Fees, rewards::Rewards},
@ -1669,7 +1666,7 @@ mod tests {
&dummy_leader_pubkey,
dummy_leader_lamports,
);
genesis_block.rent_calculator = RentCalculator {
genesis_block.rent = Rent {
lamports_per_byte_year: 5,
exemption_threshold: 1.2,
burn_percent: 5,
@ -1685,9 +1682,9 @@ mod tests {
let rent_account = bank.get_account(&sysvar::rent::id()).unwrap();
let rent = sysvar::rent::Rent::from_account(&rent_account).unwrap();
assert_eq!(rent.rent_calculator.burn_percent, 5);
assert_eq!(rent.rent_calculator.exemption_threshold, 1.2);
assert_eq!(rent.rent_calculator.lamports_per_byte_year, 5);
assert_eq!(rent.burn_percent, 5);
assert_eq!(rent.exemption_threshold, 1.2);
assert_eq!(rent.lamports_per_byte_year, 5);
}
#[test]

View File

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