stake: Remove v2 program references (#19308)

* stake: Remove v2 program references

* Remove stake v2 feature, along with stake rewrite
This commit is contained in:
Jon Cinque
2021-08-20 01:08:44 -04:00
committed by GitHub
parent 2a877ae06e
commit 73aa004c59
11 changed files with 100 additions and 618 deletions

View File

@ -1021,8 +1021,6 @@ pub struct Bank {
pub lazy_rent_collection: AtomicBool,
pub no_stake_rewrite: AtomicBool,
// this is temporary field only to remove rewards_pool entirely
pub rewards_pool_pubkeys: Arc<HashSet<Pubkey>>,
@ -1159,7 +1157,6 @@ impl Bank {
rewards: RwLock::<Vec<(Pubkey, RewardInfo)>>::default(),
cluster_type: Option::<ClusterType>::default(),
lazy_rent_collection: AtomicBool::default(),
no_stake_rewrite: AtomicBool::default(),
rewards_pool_pubkeys: Arc::<HashSet<Pubkey>>::default(),
cached_executors: RwLock::<CowCachedExecutors>::default(),
transaction_debug_keys: Option::<Arc<HashSet<Pubkey>>>::default(),
@ -1369,7 +1366,6 @@ impl Bank {
rewards: RwLock::new(vec![]),
cluster_type: parent.cluster_type,
lazy_rent_collection: AtomicBool::new(parent.lazy_rent_collection.load(Relaxed)),
no_stake_rewrite: AtomicBool::new(parent.no_stake_rewrite.load(Relaxed)),
rewards_pool_pubkeys: parent.rewards_pool_pubkeys.clone(),
cached_executors: RwLock::new(
(*parent.cached_executors.read().unwrap()).clone_with_epoch(epoch),
@ -1410,11 +1406,7 @@ impl Bank {
new.apply_feature_activations(false, false);
}
let cloned = new
.stakes
.read()
.unwrap()
.clone_with_epoch(epoch, new.stake_program_v2_enabled());
let cloned = new.stakes.read().unwrap().clone_with_epoch(epoch);
*new.stakes.write().unwrap() = cloned;
let leader_schedule_epoch = epoch_schedule.get_leader_schedule_epoch(slot);
@ -1524,7 +1516,6 @@ impl Bank {
rewards: new(),
cluster_type: Some(genesis_config.cluster_type),
lazy_rent_collection: new(),
no_stake_rewrite: new(),
rewards_pool_pubkeys: new(),
cached_executors: RwLock::new(CowCachedExecutors::new(Arc::new(RwLock::new(
CachedExecutors::new(MAX_CACHED_EXECUTORS, fields.epoch),
@ -1936,41 +1927,6 @@ impl Bank {
self.epoch_schedule.get_slots_in_epoch(prev_epoch) as f64 / self.slots_per_year
}
fn rewrite_stakes(&self) -> (usize, usize) {
let mut examined_count = 0;
let mut rewritten_count = 0;
self.cloned_stake_delegations()
.into_iter()
.for_each(|(stake_pubkey, _delegation)| {
examined_count += 1;
if let Some(mut stake_account) = self.get_account_with_fixed_root(&stake_pubkey) {
if let Ok(result) =
stake_state::rewrite_stakes(&mut stake_account, &self.rent_collector.rent)
{
self.store_account(&stake_pubkey, &stake_account);
let message = format!("rewrote stake: {}, {:?}", stake_pubkey, result);
info!("{}", message);
datapoint_info!("stake_info", ("info", message, String));
rewritten_count += 1;
}
}
});
info!(
"bank (slot: {}): rewrite_stakes: {} accounts rewritten / {} accounts examined",
self.slot(),
rewritten_count,
examined_count,
);
datapoint_info!(
"rewrite-stakes",
("examined_count", examined_count, i64),
("rewritten_count", rewritten_count, i64)
);
(examined_count, rewritten_count)
}
// Calculates the starting-slot for inflation from the activation slot.
// This method assumes that `pico_inflation` will be enabled before `full_inflation`, giving
// precedence to the latter. However, since `pico_inflation` is fixed-rate Inflation, should
@ -2037,12 +1993,8 @@ impl Bank {
let old_vote_balance_and_staked = self.stakes.read().unwrap().vote_balance_and_staked();
let validator_point_value = self.pay_validator_rewards(
prev_epoch,
validator_rewards,
reward_calc_tracer,
self.stake_program_v2_enabled(),
);
let validator_point_value =
self.pay_validator_rewards(prev_epoch, validator_rewards, reward_calc_tracer);
if !self
.feature_set
@ -2179,7 +2131,6 @@ impl Bank {
rewarded_epoch: Epoch,
rewards: u64,
reward_calc_tracer: &mut Option<impl FnMut(&RewardCalculationEvent)>,
fix_stake_deactivate: bool,
) -> f64 {
let stake_history = self.stakes.read().unwrap().history().clone();
@ -2193,13 +2144,8 @@ impl Bank {
.map(move |(_stake_pubkey, stake_account)| (stake_account, vote_account))
})
.map(|(stake_account, vote_account)| {
stake_state::calculate_points(
stake_account,
vote_account,
Some(&stake_history),
fix_stake_deactivate,
)
.unwrap_or(0)
stake_state::calculate_points(stake_account, vote_account, Some(&stake_history))
.unwrap_or(0)
})
.sum();
@ -2243,7 +2189,6 @@ impl Bank {
&point_value,
Some(&stake_history),
&mut reward_calc_tracer.as_mut(),
fix_stake_deactivate,
);
if let Ok((stakers_reward, _voters_reward)) = redeemed {
self.store_account(stake_pubkey, stake_account);
@ -3961,7 +3906,6 @@ impl Bank {
#[cfg(test)]
fn restore_old_behavior_for_fragile_tests(&self) {
self.lazy_rent_collection.store(true, Relaxed);
self.no_stake_rewrite.store(true, Relaxed);
}
fn enable_eager_rent_collection(&self) -> bool {
@ -4513,7 +4457,6 @@ impl Bank {
self.stakes.write().unwrap().store(
pubkey,
account,
self.stake_program_v2_enabled(),
self.check_init_vote_data_enabled(),
);
}
@ -5221,7 +5164,6 @@ impl Bank {
if let Some(old_vote_account) = self.stakes.write().unwrap().store(
pubkey,
account,
self.stake_program_v2_enabled(),
self.check_init_vote_data_enabled(),
) {
// TODO: one of the indices is redundant.
@ -5447,11 +5389,6 @@ impl Bank {
.is_active(&feature_set::no_overflow_rent_distribution::id())
}
pub fn stake_program_v2_enabled(&self) -> bool {
self.feature_set
.is_active(&feature_set::stake_program_v2::id())
}
pub fn check_init_vote_data_enabled(&self) -> bool {
self.feature_set
.is_active(&feature_set::check_init_vote_data::id())
@ -5531,16 +5468,6 @@ impl Bank {
if new_feature_activations.contains(&feature_set::spl_token_v2_set_authority_fix::id()) {
self.apply_spl_token_v2_set_authority_fix();
}
// Remove me after a while around v1.6
if !self.no_stake_rewrite.load(Relaxed)
&& new_feature_activations.contains(&feature_set::rewrite_stake::id())
{
// to avoid any potential risk of wrongly rewriting accounts in the future,
// only do this once, taking small risk of unknown
// bugs which again creates bad stake accounts..
self.rewrite_stakes();
}
if new_feature_activations.contains(&feature_set::rent_for_sysvars::id()) {
// when this feature is activated, immediately all of existing sysvars are susceptible
// to rent collection and account data removal due to insufficient balance due to only
@ -7836,7 +7763,7 @@ pub(crate) mod tests {
.map(move |(_stake_pubkey, stake_account)| (stake_account, vote_account))
})
.map(|(stake_account, vote_account)| {
stake_state::calculate_points(stake_account, vote_account, None, true).unwrap_or(0)
stake_state::calculate_points(stake_account, vote_account, None).unwrap_or(0)
})
.sum();
@ -9382,7 +9309,7 @@ pub(crate) mod tests {
// epoch_stakes are a snapshot at the leader_schedule_slot_offset boundary
// in the prior epoch (0 in this case)
assert_eq!(
leader_stake.stake(0, None, true),
leader_stake.stake(0, None),
vote_accounts.unwrap().get(&leader_vote_account).unwrap().0
);
@ -9398,7 +9325,7 @@ pub(crate) mod tests {
assert!(child.epoch_vote_accounts(epoch).is_some());
assert_eq!(
leader_stake.stake(child.epoch(), None, true),
leader_stake.stake(child.epoch(), None),
child
.epoch_vote_accounts(epoch)
.unwrap()
@ -9416,7 +9343,7 @@ pub(crate) mod tests {
);
assert!(child.epoch_vote_accounts(epoch).is_some());
assert_eq!(
leader_stake.stake(child.epoch(), None, true),
leader_stake.stake(child.epoch(), None),
child
.epoch_vote_accounts(epoch)
.unwrap()
@ -13365,26 +13292,6 @@ pub(crate) mod tests {
}
}
#[test]
fn test_stake_rewrite() {
let GenesisConfigInfo { genesis_config, .. } =
create_genesis_config_with_leader(500, &solana_sdk::pubkey::new_rand(), 1);
let bank = Arc::new(Bank::new_for_tests(&genesis_config));
// quickest way of creting bad stake account
let bootstrap_stake_pubkey = bank
.cloned_stake_delegations()
.keys()
.next()
.copied()
.unwrap();
let mut bootstrap_stake_account = bank.get_account(&bootstrap_stake_pubkey).unwrap();
bootstrap_stake_account.set_lamports(10000000);
bank.store_account(&bootstrap_stake_pubkey, &bootstrap_stake_account);
assert_eq!(bank.rewrite_stakes(), (1, 1));
}
#[test]
fn test_get_inflation_start_slot_devnet_testnet() {
let GenesisConfigInfo {

View File

@ -39,7 +39,7 @@ impl Stakes {
pub fn history(&self) -> &StakeHistory {
&self.stake_history
}
pub fn clone_with_epoch(&self, next_epoch: Epoch, fix_stake_deactivate: bool) -> Self {
pub fn clone_with_epoch(&self, next_epoch: Epoch) -> Self {
let prev_epoch = self.epoch;
if prev_epoch == next_epoch {
self.clone()
@ -54,7 +54,6 @@ impl Stakes {
.iter()
.map(|(_pubkey, stake_delegation)| stake_delegation),
Some(&self.stake_history),
fix_stake_deactivate,
),
);
@ -67,7 +66,6 @@ impl Stakes {
pubkey,
next_epoch,
Some(&stake_history_upto_prev_epoch),
fix_stake_deactivate,
);
(*pubkey, (stake, account.clone()))
})
@ -89,13 +87,12 @@ impl Stakes {
voter_pubkey: &Pubkey,
epoch: Epoch,
stake_history: Option<&StakeHistory>,
fix_stake_deactivate: bool,
) -> u64 {
self.stake_delegations
.iter()
.map(|(_, stake_delegation)| {
if &stake_delegation.voter_pubkey == voter_pubkey {
stake_delegation.stake(epoch, stake_history, fix_stake_deactivate)
stake_delegation.stake(epoch, stake_history)
} else {
0
}
@ -125,7 +122,6 @@ impl Stakes {
&mut self,
pubkey: &Pubkey,
account: &AccountSharedData,
fix_stake_deactivate: bool,
check_vote_init: bool,
) -> Option<VoteAccount> {
if solana_vote_program::check_id(account.owner()) {
@ -139,14 +135,7 @@ impl Stakes {
&& !(check_vote_init && VoteState::is_uninitialized_no_deser(account.data()))
{
let stake = old.as_ref().map_or_else(
|| {
self.calculate_stake(
pubkey,
self.epoch,
Some(&self.stake_history),
fix_stake_deactivate,
)
},
|| self.calculate_stake(pubkey, self.epoch, Some(&self.stake_history)),
|v| v.0,
);
@ -159,7 +148,7 @@ impl Stakes {
let old_stake = self.stake_delegations.get(pubkey).map(|delegation| {
(
delegation.voter_pubkey,
delegation.stake(self.epoch, Some(&self.stake_history), fix_stake_deactivate),
delegation.stake(self.epoch, Some(&self.stake_history)),
)
});
@ -169,11 +158,7 @@ impl Stakes {
(
delegation.voter_pubkey,
if account.lamports() != 0 {
delegation.stake(
self.epoch,
Some(&self.stake_history),
fix_stake_deactivate,
)
delegation.stake(self.epoch, Some(&self.stake_history))
} else {
// when account is removed (lamports == 0), this special `else` clause ensures
// resetting cached stake value below, even if the account happens to be
@ -312,44 +297,44 @@ pub mod tests {
let ((vote_pubkey, vote_account), (stake_pubkey, mut stake_account)) =
create_staked_node_accounts(10);
stakes.store(&vote_pubkey, &vote_account, true, true);
stakes.store(&stake_pubkey, &stake_account, true, true);
stakes.store(&vote_pubkey, &vote_account, true);
stakes.store(&stake_pubkey, &stake_account, true);
let stake = stake_state::stake_from(&stake_account).unwrap();
{
let vote_accounts = stakes.vote_accounts();
assert!(vote_accounts.get(&vote_pubkey).is_some());
assert_eq!(
vote_accounts.get(&vote_pubkey).unwrap().0,
stake.stake(i, None, true)
stake.stake(i, None)
);
}
stake_account.set_lamports(42);
stakes.store(&stake_pubkey, &stake_account, true, true);
stakes.store(&stake_pubkey, &stake_account, true);
{
let vote_accounts = stakes.vote_accounts();
assert!(vote_accounts.get(&vote_pubkey).is_some());
assert_eq!(
vote_accounts.get(&vote_pubkey).unwrap().0,
stake.stake(i, None, true)
stake.stake(i, None)
); // stays old stake, because only 10 is activated
}
// activate more
let (_stake_pubkey, mut stake_account) = create_stake_account(42, &vote_pubkey);
stakes.store(&stake_pubkey, &stake_account, true, true);
stakes.store(&stake_pubkey, &stake_account, true);
let stake = stake_state::stake_from(&stake_account).unwrap();
{
let vote_accounts = stakes.vote_accounts();
assert!(vote_accounts.get(&vote_pubkey).is_some());
assert_eq!(
vote_accounts.get(&vote_pubkey).unwrap().0,
stake.stake(i, None, true)
stake.stake(i, None)
); // now stake of 42 is activated
}
stake_account.set_lamports(0);
stakes.store(&stake_pubkey, &stake_account, true, true);
stakes.store(&stake_pubkey, &stake_account, true);
{
let vote_accounts = stakes.vote_accounts();
assert!(vote_accounts.get(&vote_pubkey).is_some());
@ -367,14 +352,14 @@ pub mod tests {
let ((vote_pubkey, vote_account), (stake_pubkey, stake_account)) =
create_staked_node_accounts(10);
stakes.store(&vote_pubkey, &vote_account, true, true);
stakes.store(&stake_pubkey, &stake_account, true, true);
stakes.store(&vote_pubkey, &vote_account, true);
stakes.store(&stake_pubkey, &stake_account, true);
let ((vote11_pubkey, vote11_account), (stake11_pubkey, stake11_account)) =
create_staked_node_accounts(20);
stakes.store(&vote11_pubkey, &vote11_account, true, true);
stakes.store(&stake11_pubkey, &stake11_account, true, true);
stakes.store(&vote11_pubkey, &vote11_account, true);
stakes.store(&stake11_pubkey, &stake11_account, true);
let vote11_node_pubkey = VoteState::from(&vote11_account).unwrap().node_pubkey;
@ -391,8 +376,8 @@ pub mod tests {
let ((vote_pubkey, mut vote_account), (stake_pubkey, stake_account)) =
create_staked_node_accounts(10);
stakes.store(&vote_pubkey, &vote_account, true, true);
stakes.store(&stake_pubkey, &stake_account, true, true);
stakes.store(&vote_pubkey, &vote_account, true);
stakes.store(&stake_pubkey, &stake_account, true);
{
let vote_accounts = stakes.vote_accounts();
@ -401,7 +386,7 @@ pub mod tests {
}
vote_account.set_lamports(0);
stakes.store(&vote_pubkey, &vote_account, true, true);
stakes.store(&vote_pubkey, &vote_account, true);
{
let vote_accounts = stakes.vote_accounts();
@ -409,7 +394,7 @@ pub mod tests {
}
vote_account.set_lamports(1);
stakes.store(&vote_pubkey, &vote_account, true, true);
stakes.store(&vote_pubkey, &vote_account, true);
{
let vote_accounts = stakes.vote_accounts();
@ -422,7 +407,7 @@ pub mod tests {
let mut pushed = vote_account.data().to_vec();
pushed.push(0);
vote_account.set_data(pushed);
stakes.store(&vote_pubkey, &vote_account, true, true);
stakes.store(&vote_pubkey, &vote_account, true);
{
let vote_accounts = stakes.vote_accounts();
@ -433,7 +418,7 @@ pub mod tests {
let default_vote_state = VoteState::default();
let versioned = VoteStateVersions::new_current(default_vote_state);
VoteState::to(&versioned, &mut vote_account).unwrap();
stakes.store(&vote_pubkey, &vote_account, true, true);
stakes.store(&vote_pubkey, &vote_account, true);
{
let vote_accounts = stakes.vote_accounts();
@ -441,7 +426,7 @@ pub mod tests {
}
vote_account.set_data(cache_data);
stakes.store(&vote_pubkey, &vote_account, true, true);
stakes.store(&vote_pubkey, &vote_account, true);
{
let vote_accounts = stakes.vote_accounts();
@ -463,11 +448,11 @@ pub mod tests {
let ((vote_pubkey2, vote_account2), (_stake_pubkey2, stake_account2)) =
create_staked_node_accounts(10);
stakes.store(&vote_pubkey, &vote_account, true, true);
stakes.store(&vote_pubkey2, &vote_account2, true, true);
stakes.store(&vote_pubkey, &vote_account, true);
stakes.store(&vote_pubkey2, &vote_account2, true);
// delegates to vote_pubkey
stakes.store(&stake_pubkey, &stake_account, true, true);
stakes.store(&stake_pubkey, &stake_account, true);
let stake = stake_state::stake_from(&stake_account).unwrap();
@ -476,14 +461,14 @@ pub mod tests {
assert!(vote_accounts.get(&vote_pubkey).is_some());
assert_eq!(
vote_accounts.get(&vote_pubkey).unwrap().0,
stake.stake(stakes.epoch, Some(&stakes.stake_history), true)
stake.stake(stakes.epoch, Some(&stakes.stake_history))
);
assert!(vote_accounts.get(&vote_pubkey2).is_some());
assert_eq!(vote_accounts.get(&vote_pubkey2).unwrap().0, 0);
}
// delegates to vote_pubkey2
stakes.store(&stake_pubkey, &stake_account2, true, true);
stakes.store(&stake_pubkey, &stake_account2, true);
{
let vote_accounts = stakes.vote_accounts();
@ -492,7 +477,7 @@ pub mod tests {
assert!(vote_accounts.get(&vote_pubkey2).is_some());
assert_eq!(
vote_accounts.get(&vote_pubkey2).unwrap().0,
stake.stake(stakes.epoch, Some(&stakes.stake_history), true)
stake.stake(stakes.epoch, Some(&stakes.stake_history))
);
}
}
@ -508,11 +493,11 @@ pub mod tests {
let (stake_pubkey2, stake_account2) = create_stake_account(10, &vote_pubkey);
stakes.store(&vote_pubkey, &vote_account, true, true);
stakes.store(&vote_pubkey, &vote_account, true);
// delegates to vote_pubkey
stakes.store(&stake_pubkey, &stake_account, true, true);
stakes.store(&stake_pubkey2, &stake_account2, true, true);
stakes.store(&stake_pubkey, &stake_account, true);
stakes.store(&stake_pubkey2, &stake_account2, true);
{
let vote_accounts = stakes.vote_accounts();
@ -527,23 +512,23 @@ pub mod tests {
let ((vote_pubkey, vote_account), (stake_pubkey, stake_account)) =
create_staked_node_accounts(10);
stakes.store(&vote_pubkey, &vote_account, true, true);
stakes.store(&stake_pubkey, &stake_account, true, true);
stakes.store(&vote_pubkey, &vote_account, true);
stakes.store(&stake_pubkey, &stake_account, true);
let stake = stake_state::stake_from(&stake_account).unwrap();
{
let vote_accounts = stakes.vote_accounts();
assert_eq!(
vote_accounts.get(&vote_pubkey).unwrap().0,
stake.stake(stakes.epoch, Some(&stakes.stake_history), true)
stake.stake(stakes.epoch, Some(&stakes.stake_history))
);
}
let stakes = stakes.clone_with_epoch(3, true);
let stakes = stakes.clone_with_epoch(3);
{
let vote_accounts = stakes.vote_accounts();
assert_eq!(
vote_accounts.get(&vote_pubkey).unwrap().0,
stake.stake(stakes.epoch, Some(&stakes.stake_history), true)
stake.stake(stakes.epoch, Some(&stakes.stake_history))
);
}
}
@ -558,8 +543,8 @@ pub mod tests {
let ((vote_pubkey, vote_account), (stake_pubkey, stake_account)) =
create_staked_node_accounts(10);
stakes.store(&vote_pubkey, &vote_account, true, true);
stakes.store(&stake_pubkey, &stake_account, true, true);
stakes.store(&vote_pubkey, &vote_account, true);
stakes.store(&stake_pubkey, &stake_account, true);
{
let vote_accounts = stakes.vote_accounts();
@ -572,7 +557,6 @@ pub mod tests {
&stake_pubkey,
&AccountSharedData::new(1, 0, &stake::program::id()),
true,
true,
);
{
let vote_accounts = stakes.vote_accounts();
@ -602,14 +586,14 @@ pub mod tests {
let genesis_epoch = 0;
let ((vote_pubkey, vote_account), (stake_pubkey, stake_account)) =
create_warming_staked_node_accounts(10, genesis_epoch);
stakes.store(&vote_pubkey, &vote_account, true, true);
stakes.store(&stake_pubkey, &stake_account, true, true);
stakes.store(&vote_pubkey, &vote_account, true);
stakes.store(&stake_pubkey, &stake_account, true);
assert_eq!(stakes.vote_balance_and_staked(), 11);
assert_eq!(stakes.vote_balance_and_warmed_staked(), 1);
for (epoch, expected_warmed_stake) in ((genesis_epoch + 1)..=3).zip(&[2, 3, 4]) {
stakes = stakes.clone_with_epoch(epoch, true);
stakes = stakes.clone_with_epoch(epoch);
// vote_balance_and_staked() always remain to return same lamports
// while vote_balance_and_warmed_staked() gradually increases
assert_eq!(stakes.vote_balance_and_staked(), 11);

View File

@ -81,7 +81,6 @@ fn warmed_up(bank: &Bank, stake_pubkey: &Pubkey) -> bool {
)
.unwrap(),
),
true,
)
}
@ -96,7 +95,6 @@ fn get_staked(bank: &Bank, stake_pubkey: &Pubkey) -> u64 {
)
.unwrap(),
),
true,
)
}