turn on rent (#7368)

* turn on rent

* add rent exempt balances for bootstrap accounts

* use Rent::free() when not testing rent
This commit is contained in:
Rob Walker 2019-12-09 21:56:43 -08:00 committed by GitHub
parent ed9cf3566c
commit 39cd6dff7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 89 additions and 48 deletions

View File

@ -163,14 +163,20 @@ pub fn process_create_storage_account(
"storage_account_pubkey".to_string(),
),
)?;
let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
use solana_storage_program::storage_contract::STORAGE_ACCOUNT_SPACE;
let required_balance = rpc_client
.get_minimum_balance_for_rent_exemption(STORAGE_ACCOUNT_SPACE as usize)?
.max(1);
let ixs = storage_instruction::create_storage_account(
&config.keypair.pubkey(),
&account_owner,
&storage_account_pubkey,
1,
required_balance,
account_type,
);
let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
let mut tx = Transaction::new_signed_instructions(
&[&config.keypair, &storage_account],
ixs,

View File

@ -243,13 +243,11 @@ pub fn process_create_vote_account(
(&config.keypair.pubkey(), "cli keypair".to_string()),
(&vote_account_pubkey, "vote_account_pubkey".to_string()),
)?;
let required_balance =
rpc_client.get_minimum_balance_for_rent_exemption(VoteState::size_of())?;
let lamports = if required_balance > 0 {
required_balance
} else {
1
};
let required_balance = dbg!(rpc_client
.get_minimum_balance_for_rent_exemption(VoteState::size_of())?
.max(1));
let vote_init = VoteInit {
node_pubkey: *node_pubkey,
authorized_voter: authorized_voter.unwrap_or(vote_account_pubkey),
@ -260,7 +258,7 @@ pub fn process_create_vote_account(
&config.keypair.pubkey(),
&vote_account_pubkey,
&vote_init,
lamports,
required_balance,
);
let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
let mut tx = Transaction::new_signed_instructions(

View File

@ -19,9 +19,9 @@ use solana_sdk::{
signature::{Keypair, KeypairUtil},
system_program, timing,
};
use solana_stake_program::stake_state;
use solana_stake_program::stake_state::{self, StakeState};
use solana_storage_program::storage_contract;
use solana_vote_program::vote_state;
use solana_vote_program::vote_state::{self, VoteState};
use std::{
collections::{BTreeMap, HashMap},
error,
@ -98,26 +98,34 @@ pub fn load_genesis_accounts(file: &str, genesis_config: &mut GenesisConfig) ->
#[allow(clippy::cognitive_complexity)]
fn main() -> Result<(), Box<dyn error::Error>> {
let default_bootstrap_leader_lamports = &sol_to_lamports(500.0).to_string();
let default_bootstrap_leader_stake_lamports = &sol_to_lamports(0.5).to_string();
let default_target_lamports_per_signature = &FeeCalculator::default()
.target_lamports_per_signature
.to_string();
let default_target_signatures_per_slot = &FeeCalculator::default()
.target_signatures_per_slot
.to_string();
let rent = Rent::default();
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(),
)
};
// vote account
let default_bootstrap_leader_lamports = &sol_to_lamports(500.0)
.max(VoteState::get_rent_exempt_reserve(&rent))
.to_string();
// stake account
let default_bootstrap_leader_stake_lamports = &sol_to_lamports(0.5)
.max(StakeState::get_rent_exempt_reserve(&rent))
.to_string();
let default_target_tick_duration =
timing::duration_as_us(&PohConfig::default().target_tick_duration);
let default_ticks_per_slot = &clock::DEFAULT_TICKS_PER_SLOT.to_string();
@ -324,9 +332,36 @@ fn main() -> Result<(), Box<dyn error::Error>> {
let faucet_lamports = value_t!(matches, "faucet_lamports", u64).unwrap_or(0);
let ledger_path = PathBuf::from(matches.value_of("ledger_path").unwrap());
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),
};
fn rent_exempt_check(matches: &ArgMatches<'_>, name: &str, exempt: u64) -> io::Result<u64> {
let lamports = value_t_or_exit!(matches, name, u64);
if lamports < exempt {
Err(io::Error::new(
io::ErrorKind::Other,
format!(
"error: insufficient {}: {} for rent exemption, requires {}",
name, lamports, exempt
),
))
} else {
Ok(lamports)
}
}
let bootstrap_leader_lamports = value_t_or_exit!(matches, "bootstrap_leader_lamports", u64);
let bootstrap_leader_stake_lamports =
value_t_or_exit!(matches, "bootstrap_leader_stake_lamports", u64);
let bootstrap_leader_stake_lamports = rent_exempt_check(
&matches,
"bootstrap_leader_stake_lamports",
StakeState::get_rent_exempt_reserve(&rent),
)?;
let bootstrap_leader_pubkey = required_pubkey(&matches, "bootstrap_leader_pubkey_file")?;
let bootstrap_vote_pubkey = required_pubkey(&matches, "bootstrap_vote_pubkey_file")?;
@ -336,14 +371,12 @@ fn main() -> Result<(), Box<dyn error::Error>> {
let bootstrap_storage_pubkey = pubkey_of(&matches, "bootstrap_storage_pubkey_file");
let faucet_pubkey = pubkey_of(&matches, "faucet_pubkey_file");
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),
};
let bootstrap_leader_vote_account =
vote_state::create_account(&bootstrap_vote_pubkey, &bootstrap_leader_pubkey, 0, 1);
let bootstrap_leader_vote_account = vote_state::create_account(
&bootstrap_vote_pubkey,
&bootstrap_leader_pubkey,
0,
VoteState::get_rent_exempt_reserve(&rent).max(1),
);
let bootstrap_leader_stake_account = stake_state::create_account(
bootstrap_stake_authorized_pubkey

View File

@ -258,8 +258,9 @@ mod tests {
let rent_key = rent::id();
let mut file = File::open("test_elfs/noop.so").expect("file open failed");
let mut elf = Vec::new();
let rent = rent::Rent::default();
file.read_to_end(&mut elf).unwrap();
let mut program_account = Account::new(1, 0, &program_id);
let mut program_account = Account::new(rent.minimum_balance(elf.len()), 0, &program_id);
program_account.data = elf;
let mut keyed_accounts = vec![KeyedAccount::new(&program_key, false, &mut program_account)];
let ix_data = bincode::serialize(&LoaderInstruction::Finalize).unwrap();
@ -270,7 +271,7 @@ mod tests {
process_instruction(&program_id, &mut vec![], &ix_data)
);
let mut rent_account = rent::create_account(1, &rent::Rent::default());
let mut rent_account = rent::create_account(1, &rent);
keyed_accounts.push(KeyedAccount::new(&rent_key, false, &mut rent_account));
// Case: Not signed

View File

@ -156,7 +156,8 @@ mod tests {
use std::sync::Arc;
fn create_bank(lamports: u64) -> (Arc<Bank>, Keypair, Keypair, Pubkey, Pubkey) {
let (genesis_config, mint) = create_genesis_config(lamports);
let (mut genesis_config, mint) = create_genesis_config(lamports);
genesis_config.rent.lamports_per_byte_year = 0;
let mut bank = Bank::new(&genesis_config);
bank.add_instruction_processor(
solana_sdk::move_loader::id(),

View File

@ -463,7 +463,7 @@ mod tests {
let sender_address = AccountAddress::default();
let mut script = LibraAccount::create_script(&sender_address, code, vec![]);
let rent_id = rent::id();
let mut rent_account = rent::create_account(1, &Rent::default());
let mut rent_account = rent::create_account(1, &Rent::free());
let mut keyed_accounts = vec![
KeyedAccount::new(&script.key, true, &mut script.account),
KeyedAccount::new(&rent_id, false, &mut rent_account),
@ -509,7 +509,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, &Rent::default());
let mut rent_account = rent::create_account(1, &Rent::free());
let mut keyed_accounts = vec![
KeyedAccount::new(&script.key, true, &mut script.account),
KeyedAccount::new(&rent_id, false, &mut rent_account),
@ -547,7 +547,7 @@ mod tests {
";
let mut module = LibraAccount::create_module(code, vec![]);
let rent_id = rent::id();
let mut rent_account = rent::create_account(1, &Rent::default());
let mut rent_account = rent::create_account(1, &Rent::free());
let mut keyed_accounts = vec![
KeyedAccount::new(&module.key, true, &mut module.account),
KeyedAccount::new(&rent_id, false, &mut rent_account),
@ -572,7 +572,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, &Rent::default());
let mut rent_account = rent::create_account(1, &Rent::free());
let mut keyed_accounts = vec![
KeyedAccount::new(&script.key, true, &mut script.account),
KeyedAccount::new(&rent_id, false, &mut rent_account),
@ -650,7 +650,7 @@ mod tests {
let mut payee = LibraAccount::create_unallocated(BIG_ENOUGH);
let rent_id = rent::id();
let mut rent_account = rent::create_account(1, &Rent::default());
let mut rent_account = rent::create_account(1, &Rent::free());
let mut keyed_accounts = vec![
KeyedAccount::new(&script.key, true, &mut script.account),
KeyedAccount::new(&rent_id, false, &mut rent_account),
@ -711,7 +711,7 @@ mod tests {
let mut module = LibraAccount::create_module(&code, vec![]);
let rent_id = rent::id();
let mut rent_account = rent::create_account(1, &Rent::default());
let mut rent_account = rent::create_account(1, &Rent::free());
let mut keyed_accounts = vec![
KeyedAccount::new(&module.key, true, &mut module.account),
KeyedAccount::new(&rent_id, false, &mut rent_account),
@ -735,7 +735,7 @@ mod tests {
import 0x0.LibraAccount;
import 0x0.LibraCoin;
import 0x{}.M;
main(payee: address) {{
let amount: u64;
amount = M.universal_truth();
@ -750,7 +750,7 @@ mod tests {
let mut payee = LibraAccount::create_unallocated(BIG_ENOUGH);
let rent_id = rent::id();
let mut rent_account = rent::create_account(1, &Rent::default());
let mut rent_account = rent::create_account(1, &Rent::free());
let mut keyed_accounts = vec![
KeyedAccount::new(&script.key, true, &mut script.account),
KeyedAccount::new(&rent_id, false, &mut rent_account),
@ -803,7 +803,7 @@ mod tests {
let mut payee = LibraAccount::create_unallocated(BIG_ENOUGH);
let rent_id = rent::id();
let mut rent_account = rent::create_account(1, &Rent::default());
let mut rent_account = rent::create_account(1, &Rent::free());
let mut keyed_accounts = vec![
KeyedAccount::new(&script.key, true, &mut script.account),
KeyedAccount::new(&rent_id, false, &mut rent_account),

View File

@ -1393,7 +1393,7 @@ mod tests {
&Lockup::default(),
&Rent {
lamports_per_byte_year: 42,
..Rent::default()
..Rent::free()
},
),
Err(InstructionError::InsufficientFunds)
@ -1407,7 +1407,7 @@ mod tests {
epoch: 1,
custodian
},
&Rent::default(),
&Rent::free(),
),
Ok(())
);
@ -1431,7 +1431,7 @@ mod tests {
stake_keyed_account.initialize(
&Authorized::default(),
&Lockup::default(),
&Rent::default()
&Rent::free()
),
Err(InstructionError::InvalidAccountData)
);
@ -1559,7 +1559,7 @@ mod tests {
epoch: 0,
custodian,
},
&Rent::default(),
&Rent::free(),
)
.unwrap();

View File

@ -210,7 +210,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) {
Rent::default().create_account(1)
Rent::free().create_account(1)
} else {
Account::default()
}

View File

@ -4390,6 +4390,7 @@ mod tests {
F: FnMut(&mut GenesisConfig),
{
let (mut genesis_config, mint_keypair) = create_genesis_config(supply_lamports);
genesis_config.rent.lamports_per_byte_year = 0;
genesis_cfg_fn(&mut genesis_config);
let mut bank = Arc::new(Bank::new(&genesis_config));

View File

@ -95,7 +95,8 @@ pub(crate) mod tests {
#[test]
fn test_store_and_recover() {
let (genesis_config, mint_keypair) = create_genesis_config(1000);
let (mut genesis_config, mint_keypair) = create_genesis_config(1000);
genesis_config.rent.lamports_per_byte_year = 0;
let mint_pubkey = mint_keypair.pubkey();
let archiver_keypair = Keypair::new();
let archiver_pubkey = archiver_keypair.pubkey();

View File

@ -172,7 +172,7 @@ mod tests {
vec![(0u64, &Hash::default()); 32].into_iter(),
)
} else if sysvar::rent::check_id(&meta.pubkey) {
sysvar::rent::create_account(1, &Rent::default())
sysvar::rent::create_account(1, &Rent::free())
} else {
Account::default()
}
@ -276,7 +276,7 @@ mod tests {
KeyedAccount::new(
&sysvar::rent::id(),
false,
&mut sysvar::rent::create_account(1, &Rent::default()),
&mut sysvar::rent::create_account(1, &Rent::free()),
),
],
&serialize(&NonceInstruction::Initialize).unwrap(),
@ -409,7 +409,7 @@ mod tests {
KeyedAccount::new(
&sysvar::rent::id(),
false,
&mut sysvar::rent::create_account(1, &Rent::default())
&mut sysvar::rent::create_account(1, &Rent::free())
),
],
&serialize(&NonceInstruction::Withdraw(42)).unwrap(),
@ -526,7 +526,7 @@ mod tests {
KeyedAccount::new(
&sysvar::rent::id(),
false,
&mut sysvar::rent::create_account(1, &Rent::default())
&mut sysvar::rent::create_account(1, &Rent::free())
),
],
&serialize(&NonceInstruction::Initialize).unwrap(),

View File

@ -18,7 +18,7 @@ pub struct Rent {
/// $1 per SOL
/// $0.01 per megabyte day
/// $3.65 per megabyte year
pub const DEFAULT_LAMPORTS_PER_BYTE_YEAR: u64 = 0; //1_000_000_000 / 100 * 365 / (1024 * 1024);
pub const DEFAULT_LAMPORTS_PER_BYTE_YEAR: u64 = 1_000_000_000 / 100 * 365 / (1024 * 1024);
/// default amount of time (in years) the balance has to include rent for
pub const DEFAULT_EXEMPTION_THRESHOLD: f64 = 2.0;