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);
|
||||
|
||||
genesis_block.rent_calculator.lamports_per_byte_year = 50;
|
||||
genesis_block.rent_calculator.exemption_threshold = 2.0;
|
||||
genesis_block.rent.lamports_per_byte_year = 50;
|
||||
genesis_block.rent.exemption_threshold = 2.0;
|
||||
|
||||
let bank = Bank::new(&genesis_block);
|
||||
(
|
||||
|
|
|
@ -591,8 +591,8 @@ pub fn new_validator_for_tests() -> (Validator, ContactInfo, Keypair, PathBuf) {
|
|||
.native_instruction_processors
|
||||
.push(solana_budget_program!());
|
||||
|
||||
genesis_block.rent_calculator.lamports_per_byte_year = 1;
|
||||
genesis_block.rent_calculator.exemption_threshold = 1.0;
|
||||
genesis_block.rent.lamports_per_byte_year = 1;
|
||||
genesis_block.rent.exemption_threshold = 1.0;
|
||||
|
||||
let (ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_block);
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ use solana_sdk::{
|
|||
native_token::sol_to_lamports,
|
||||
poh_config::PohConfig,
|
||||
pubkey::Pubkey,
|
||||
rent_calculator::RentCalculator,
|
||||
rent::Rent,
|
||||
signature::{read_keypair_file, Keypair, KeypairUtil},
|
||||
system_program, timing,
|
||||
};
|
||||
|
@ -86,11 +86,18 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||
let default_target_signatures_per_slot = &FeeCalculator::default()
|
||||
.target_signatures_per_slot
|
||||
.to_string();
|
||||
let default_lamports_per_byte_year =
|
||||
&RentCalculator::default().lamports_per_byte_year.to_string();
|
||||
let default_rent_exemption_threshold =
|
||||
&RentCalculator::default().exemption_threshold.to_string();
|
||||
let default_rent_burn_percentage = &RentCalculator::default().burn_percent.to_string();
|
||||
let (
|
||||
default_lamports_per_byte_year,
|
||||
default_rent_exemption_threshold,
|
||||
default_rent_burn_percentage,
|
||||
) = {
|
||||
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 =
|
||||
&timing::duration_as_ms(&PohConfig::default().target_tick_duration).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),
|
||||
);
|
||||
|
||||
let rent_calculator = RentCalculator {
|
||||
let rent = Rent {
|
||||
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),
|
||||
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,
|
||||
epoch_schedule,
|
||||
fee_calculator,
|
||||
rent_calculator,
|
||||
rent,
|
||||
poh_config,
|
||||
operating_mode,
|
||||
..GenesisBlock::default()
|
||||
|
|
|
@ -7,7 +7,7 @@ use solana_sdk::{
|
|||
entrypoint,
|
||||
entrypoint::SUCCESS,
|
||||
pubkey::Pubkey,
|
||||
rent_calculator,
|
||||
rent,
|
||||
sysvar::{
|
||||
clock::Clock, fees::Fees, rent::Rent, rewards::Rewards, slot_hashes::SlotHashes,
|
||||
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();
|
||||
assert_eq!(
|
||||
rent.rent_calculator.due(
|
||||
rent_calculator::DEFAULT_LAMPORTS_PER_BYTE_YEAR
|
||||
* rent_calculator::DEFAULT_EXEMPTION_THRESHOLD as u64,
|
||||
rent.due(
|
||||
rent::DEFAULT_LAMPORTS_PER_BYTE_YEAR * rent::DEFAULT_EXEMPTION_THRESHOLD as u64,
|
||||
1,
|
||||
1.0
|
||||
),
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
/target/
|
|
@ -428,7 +428,7 @@ impl MoveProcessor {
|
|||
mod tests {
|
||||
use super::*;
|
||||
use solana_sdk::account::Account;
|
||||
use solana_sdk::rent_calculator::RentCalculator;
|
||||
use solana_sdk::rent::Rent;
|
||||
use solana_sdk::sysvar::rent;
|
||||
|
||||
const BIG_ENOUGH: usize = 10_000;
|
||||
|
@ -467,7 +467,7 @@ mod tests {
|
|||
let sender_address = AccountAddress::default();
|
||||
let mut program = LibraAccount::create_program(&sender_address, code, vec![]);
|
||||
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![
|
||||
KeyedAccount::new(&program.key, true, &mut program.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 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![
|
||||
KeyedAccount::new(&program.key, true, &mut program.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 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![
|
||||
KeyedAccount::new(&program.key, true, &mut program.account),
|
||||
KeyedAccount::new(&rent_id, false, &mut rent_account),
|
||||
|
@ -629,7 +629,7 @@ mod tests {
|
|||
let sender = &mut sender[0];
|
||||
|
||||
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![
|
||||
KeyedAccount::new(&program.key, true, &mut program.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 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![
|
||||
KeyedAccount::new(&program.key, true, &mut program.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 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![
|
||||
KeyedAccount::new(&program.key, true, &mut program.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]);
|
||||
|
||||
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![
|
||||
KeyedAccount::new(&program.key, true, &mut program.account),
|
||||
KeyedAccount::new(&rent_id, false, &mut rent_account),
|
||||
|
@ -833,7 +833,7 @@ mod tests {
|
|||
let mut payee = LibraAccount::create_unallocated();
|
||||
|
||||
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![
|
||||
KeyedAccount::new(&program.key, true, &mut program.account),
|
||||
KeyedAccount::new(&rent_id, false, &mut rent_account),
|
||||
|
|
|
@ -328,9 +328,7 @@ pub fn process_instruction(
|
|||
mod tests {
|
||||
use super::*;
|
||||
use bincode::serialize;
|
||||
use solana_sdk::{
|
||||
account::Account, rent_calculator::RentCalculator, sysvar::stake_history::StakeHistory,
|
||||
};
|
||||
use solana_sdk::{account::Account, rent::Rent, sysvar::stake_history::StakeHistory};
|
||||
|
||||
fn process_instruction(instruction: &Instruction) -> Result<(), InstructionError> {
|
||||
let mut accounts: Vec<_> = instruction
|
||||
|
@ -346,7 +344,7 @@ mod tests {
|
|||
} else if config::check_id(&meta.pubkey) {
|
||||
config::create_account(1, &config::Config::default())
|
||||
} else if sysvar::rent::check_id(&meta.pubkey) {
|
||||
sysvar::rent::create_account(1, &RentCalculator::default())
|
||||
sysvar::rent::create_account(1, &Rent::default())
|
||||
} else {
|
||||
Account::default()
|
||||
}
|
||||
|
|
|
@ -219,7 +219,7 @@ pub fn process_instruction(
|
|||
mod tests {
|
||||
use super::*;
|
||||
use solana_sdk::account::Account;
|
||||
use solana_sdk::rent_calculator::RentCalculator;
|
||||
use solana_sdk::rent::Rent;
|
||||
|
||||
// these are for 100% coverage in this file
|
||||
#[test]
|
||||
|
@ -240,7 +240,7 @@ mod tests {
|
|||
} else if sysvar::slot_hashes::check_id(&meta.pubkey) {
|
||||
sysvar::slot_hashes::create_account(1, &[])
|
||||
} else if sysvar::rent::check_id(&meta.pubkey) {
|
||||
sysvar::rent::create_account(1, &RentCalculator::default())
|
||||
sysvar::rent::create_account(1, &Rent::default())
|
||||
} else {
|
||||
Account::default()
|
||||
}
|
||||
|
@ -303,8 +303,8 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_minimum_balance() {
|
||||
let rent_calculator = solana_sdk::rent_calculator::RentCalculator::default();
|
||||
let minimum_balance = rent_calculator.minimum_balance(VoteState::size_of());
|
||||
let rent = solana_sdk::rent::Rent::default();
|
||||
let minimum_balance = rent.minimum_balance(VoteState::size_of());
|
||||
// vote state cheaper than "my $0.02" ;)
|
||||
assert!(minimum_balance as f64 / 10f64.powf(9.0) < 0.02)
|
||||
}
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -9,7 +9,7 @@ use crate::{
|
|||
inflation::Inflation,
|
||||
poh_config::PohConfig,
|
||||
pubkey::Pubkey,
|
||||
rent_calculator::RentCalculator,
|
||||
rent::Rent,
|
||||
signature::{Keypair, KeypairUtil},
|
||||
system_program::{self, solana_system_program},
|
||||
};
|
||||
|
@ -36,7 +36,7 @@ pub struct GenesisBlock {
|
|||
pub slots_per_segment: u64,
|
||||
pub poh_config: PohConfig,
|
||||
pub fee_calculator: FeeCalculator,
|
||||
pub rent_calculator: RentCalculator,
|
||||
pub rent: Rent,
|
||||
pub inflation: Inflation,
|
||||
pub epoch_schedule: EpochSchedule,
|
||||
pub operating_mode: OperatingMode,
|
||||
|
@ -68,7 +68,7 @@ impl Default for GenesisBlock {
|
|||
poh_config: PohConfig::default(),
|
||||
inflation: Inflation::default(),
|
||||
fee_calculator: FeeCalculator::default(),
|
||||
rent_calculator: RentCalculator::default(),
|
||||
rent: Rent::default(),
|
||||
epoch_schedule: EpochSchedule::default(),
|
||||
operating_mode: OperatingMode::Development,
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ pub mod native_loader;
|
|||
pub mod native_token;
|
||||
pub mod poh_config;
|
||||
pub mod pubkey;
|
||||
pub mod rent_calculator;
|
||||
pub mod rent;
|
||||
pub mod rpc_port;
|
||||
pub mod short_vec;
|
||||
pub mod slot_hashes;
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
//! configuration for network rent
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Serialize, Deserialize, PartialEq, Clone, Copy, Debug)]
|
||||
pub struct RentCalculator {
|
||||
pub struct Rent {
|
||||
/// Rental rate
|
||||
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
|
||||
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 {
|
||||
Self {
|
||||
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()
|
||||
pub fn minimum_balance(&self, data_len: usize) -> u64 {
|
||||
let bytes = data_len as u64;
|
||||
|
@ -66,17 +67,17 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_due() {
|
||||
let rent_calculator = RentCalculator::default();
|
||||
let rent = Rent::default();
|
||||
|
||||
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 == 0
|
||||
)
|
||||
);
|
||||
assert_eq!(
|
||||
rent_calculator.due(
|
||||
rent.due(
|
||||
DEFAULT_LAMPORTS_PER_BYTE_YEAR * DEFAULT_EXEMPTION_THRESHOLD as u64,
|
||||
1,
|
||||
1.0
|
||||
|
@ -94,21 +95,21 @@ mod tests {
|
|||
// const SLOTS_PER_YEAR: 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();
|
||||
// // lamports charged per byte per slot at $1/MByear, rent per slot is zero
|
||||
// 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,
|
||||
// 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
|
||||
// eprintln(
|
||||
// "{} lamports per byte-epoch, rent_calculator.due(): {}",
|
||||
// "{} lamports per byte-epoch, rent.due(): {}",
|
||||
// (1.0 / SLOTS_PER_YEAR)
|
||||
// * (DEFAULT_LAMPORTS_PER_BYTE_YEAR * DEFAULT_SLOTS_PER_EPOCH) as f64,
|
||||
// rent_calculator.due(
|
||||
// rent.due(
|
||||
// 0,
|
||||
// 1,
|
||||
// (1.0 / SLOTS_PER_YEAR) * DEFAULT_SLOTS_PER_EPOCH as f64
|
||||
|
@ -119,7 +120,7 @@ mod tests {
|
|||
// eprintln(
|
||||
// "stake_history: {}kB == {} lamports per epoch",
|
||||
// crate::sysvar::stake_history::StakeHistory::size_of() / 1024,
|
||||
// rent_calculator.due(
|
||||
// rent.due(
|
||||
// 0,
|
||||
// crate::sysvar::stake_history::StakeHistory::size_of(),
|
||||
// (1.0 / SLOTS_PER_YEAR) * DEFAULT_SLOTS_PER_EPOCH as f64
|
|
@ -1,10 +1,11 @@
|
|||
//! This account contains the current cluster rent
|
||||
//!
|
||||
pub use crate::rent::Rent;
|
||||
|
||||
use crate::{
|
||||
account::{Account, KeyedAccount},
|
||||
account_info::AccountInfo,
|
||||
instruction::InstructionError,
|
||||
rent_calculator::RentCalculator,
|
||||
sysvar,
|
||||
};
|
||||
use bincode::serialized_size;
|
||||
|
@ -17,12 +18,6 @@ const ID: [u8; 32] = [
|
|||
|
||||
crate::solana_sysvar_id!(ID, "SysvarRent111111111111111111111111111111111");
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Serialize, Deserialize, Debug, Default)]
|
||||
pub struct Rent {
|
||||
pub rent_calculator: RentCalculator,
|
||||
}
|
||||
|
||||
impl Rent {
|
||||
pub fn from_account(account: &Account) -> Option<Self> {
|
||||
account.deserialize_data().ok()
|
||||
|
@ -41,15 +36,8 @@ impl Rent {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn create_account(lamports: u64, rent_calculator: &RentCalculator) -> Account {
|
||||
Account::new_data(
|
||||
lamports,
|
||||
&Rent {
|
||||
rent_calculator: *rent_calculator,
|
||||
},
|
||||
&sysvar::id(),
|
||||
)
|
||||
.unwrap()
|
||||
pub fn create_account(lamports: u64, rent: &Rent) -> Account {
|
||||
Account::new_data(lamports, rent, &sysvar::id()).unwrap()
|
||||
}
|
||||
|
||||
pub fn from_keyed_account(account: &KeyedAccount) -> Result<Rent, InstructionError> {
|
||||
|
@ -64,7 +52,6 @@ pub fn verify_rent_exemption(
|
|||
rent_sysvar_account: &KeyedAccount,
|
||||
) -> Result<(), InstructionError> {
|
||||
if !from_keyed_account(rent_sysvar_account)?
|
||||
.rent_calculator
|
||||
.is_exempt(account.account.lamports, account.account.data.len())
|
||||
{
|
||||
Err(InstructionError::InsufficientFunds)
|
||||
|
@ -80,8 +67,8 @@ mod tests {
|
|||
#[test]
|
||||
fn test_rent_create_account() {
|
||||
let lamports = 42;
|
||||
let account = create_account(lamports, &RentCalculator::default());
|
||||
let account = create_account(lamports, &Rent::default());
|
||||
let rent = Rent::from_account(&account).unwrap();
|
||||
assert_eq!(rent.rent_calculator, RentCalculator::default());
|
||||
assert_eq!(rent, Rent::default());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue