kill rent calculator (#6625)
This commit is contained in:
parent
d2d78a073f
commit
fa12a5f70b
|
@ -1327,8 +1327,8 @@ pub mod tests {
|
||||||
..
|
..
|
||||||
} = create_genesis_block(TEST_MINT_LAMPORTS);
|
} = create_genesis_block(TEST_MINT_LAMPORTS);
|
||||||
|
|
||||||
genesis_block.rent_calculator.lamports_per_byte_year = 50;
|
genesis_block.rent.lamports_per_byte_year = 50;
|
||||||
genesis_block.rent_calculator.exemption_threshold = 2.0;
|
genesis_block.rent.exemption_threshold = 2.0;
|
||||||
|
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
(
|
(
|
||||||
|
|
|
@ -591,8 +591,8 @@ pub fn new_validator_for_tests() -> (Validator, ContactInfo, Keypair, PathBuf) {
|
||||||
.native_instruction_processors
|
.native_instruction_processors
|
||||||
.push(solana_budget_program!());
|
.push(solana_budget_program!());
|
||||||
|
|
||||||
genesis_block.rent_calculator.lamports_per_byte_year = 1;
|
genesis_block.rent.lamports_per_byte_year = 1;
|
||||||
genesis_block.rent_calculator.exemption_threshold = 1.0;
|
genesis_block.rent.exemption_threshold = 1.0;
|
||||||
|
|
||||||
let (ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_block);
|
let (ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_block);
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ use solana_sdk::{
|
||||||
native_token::sol_to_lamports,
|
native_token::sol_to_lamports,
|
||||||
poh_config::PohConfig,
|
poh_config::PohConfig,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
rent_calculator::RentCalculator,
|
rent::Rent,
|
||||||
signature::{read_keypair_file, Keypair, KeypairUtil},
|
signature::{read_keypair_file, Keypair, KeypairUtil},
|
||||||
system_program, timing,
|
system_program, timing,
|
||||||
};
|
};
|
||||||
|
@ -86,11 +86,18 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
||||||
let default_target_signatures_per_slot = &FeeCalculator::default()
|
let default_target_signatures_per_slot = &FeeCalculator::default()
|
||||||
.target_signatures_per_slot
|
.target_signatures_per_slot
|
||||||
.to_string();
|
.to_string();
|
||||||
let default_lamports_per_byte_year =
|
let (
|
||||||
&RentCalculator::default().lamports_per_byte_year.to_string();
|
default_lamports_per_byte_year,
|
||||||
let default_rent_exemption_threshold =
|
default_rent_exemption_threshold,
|
||||||
&RentCalculator::default().exemption_threshold.to_string();
|
default_rent_burn_percentage,
|
||||||
let default_rent_burn_percentage = &RentCalculator::default().burn_percent.to_string();
|
) = {
|
||||||
|
let rent = Rent::default();
|
||||||
|
(
|
||||||
|
&rent.lamports_per_byte_year.to_string(),
|
||||||
|
&rent.exemption_threshold.to_string(),
|
||||||
|
&rent.burn_percent.to_string(),
|
||||||
|
)
|
||||||
|
};
|
||||||
let default_target_tick_duration =
|
let default_target_tick_duration =
|
||||||
&timing::duration_as_ms(&PohConfig::default().target_tick_duration).to_string();
|
&timing::duration_as_ms(&PohConfig::default().target_tick_duration).to_string();
|
||||||
let default_ticks_per_slot = &clock::DEFAULT_TICKS_PER_SLOT.to_string();
|
let default_ticks_per_slot = &clock::DEFAULT_TICKS_PER_SLOT.to_string();
|
||||||
|
@ -362,7 +369,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
||||||
value_t_or_exit!(matches, "target_signatures_per_slot", usize),
|
value_t_or_exit!(matches, "target_signatures_per_slot", usize),
|
||||||
);
|
);
|
||||||
|
|
||||||
let rent_calculator = RentCalculator {
|
let rent = Rent {
|
||||||
lamports_per_byte_year: value_t_or_exit!(matches, "lamports_per_byte_year", u64),
|
lamports_per_byte_year: value_t_or_exit!(matches, "lamports_per_byte_year", u64),
|
||||||
exemption_threshold: value_t_or_exit!(matches, "rent_exemption_threshold", f64),
|
exemption_threshold: value_t_or_exit!(matches, "rent_exemption_threshold", f64),
|
||||||
burn_percent: value_t_or_exit!(matches, "rent_burn_percentage", u8),
|
burn_percent: value_t_or_exit!(matches, "rent_burn_percentage", u8),
|
||||||
|
@ -399,7 +406,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
||||||
ticks_per_slot,
|
ticks_per_slot,
|
||||||
epoch_schedule,
|
epoch_schedule,
|
||||||
fee_calculator,
|
fee_calculator,
|
||||||
rent_calculator,
|
rent,
|
||||||
poh_config,
|
poh_config,
|
||||||
operating_mode,
|
operating_mode,
|
||||||
..GenesisBlock::default()
|
..GenesisBlock::default()
|
||||||
|
|
|
@ -7,7 +7,7 @@ use solana_sdk::{
|
||||||
entrypoint,
|
entrypoint,
|
||||||
entrypoint::SUCCESS,
|
entrypoint::SUCCESS,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
rent_calculator,
|
rent,
|
||||||
sysvar::{
|
sysvar::{
|
||||||
clock::Clock, fees::Fees, rent::Rent, rewards::Rewards, slot_hashes::SlotHashes,
|
clock::Clock, fees::Fees, rent::Rent, rewards::Rewards, slot_hashes::SlotHashes,
|
||||||
stake_history::StakeHistory,
|
stake_history::StakeHistory,
|
||||||
|
@ -42,9 +42,8 @@ fn process_instruction(_program_id: &Pubkey, accounts: &mut [AccountInfo], _data
|
||||||
|
|
||||||
let rent = Rent::from_account_info(&accounts[7]).unwrap();
|
let rent = Rent::from_account_info(&accounts[7]).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
rent.rent_calculator.due(
|
rent.due(
|
||||||
rent_calculator::DEFAULT_LAMPORTS_PER_BYTE_YEAR
|
rent::DEFAULT_LAMPORTS_PER_BYTE_YEAR * rent::DEFAULT_EXEMPTION_THRESHOLD as u64,
|
||||||
* rent_calculator::DEFAULT_EXEMPTION_THRESHOLD as u64,
|
|
||||||
1,
|
1,
|
||||||
1.0
|
1.0
|
||||||
),
|
),
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
/target/
|
|
@ -428,7 +428,7 @@ impl MoveProcessor {
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use solana_sdk::account::Account;
|
use solana_sdk::account::Account;
|
||||||
use solana_sdk::rent_calculator::RentCalculator;
|
use solana_sdk::rent::Rent;
|
||||||
use solana_sdk::sysvar::rent;
|
use solana_sdk::sysvar::rent;
|
||||||
|
|
||||||
const BIG_ENOUGH: usize = 10_000;
|
const BIG_ENOUGH: usize = 10_000;
|
||||||
|
@ -467,7 +467,7 @@ mod tests {
|
||||||
let sender_address = AccountAddress::default();
|
let sender_address = AccountAddress::default();
|
||||||
let mut program = LibraAccount::create_program(&sender_address, code, vec![]);
|
let mut program = LibraAccount::create_program(&sender_address, code, vec![]);
|
||||||
let rent_id = rent::id();
|
let rent_id = rent::id();
|
||||||
let mut rent_account = rent::create_account(1, &RentCalculator::default());
|
let mut rent_account = rent::create_account(1, &Rent::default());
|
||||||
let mut keyed_accounts = vec![
|
let mut keyed_accounts = vec![
|
||||||
KeyedAccount::new(&program.key, true, &mut program.account),
|
KeyedAccount::new(&program.key, true, &mut program.account),
|
||||||
KeyedAccount::new(&rent_id, false, &mut rent_account),
|
KeyedAccount::new(&rent_id, false, &mut rent_account),
|
||||||
|
@ -514,7 +514,7 @@ mod tests {
|
||||||
let mut genesis = LibraAccount::create_genesis(1_000_000_000);
|
let mut genesis = LibraAccount::create_genesis(1_000_000_000);
|
||||||
|
|
||||||
let rent_id = rent::id();
|
let rent_id = rent::id();
|
||||||
let mut rent_account = rent::create_account(1, &RentCalculator::default());
|
let mut rent_account = rent::create_account(1, &Rent::default());
|
||||||
let mut keyed_accounts = vec![
|
let mut keyed_accounts = vec![
|
||||||
KeyedAccount::new(&program.key, true, &mut program.account),
|
KeyedAccount::new(&program.key, true, &mut program.account),
|
||||||
KeyedAccount::new(&rent_id, false, &mut rent_account),
|
KeyedAccount::new(&rent_id, false, &mut rent_account),
|
||||||
|
@ -554,7 +554,7 @@ mod tests {
|
||||||
let mut genesis = LibraAccount::create_genesis(1_000_000_000);
|
let mut genesis = LibraAccount::create_genesis(1_000_000_000);
|
||||||
|
|
||||||
let rent_id = rent::id();
|
let rent_id = rent::id();
|
||||||
let mut rent_account = rent::create_account(1, &RentCalculator::default());
|
let mut rent_account = rent::create_account(1, &Rent::default());
|
||||||
let mut keyed_accounts = vec![
|
let mut keyed_accounts = vec![
|
||||||
KeyedAccount::new(&program.key, true, &mut program.account),
|
KeyedAccount::new(&program.key, true, &mut program.account),
|
||||||
KeyedAccount::new(&rent_id, false, &mut rent_account),
|
KeyedAccount::new(&rent_id, false, &mut rent_account),
|
||||||
|
@ -629,7 +629,7 @@ mod tests {
|
||||||
let sender = &mut sender[0];
|
let sender = &mut sender[0];
|
||||||
|
|
||||||
let rent_id = rent::id();
|
let rent_id = rent::id();
|
||||||
let mut rent_account = rent::create_account(1, &RentCalculator::default());
|
let mut rent_account = rent::create_account(1, &Rent::default());
|
||||||
let mut keyed_accounts = vec![
|
let mut keyed_accounts = vec![
|
||||||
KeyedAccount::new(&program.key, true, &mut program.account),
|
KeyedAccount::new(&program.key, true, &mut program.account),
|
||||||
KeyedAccount::new(&rent_id, false, &mut rent_account),
|
KeyedAccount::new(&rent_id, false, &mut rent_account),
|
||||||
|
@ -701,7 +701,7 @@ mod tests {
|
||||||
let mut program = LibraAccount::create_program(&payee.address, code, vec![]);
|
let mut program = LibraAccount::create_program(&payee.address, code, vec![]);
|
||||||
|
|
||||||
let rent_id = rent::id();
|
let rent_id = rent::id();
|
||||||
let mut rent_account = rent::create_account(1, &RentCalculator::default());
|
let mut rent_account = rent::create_account(1, &Rent::default());
|
||||||
let mut keyed_accounts = vec![
|
let mut keyed_accounts = vec![
|
||||||
KeyedAccount::new(&program.key, true, &mut program.account),
|
KeyedAccount::new(&program.key, true, &mut program.account),
|
||||||
KeyedAccount::new(&rent_id, false, &mut rent_account),
|
KeyedAccount::new(&rent_id, false, &mut rent_account),
|
||||||
|
@ -747,7 +747,7 @@ mod tests {
|
||||||
let mut genesis = LibraAccount::create_genesis(1_000_000_000);
|
let mut genesis = LibraAccount::create_genesis(1_000_000_000);
|
||||||
|
|
||||||
let rent_id = rent::id();
|
let rent_id = rent::id();
|
||||||
let mut rent_account = rent::create_account(1, &RentCalculator::default());
|
let mut rent_account = rent::create_account(1, &Rent::default());
|
||||||
let mut keyed_accounts = vec![
|
let mut keyed_accounts = vec![
|
||||||
KeyedAccount::new(&program.key, true, &mut program.account),
|
KeyedAccount::new(&program.key, true, &mut program.account),
|
||||||
KeyedAccount::new(&rent_id, false, &mut rent_account),
|
KeyedAccount::new(&rent_id, false, &mut rent_account),
|
||||||
|
@ -791,7 +791,7 @@ mod tests {
|
||||||
LibraAccount::create_program(&module.address, &code, vec![&module.account.data]);
|
LibraAccount::create_program(&module.address, &code, vec![&module.account.data]);
|
||||||
|
|
||||||
let rent_id = rent::id();
|
let rent_id = rent::id();
|
||||||
let mut rent_account = rent::create_account(1, &RentCalculator::default());
|
let mut rent_account = rent::create_account(1, &Rent::default());
|
||||||
let mut keyed_accounts = vec![
|
let mut keyed_accounts = vec![
|
||||||
KeyedAccount::new(&program.key, true, &mut program.account),
|
KeyedAccount::new(&program.key, true, &mut program.account),
|
||||||
KeyedAccount::new(&rent_id, false, &mut rent_account),
|
KeyedAccount::new(&rent_id, false, &mut rent_account),
|
||||||
|
@ -833,7 +833,7 @@ mod tests {
|
||||||
let mut payee = LibraAccount::create_unallocated();
|
let mut payee = LibraAccount::create_unallocated();
|
||||||
|
|
||||||
let rent_id = rent::id();
|
let rent_id = rent::id();
|
||||||
let mut rent_account = rent::create_account(1, &RentCalculator::default());
|
let mut rent_account = rent::create_account(1, &Rent::default());
|
||||||
let mut keyed_accounts = vec![
|
let mut keyed_accounts = vec![
|
||||||
KeyedAccount::new(&program.key, true, &mut program.account),
|
KeyedAccount::new(&program.key, true, &mut program.account),
|
||||||
KeyedAccount::new(&rent_id, false, &mut rent_account),
|
KeyedAccount::new(&rent_id, false, &mut rent_account),
|
||||||
|
|
|
@ -328,9 +328,7 @@ pub fn process_instruction(
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use bincode::serialize;
|
use bincode::serialize;
|
||||||
use solana_sdk::{
|
use solana_sdk::{account::Account, rent::Rent, sysvar::stake_history::StakeHistory};
|
||||||
account::Account, rent_calculator::RentCalculator, sysvar::stake_history::StakeHistory,
|
|
||||||
};
|
|
||||||
|
|
||||||
fn process_instruction(instruction: &Instruction) -> Result<(), InstructionError> {
|
fn process_instruction(instruction: &Instruction) -> Result<(), InstructionError> {
|
||||||
let mut accounts: Vec<_> = instruction
|
let mut accounts: Vec<_> = instruction
|
||||||
|
@ -346,7 +344,7 @@ mod tests {
|
||||||
} else if config::check_id(&meta.pubkey) {
|
} else if config::check_id(&meta.pubkey) {
|
||||||
config::create_account(1, &config::Config::default())
|
config::create_account(1, &config::Config::default())
|
||||||
} else if sysvar::rent::check_id(&meta.pubkey) {
|
} else if sysvar::rent::check_id(&meta.pubkey) {
|
||||||
sysvar::rent::create_account(1, &RentCalculator::default())
|
sysvar::rent::create_account(1, &Rent::default())
|
||||||
} else {
|
} else {
|
||||||
Account::default()
|
Account::default()
|
||||||
}
|
}
|
||||||
|
|
|
@ -219,7 +219,7 @@ pub fn process_instruction(
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use solana_sdk::account::Account;
|
use solana_sdk::account::Account;
|
||||||
use solana_sdk::rent_calculator::RentCalculator;
|
use solana_sdk::rent::Rent;
|
||||||
|
|
||||||
// these are for 100% coverage in this file
|
// these are for 100% coverage in this file
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -240,7 +240,7 @@ mod tests {
|
||||||
} else if sysvar::slot_hashes::check_id(&meta.pubkey) {
|
} else if sysvar::slot_hashes::check_id(&meta.pubkey) {
|
||||||
sysvar::slot_hashes::create_account(1, &[])
|
sysvar::slot_hashes::create_account(1, &[])
|
||||||
} else if sysvar::rent::check_id(&meta.pubkey) {
|
} else if sysvar::rent::check_id(&meta.pubkey) {
|
||||||
sysvar::rent::create_account(1, &RentCalculator::default())
|
sysvar::rent::create_account(1, &Rent::default())
|
||||||
} else {
|
} else {
|
||||||
Account::default()
|
Account::default()
|
||||||
}
|
}
|
||||||
|
@ -303,8 +303,8 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_minimum_balance() {
|
fn test_minimum_balance() {
|
||||||
let rent_calculator = solana_sdk::rent_calculator::RentCalculator::default();
|
let rent = solana_sdk::rent::Rent::default();
|
||||||
let minimum_balance = rent_calculator.minimum_balance(VoteState::size_of());
|
let minimum_balance = rent.minimum_balance(VoteState::size_of());
|
||||||
// vote state cheaper than "my $0.02" ;)
|
// vote state cheaper than "my $0.02" ;)
|
||||||
assert!(minimum_balance as f64 / 10f64.powf(9.0) < 0.02)
|
assert!(minimum_balance as f64 / 10f64.powf(9.0) < 0.02)
|
||||||
}
|
}
|
||||||
|
|
|
@ -473,7 +473,7 @@ impl Bank {
|
||||||
fn update_rent(&self) {
|
fn update_rent(&self) {
|
||||||
self.store_account(
|
self.store_account(
|
||||||
&sysvar::rent::id(),
|
&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;
|
self.inflation = genesis_block.inflation;
|
||||||
|
|
||||||
let rent_calculator = genesis_block.rent_calculator;
|
|
||||||
self.rent_collector = RentCollector::new(
|
self.rent_collector = RentCollector::new(
|
||||||
self.epoch,
|
self.epoch,
|
||||||
&self.epoch_schedule,
|
&self.epoch_schedule,
|
||||||
self.slots_per_year,
|
self.slots_per_year,
|
||||||
&rent_calculator,
|
&genesis_block.rent,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Add additional native programs specified in the genesis block
|
// 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 {
|
pub fn get_minimum_balance_for_rent_exemption(&self, data_len: usize) -> u64 {
|
||||||
self.rent_collector
|
self.rent_collector.rent.minimum_balance(data_len)
|
||||||
.rent_calculator
|
|
||||||
.minimum_balance(data_len)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn last_blockhash_with_fee_calculator(&self) -> (Hash, FeeCalculator) {
|
pub fn last_blockhash_with_fee_calculator(&self) -> (Hash, FeeCalculator) {
|
||||||
|
@ -1641,7 +1638,7 @@ mod tests {
|
||||||
hash,
|
hash,
|
||||||
instruction::InstructionError,
|
instruction::InstructionError,
|
||||||
poh_config::PohConfig,
|
poh_config::PohConfig,
|
||||||
rent_calculator::RentCalculator,
|
rent::Rent,
|
||||||
signature::{Keypair, KeypairUtil},
|
signature::{Keypair, KeypairUtil},
|
||||||
system_instruction, system_transaction,
|
system_instruction, system_transaction,
|
||||||
sysvar::{fees::Fees, rewards::Rewards},
|
sysvar::{fees::Fees, rewards::Rewards},
|
||||||
|
@ -1669,7 +1666,7 @@ mod tests {
|
||||||
&dummy_leader_pubkey,
|
&dummy_leader_pubkey,
|
||||||
dummy_leader_lamports,
|
dummy_leader_lamports,
|
||||||
);
|
);
|
||||||
genesis_block.rent_calculator = RentCalculator {
|
genesis_block.rent = Rent {
|
||||||
lamports_per_byte_year: 5,
|
lamports_per_byte_year: 5,
|
||||||
exemption_threshold: 1.2,
|
exemption_threshold: 1.2,
|
||||||
burn_percent: 5,
|
burn_percent: 5,
|
||||||
|
@ -1685,9 +1682,9 @@ mod tests {
|
||||||
let rent_account = bank.get_account(&sysvar::rent::id()).unwrap();
|
let rent_account = bank.get_account(&sysvar::rent::id()).unwrap();
|
||||||
let rent = sysvar::rent::Rent::from_account(&rent_account).unwrap();
|
let rent = sysvar::rent::Rent::from_account(&rent_account).unwrap();
|
||||||
|
|
||||||
assert_eq!(rent.rent_calculator.burn_percent, 5);
|
assert_eq!(rent.burn_percent, 5);
|
||||||
assert_eq!(rent.rent_calculator.exemption_threshold, 1.2);
|
assert_eq!(rent.exemption_threshold, 1.2);
|
||||||
assert_eq!(rent.rent_calculator.lamports_per_byte_year, 5);
|
assert_eq!(rent.lamports_per_byte_year, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
//! calculate and collect rent from Accounts
|
//! calculate and collect rent from Accounts
|
||||||
use solana_sdk::{
|
use solana_sdk::{account::Account, clock::Epoch, epoch_schedule::EpochSchedule, rent::Rent};
|
||||||
account::Account, clock::Epoch, epoch_schedule::EpochSchedule, rent_calculator::RentCalculator,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Default, Serialize, Deserialize, Clone)]
|
#[derive(Default, Serialize, Deserialize, Clone)]
|
||||||
pub struct RentCollector {
|
pub struct RentCollector {
|
||||||
pub epoch: Epoch,
|
pub epoch: Epoch,
|
||||||
pub epoch_schedule: EpochSchedule,
|
pub epoch_schedule: EpochSchedule,
|
||||||
pub slots_per_year: f64,
|
pub slots_per_year: f64,
|
||||||
pub rent_calculator: RentCalculator,
|
pub rent: Rent,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RentCollector {
|
impl RentCollector {
|
||||||
|
@ -16,13 +14,13 @@ impl RentCollector {
|
||||||
epoch: Epoch,
|
epoch: Epoch,
|
||||||
epoch_schedule: &EpochSchedule,
|
epoch_schedule: &EpochSchedule,
|
||||||
slots_per_year: f64,
|
slots_per_year: f64,
|
||||||
rent_calculator: &RentCalculator,
|
rent: &Rent,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
epoch,
|
epoch,
|
||||||
epoch_schedule: *epoch_schedule,
|
epoch_schedule: *epoch_schedule,
|
||||||
slots_per_year,
|
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))
|
.map(|epoch| self.epoch_schedule.get_slots_in_epoch(epoch + 1))
|
||||||
.sum();
|
.sum();
|
||||||
|
|
||||||
let (rent_due, exempt) = self.rent_calculator.due(
|
let (rent_due, exempt) = self.rent.due(
|
||||||
account.lamports,
|
account.lamports,
|
||||||
account.data.len(),
|
account.data.len(),
|
||||||
slots_elapsed as f64 / self.slots_per_year,
|
slots_elapsed as f64 / self.slots_per_year,
|
||||||
|
|
|
@ -9,7 +9,7 @@ use crate::{
|
||||||
inflation::Inflation,
|
inflation::Inflation,
|
||||||
poh_config::PohConfig,
|
poh_config::PohConfig,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
rent_calculator::RentCalculator,
|
rent::Rent,
|
||||||
signature::{Keypair, KeypairUtil},
|
signature::{Keypair, KeypairUtil},
|
||||||
system_program::{self, solana_system_program},
|
system_program::{self, solana_system_program},
|
||||||
};
|
};
|
||||||
|
@ -36,7 +36,7 @@ pub struct GenesisBlock {
|
||||||
pub slots_per_segment: u64,
|
pub slots_per_segment: u64,
|
||||||
pub poh_config: PohConfig,
|
pub poh_config: PohConfig,
|
||||||
pub fee_calculator: FeeCalculator,
|
pub fee_calculator: FeeCalculator,
|
||||||
pub rent_calculator: RentCalculator,
|
pub rent: Rent,
|
||||||
pub inflation: Inflation,
|
pub inflation: Inflation,
|
||||||
pub epoch_schedule: EpochSchedule,
|
pub epoch_schedule: EpochSchedule,
|
||||||
pub operating_mode: OperatingMode,
|
pub operating_mode: OperatingMode,
|
||||||
|
@ -68,7 +68,7 @@ impl Default for GenesisBlock {
|
||||||
poh_config: PohConfig::default(),
|
poh_config: PohConfig::default(),
|
||||||
inflation: Inflation::default(),
|
inflation: Inflation::default(),
|
||||||
fee_calculator: FeeCalculator::default(),
|
fee_calculator: FeeCalculator::default(),
|
||||||
rent_calculator: RentCalculator::default(),
|
rent: Rent::default(),
|
||||||
epoch_schedule: EpochSchedule::default(),
|
epoch_schedule: EpochSchedule::default(),
|
||||||
operating_mode: OperatingMode::Development,
|
operating_mode: OperatingMode::Development,
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ pub mod native_loader;
|
||||||
pub mod native_token;
|
pub mod native_token;
|
||||||
pub mod poh_config;
|
pub mod poh_config;
|
||||||
pub mod pubkey;
|
pub mod pubkey;
|
||||||
pub mod rent_calculator;
|
pub mod rent;
|
||||||
pub mod rpc_port;
|
pub mod rpc_port;
|
||||||
pub mod short_vec;
|
pub mod short_vec;
|
||||||
pub mod slot_hashes;
|
pub mod slot_hashes;
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
//! configuration for network rent
|
//! configuration for network rent
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
#[derive(Serialize, Deserialize, PartialEq, Clone, Copy, Debug)]
|
#[derive(Serialize, Deserialize, PartialEq, Clone, Copy, Debug)]
|
||||||
pub struct RentCalculator {
|
pub struct Rent {
|
||||||
/// Rental rate
|
/// Rental rate
|
||||||
pub lamports_per_byte_year: u64,
|
pub lamports_per_byte_year: u64,
|
||||||
|
|
||||||
|
@ -25,7 +26,7 @@ pub const DEFAULT_EXEMPTION_THRESHOLD: f64 = 2.0;
|
||||||
/// default amount of rent to burn, as a fraction of std::u8::MAX
|
/// default amount of rent to burn, as a fraction of std::u8::MAX
|
||||||
pub const DEFAULT_BURN_PERCENT: u8 = ((50usize * std::u8::MAX as usize) / 100usize) as u8;
|
pub const DEFAULT_BURN_PERCENT: u8 = ((50usize * std::u8::MAX as usize) / 100usize) as u8;
|
||||||
|
|
||||||
impl Default for RentCalculator {
|
impl Default for Rent {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
lamports_per_byte_year: DEFAULT_LAMPORTS_PER_BYTE_YEAR,
|
lamports_per_byte_year: DEFAULT_LAMPORTS_PER_BYTE_YEAR,
|
||||||
|
@ -35,7 +36,7 @@ impl Default for RentCalculator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RentCalculator {
|
impl Rent {
|
||||||
/// minimum balance due for a given size Account::data.len()
|
/// minimum balance due for a given size Account::data.len()
|
||||||
pub fn minimum_balance(&self, data_len: usize) -> u64 {
|
pub fn minimum_balance(&self, data_len: usize) -> u64 {
|
||||||
let bytes = data_len as u64;
|
let bytes = data_len as u64;
|
||||||
|
@ -66,17 +67,17 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_due() {
|
fn test_due() {
|
||||||
let rent_calculator = RentCalculator::default();
|
let rent = Rent::default();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
rent_calculator.due(0, 1, 1.0),
|
rent.due(0, 1, 1.0),
|
||||||
(
|
(
|
||||||
DEFAULT_LAMPORTS_PER_BYTE_YEAR,
|
DEFAULT_LAMPORTS_PER_BYTE_YEAR,
|
||||||
DEFAULT_LAMPORTS_PER_BYTE_YEAR == 0
|
DEFAULT_LAMPORTS_PER_BYTE_YEAR == 0
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
rent_calculator.due(
|
rent.due(
|
||||||
DEFAULT_LAMPORTS_PER_BYTE_YEAR * DEFAULT_EXEMPTION_THRESHOLD as u64,
|
DEFAULT_LAMPORTS_PER_BYTE_YEAR * DEFAULT_EXEMPTION_THRESHOLD as u64,
|
||||||
1,
|
1,
|
||||||
1.0
|
1.0
|
||||||
|
@ -94,21 +95,21 @@ mod tests {
|
||||||
// const SLOTS_PER_YEAR: f64 =
|
// const SLOTS_PER_YEAR: f64 =
|
||||||
// SECONDS_PER_YEAR / (DEFAULT_TICKS_PER_SLOT as f64 / DEFAULT_TICKS_PER_SECOND as f64);
|
// SECONDS_PER_YEAR / (DEFAULT_TICKS_PER_SLOT as f64 / DEFAULT_TICKS_PER_SECOND as f64);
|
||||||
//
|
//
|
||||||
// let rent_calculator = RentCalculator::default();
|
// let rent = Rent::default();
|
||||||
//
|
//
|
||||||
// eprintln();
|
// eprintln();
|
||||||
// // lamports charged per byte per slot at $1/MByear, rent per slot is zero
|
// // lamports charged per byte per slot at $1/MByear, rent per slot is zero
|
||||||
// eprintln(
|
// eprintln(
|
||||||
// "{} lamports per byte-slot, rent_calculator.due(): {}",
|
// "{} lamports per byte-slot, rent.due(): {}",
|
||||||
// (1.0 / SLOTS_PER_YEAR) * DEFAULT_LAMPORTS_PER_BYTE_YEAR as f64,
|
// (1.0 / SLOTS_PER_YEAR) * DEFAULT_LAMPORTS_PER_BYTE_YEAR as f64,
|
||||||
// rent_calculator.due(0, 1, 1.0 / SLOTS_PER_YEAR).0,
|
// rent.due(0, 1, 1.0 / SLOTS_PER_YEAR).0,
|
||||||
// );
|
// );
|
||||||
// // lamports charged per byte per _epoch_ starts to have some significant digits
|
// // lamports charged per byte per _epoch_ starts to have some significant digits
|
||||||
// eprintln(
|
// eprintln(
|
||||||
// "{} lamports per byte-epoch, rent_calculator.due(): {}",
|
// "{} lamports per byte-epoch, rent.due(): {}",
|
||||||
// (1.0 / SLOTS_PER_YEAR)
|
// (1.0 / SLOTS_PER_YEAR)
|
||||||
// * (DEFAULT_LAMPORTS_PER_BYTE_YEAR * DEFAULT_SLOTS_PER_EPOCH) as f64,
|
// * (DEFAULT_LAMPORTS_PER_BYTE_YEAR * DEFAULT_SLOTS_PER_EPOCH) as f64,
|
||||||
// rent_calculator.due(
|
// rent.due(
|
||||||
// 0,
|
// 0,
|
||||||
// 1,
|
// 1,
|
||||||
// (1.0 / SLOTS_PER_YEAR) * DEFAULT_SLOTS_PER_EPOCH as f64
|
// (1.0 / SLOTS_PER_YEAR) * DEFAULT_SLOTS_PER_EPOCH as f64
|
||||||
|
@ -119,7 +120,7 @@ mod tests {
|
||||||
// eprintln(
|
// eprintln(
|
||||||
// "stake_history: {}kB == {} lamports per epoch",
|
// "stake_history: {}kB == {} lamports per epoch",
|
||||||
// crate::sysvar::stake_history::StakeHistory::size_of() / 1024,
|
// crate::sysvar::stake_history::StakeHistory::size_of() / 1024,
|
||||||
// rent_calculator.due(
|
// rent.due(
|
||||||
// 0,
|
// 0,
|
||||||
// crate::sysvar::stake_history::StakeHistory::size_of(),
|
// crate::sysvar::stake_history::StakeHistory::size_of(),
|
||||||
// (1.0 / SLOTS_PER_YEAR) * DEFAULT_SLOTS_PER_EPOCH as f64
|
// (1.0 / SLOTS_PER_YEAR) * DEFAULT_SLOTS_PER_EPOCH as f64
|
|
@ -1,10 +1,11 @@
|
||||||
//! This account contains the current cluster rent
|
//! This account contains the current cluster rent
|
||||||
//!
|
//!
|
||||||
|
pub use crate::rent::Rent;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
account::{Account, KeyedAccount},
|
account::{Account, KeyedAccount},
|
||||||
account_info::AccountInfo,
|
account_info::AccountInfo,
|
||||||
instruction::InstructionError,
|
instruction::InstructionError,
|
||||||
rent_calculator::RentCalculator,
|
|
||||||
sysvar,
|
sysvar,
|
||||||
};
|
};
|
||||||
use bincode::serialized_size;
|
use bincode::serialized_size;
|
||||||
|
@ -17,12 +18,6 @@ const ID: [u8; 32] = [
|
||||||
|
|
||||||
crate::solana_sysvar_id!(ID, "SysvarRent111111111111111111111111111111111");
|
crate::solana_sysvar_id!(ID, "SysvarRent111111111111111111111111111111111");
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Default)]
|
|
||||||
pub struct Rent {
|
|
||||||
pub rent_calculator: RentCalculator,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Rent {
|
impl Rent {
|
||||||
pub fn from_account(account: &Account) -> Option<Self> {
|
pub fn from_account(account: &Account) -> Option<Self> {
|
||||||
account.deserialize_data().ok()
|
account.deserialize_data().ok()
|
||||||
|
@ -41,15 +36,8 @@ impl Rent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_account(lamports: u64, rent_calculator: &RentCalculator) -> Account {
|
pub fn create_account(lamports: u64, rent: &Rent) -> Account {
|
||||||
Account::new_data(
|
Account::new_data(lamports, rent, &sysvar::id()).unwrap()
|
||||||
lamports,
|
|
||||||
&Rent {
|
|
||||||
rent_calculator: *rent_calculator,
|
|
||||||
},
|
|
||||||
&sysvar::id(),
|
|
||||||
)
|
|
||||||
.unwrap()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_keyed_account(account: &KeyedAccount) -> Result<Rent, InstructionError> {
|
pub fn from_keyed_account(account: &KeyedAccount) -> Result<Rent, InstructionError> {
|
||||||
|
@ -64,7 +52,6 @@ pub fn verify_rent_exemption(
|
||||||
rent_sysvar_account: &KeyedAccount,
|
rent_sysvar_account: &KeyedAccount,
|
||||||
) -> Result<(), InstructionError> {
|
) -> Result<(), InstructionError> {
|
||||||
if !from_keyed_account(rent_sysvar_account)?
|
if !from_keyed_account(rent_sysvar_account)?
|
||||||
.rent_calculator
|
|
||||||
.is_exempt(account.account.lamports, account.account.data.len())
|
.is_exempt(account.account.lamports, account.account.data.len())
|
||||||
{
|
{
|
||||||
Err(InstructionError::InsufficientFunds)
|
Err(InstructionError::InsufficientFunds)
|
||||||
|
@ -80,8 +67,8 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rent_create_account() {
|
fn test_rent_create_account() {
|
||||||
let lamports = 42;
|
let lamports = 42;
|
||||||
let account = create_account(lamports, &RentCalculator::default());
|
let account = create_account(lamports, &Rent::default());
|
||||||
let rent = Rent::from_account(&account).unwrap();
|
let rent = Rent::from_account(&account).unwrap();
|
||||||
assert_eq!(rent.rent_calculator, RentCalculator::default());
|
assert_eq!(rent, Rent::default());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue