add rent reserve for bootstrap stakes (#6876)
* genesis investor stakes * assert rent is sufficient for these bootstrappers
This commit is contained in:
parent
73e3fc7c4f
commit
bb00904fc8
|
@ -438,11 +438,13 @@ mod tests {
|
||||||
let sk1 = Pubkey::new_rand();
|
let sk1 = Pubkey::new_rand();
|
||||||
let pk1 = Pubkey::new_rand();
|
let pk1 = Pubkey::new_rand();
|
||||||
let mut vote_account1 = vote_state::create_account(&pk1, &Pubkey::new_rand(), 0, 100);
|
let mut vote_account1 = vote_state::create_account(&pk1, &Pubkey::new_rand(), 0, 100);
|
||||||
let stake_account1 = stake_state::create_account(&sk1, &pk1, &vote_account1, 100);
|
let stake_account1 =
|
||||||
|
stake_state::create_account(&sk1, &pk1, &vote_account1, &genesis_config.rent, 100);
|
||||||
let sk2 = Pubkey::new_rand();
|
let sk2 = Pubkey::new_rand();
|
||||||
let pk2 = Pubkey::new_rand();
|
let pk2 = Pubkey::new_rand();
|
||||||
let mut vote_account2 = vote_state::create_account(&pk2, &Pubkey::new_rand(), 0, 50);
|
let mut vote_account2 = vote_state::create_account(&pk2, &Pubkey::new_rand(), 0, 50);
|
||||||
let stake_account2 = stake_state::create_account(&sk2, &pk2, &vote_account2, 50);
|
let stake_account2 =
|
||||||
|
stake_state::create_account(&sk2, &pk2, &vote_account2, &genesis_config.rent, 50);
|
||||||
|
|
||||||
genesis_config.accounts.extend(vec![
|
genesis_config.accounts.extend(vec![
|
||||||
(pk1, vote_account1.clone()),
|
(pk1, vote_account1.clone()),
|
||||||
|
|
|
@ -319,10 +319,18 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
||||||
|
|
||||||
let bootstrap_leader_vote_account =
|
let bootstrap_leader_vote_account =
|
||||||
vote_state::create_account(&bootstrap_vote_pubkey, &bootstrap_leader_pubkey, 0, 1);
|
vote_state::create_account(&bootstrap_vote_pubkey, &bootstrap_leader_pubkey, 0, 1);
|
||||||
|
|
||||||
|
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_stake_account = stake_state::create_account(
|
let bootstrap_leader_stake_account = stake_state::create_account(
|
||||||
&bootstrap_leader_pubkey,
|
&bootstrap_leader_pubkey,
|
||||||
&bootstrap_vote_pubkey,
|
&bootstrap_vote_pubkey,
|
||||||
&bootstrap_leader_vote_account,
|
&bootstrap_leader_vote_account,
|
||||||
|
&rent,
|
||||||
bootstrap_leader_stake_lamports,
|
bootstrap_leader_stake_lamports,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -352,12 +360,6 @@ 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 = 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 mut poh_config = PohConfig::default();
|
let mut poh_config = PohConfig::default();
|
||||||
poh_config.target_tick_duration =
|
poh_config.target_tick_duration =
|
||||||
Duration::from_millis(value_t_or_exit!(matches, "target_tick_duration", u64));
|
Duration::from_millis(value_t_or_exit!(matches, "target_tick_duration", u64));
|
||||||
|
|
|
@ -356,16 +356,6 @@ impl Stake {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_bootstrap(stake: u64, voter_pubkey: &Pubkey, vote_state: &VoteState) -> Self {
|
|
||||||
Self::new(
|
|
||||||
stake,
|
|
||||||
voter_pubkey,
|
|
||||||
vote_state,
|
|
||||||
std::u64::MAX,
|
|
||||||
&Config::default(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn redelegate(
|
fn redelegate(
|
||||||
&mut self,
|
&mut self,
|
||||||
voter_pubkey: &Pubkey,
|
voter_pubkey: &Pubkey,
|
||||||
|
@ -779,24 +769,30 @@ pub fn create_account(
|
||||||
authorized: &Pubkey,
|
authorized: &Pubkey,
|
||||||
voter_pubkey: &Pubkey,
|
voter_pubkey: &Pubkey,
|
||||||
vote_account: &Account,
|
vote_account: &Account,
|
||||||
|
rent: &Rent,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
) -> Account {
|
) -> Account {
|
||||||
let mut stake_account = Account::new(lamports, std::mem::size_of::<StakeState>(), &id());
|
let mut stake_account = Account::new(lamports, std::mem::size_of::<StakeState>(), &id());
|
||||||
|
|
||||||
let vote_state = VoteState::from(vote_account).expect("vote_state");
|
let vote_state = VoteState::from(vote_account).expect("vote_state");
|
||||||
|
let rent_exempt_reserve = rent.minimum_balance(std::mem::size_of::<StakeState>());
|
||||||
stake_account
|
stake_account
|
||||||
.set_state(&StakeState::Stake(
|
.set_state(&StakeState::Stake(
|
||||||
Meta {
|
Meta {
|
||||||
rent_exempt_reserve: Rent::default()
|
rent_exempt_reserve,
|
||||||
.minimum_balance(std::mem::size_of::<StakeState>()),
|
|
||||||
authorized: Authorized {
|
authorized: Authorized {
|
||||||
staker: *authorized,
|
staker: *authorized,
|
||||||
withdrawer: *authorized,
|
withdrawer: *authorized,
|
||||||
},
|
},
|
||||||
lockup: Lockup::default(),
|
lockup: Lockup::default(),
|
||||||
},
|
},
|
||||||
Stake::new_bootstrap(lamports, voter_pubkey, &vote_state),
|
Stake::new(
|
||||||
|
lamports - rent_exempt_reserve, // underflow is an error, assert!(lamports> rent_exempt_reserve);
|
||||||
|
voter_pubkey,
|
||||||
|
&vote_state,
|
||||||
|
std::u64::MAX,
|
||||||
|
&Config::default(),
|
||||||
|
),
|
||||||
))
|
))
|
||||||
.expect("set_state");
|
.expect("set_state");
|
||||||
|
|
||||||
|
@ -1737,7 +1733,13 @@ mod tests {
|
||||||
let mut vote_state = VoteState::default();
|
let mut vote_state = VoteState::default();
|
||||||
// assume stake.stake() is right
|
// assume stake.stake() is right
|
||||||
// bootstrap means fully-vested stake at epoch 0
|
// bootstrap means fully-vested stake at epoch 0
|
||||||
let mut stake = Stake::new_bootstrap(1, &Pubkey::default(), &vote_state);
|
let mut stake = Stake::new(
|
||||||
|
1,
|
||||||
|
&Pubkey::default(),
|
||||||
|
&vote_state,
|
||||||
|
std::u64::MAX,
|
||||||
|
&Config::default(),
|
||||||
|
);
|
||||||
|
|
||||||
// this one can't collect now, credits_observed == vote_state.credits()
|
// this one can't collect now, credits_observed == vote_state.credits()
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
|
@ -3,6 +3,7 @@ use solana_sdk::{
|
||||||
fee_calculator::FeeCalculator,
|
fee_calculator::FeeCalculator,
|
||||||
genesis_config::GenesisConfig,
|
genesis_config::GenesisConfig,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
|
rent::Rent,
|
||||||
signature::{Keypair, KeypairUtil},
|
signature::{Keypair, KeypairUtil},
|
||||||
system_program::{self, solana_system_program},
|
system_program::{self, solana_system_program},
|
||||||
};
|
};
|
||||||
|
@ -39,10 +40,13 @@ pub fn create_genesis_config_with_leader(
|
||||||
bootstrap_leader_stake_lamports,
|
bootstrap_leader_stake_lamports,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let rent = Rent::free();
|
||||||
|
|
||||||
let stake_account = stake_state::create_account(
|
let stake_account = stake_state::create_account(
|
||||||
&staking_keypair.pubkey(),
|
&staking_keypair.pubkey(),
|
||||||
&voting_keypair.pubkey(),
|
&voting_keypair.pubkey(),
|
||||||
&vote_account,
|
&vote_account,
|
||||||
|
&rent,
|
||||||
bootstrap_leader_stake_lamports,
|
bootstrap_leader_stake_lamports,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -77,6 +81,7 @@ pub fn create_genesis_config_with_leader(
|
||||||
accounts,
|
accounts,
|
||||||
native_instruction_processors,
|
native_instruction_processors,
|
||||||
fee_calculator,
|
fee_calculator,
|
||||||
|
rent,
|
||||||
..GenesisConfig::default()
|
..GenesisConfig::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -209,7 +209,7 @@ impl Stakes {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub mod tests {
|
pub mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::{pubkey::Pubkey, rent::Rent};
|
||||||
use solana_stake_api::stake_state;
|
use solana_stake_api::stake_state;
|
||||||
use solana_vote_api::vote_state::{self, VoteState, MAX_LOCKOUT_HISTORY};
|
use solana_vote_api::vote_state::{self, VoteState, MAX_LOCKOUT_HISTORY};
|
||||||
|
|
||||||
|
@ -232,6 +232,7 @@ pub mod tests {
|
||||||
&stake_pubkey,
|
&stake_pubkey,
|
||||||
&vote_pubkey,
|
&vote_pubkey,
|
||||||
&vote_state::create_account(&vote_pubkey, &Pubkey::new_rand(), 0, 1),
|
&vote_state::create_account(&vote_pubkey, &Pubkey::new_rand(), 0, 1),
|
||||||
|
&Rent::free(),
|
||||||
stake,
|
stake,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
|
@ -59,6 +59,13 @@ impl Rent {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn free() -> Self {
|
||||||
|
Self {
|
||||||
|
lamports_per_byte_year: 0,
|
||||||
|
..Rent::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
Loading…
Reference in New Issue