Skip to content

Commit

Permalink
Cleanup - reject_vote_account_close_unless_zero_credit_epoch (solana-…
Browse files Browse the repository at this point in the history
…labs#31761)

reject_vote_account_close_unless_zero_credit_epoch
  • Loading branch information
Lichtso authored May 23, 2023
1 parent 91a5703 commit f6ebd82
Showing 2 changed files with 8 additions and 36 deletions.
35 changes: 3 additions & 32 deletions programs/vote/src/vote_processor.rs
Original file line number Diff line number Diff line change
@@ -224,15 +224,7 @@ declare_process_instruction!(process_instruction, 2100, |invoke_context| {
VoteInstruction::Withdraw(lamports) => {
instruction_context.check_number_of_instruction_accounts(2)?;
let rent_sysvar = invoke_context.get_sysvar_cache().get_rent()?;

let clock_if_feature_active = if invoke_context
.feature_set
.is_active(&feature_set::reject_vote_account_close_unless_zero_credit_epoch::id())
{
Some(invoke_context.get_sysvar_cache().get_clock()?)
} else {
None
};
let clock_sysvar = invoke_context.get_sysvar_cache().get_clock()?;

drop(me);
vote_state::withdraw(
@@ -243,7 +235,7 @@ declare_process_instruction!(process_instruction, 2100, |invoke_context| {
1,
&signers,
&rent_sysvar,
clock_if_feature_active.as_deref(),
&clock_sysvar,
&invoke_context.feature_set,
)
}
@@ -1230,31 +1222,10 @@ mod tests {
// full withdraw, without 0 credit epoch
instruction_accounts[0].pubkey = vote_pubkey_2;
process_instruction(
&serialize(&VoteInstruction::Withdraw(lamports)).unwrap(),
transaction_accounts.clone(),
instruction_accounts.clone(),
Err(VoteError::ActiveVoteAccountClose.into()),
);

// Following features disabled:
// reject_vote_account_close_unless_zero_credit_epoch

// full withdraw, with 0 credit epoch
instruction_accounts[0].pubkey = vote_pubkey_1;
process_instruction_disabled_features(
&serialize(&VoteInstruction::Withdraw(lamports)).unwrap(),
transaction_accounts.clone(),
instruction_accounts.clone(),
Ok(()),
);

// full withdraw, without 0 credit epoch
instruction_accounts[0].pubkey = vote_pubkey_2;
process_instruction_disabled_features(
&serialize(&VoteInstruction::Withdraw(lamports)).unwrap(),
transaction_accounts,
instruction_accounts,
Ok(()),
Err(VoteError::ActiveVoteAccountClose.into()),
);
}

9 changes: 5 additions & 4 deletions programs/vote/src/vote_state/mod.rs
Original file line number Diff line number Diff line change
@@ -908,7 +908,7 @@ pub fn withdraw<S: std::hash::BuildHasher>(
to_account_index: IndexOfAccount,
signers: &HashSet<Pubkey, S>,
rent_sysvar: &Rent,
clock: Option<&Clock>,
clock: &Clock,
feature_set: &FeatureSet,
) -> Result<(), InstructionError> {
let mut vote_account = instruction_context
@@ -925,9 +925,10 @@ pub fn withdraw<S: std::hash::BuildHasher>(
.ok_or(InstructionError::InsufficientFunds)?;

if remaining_balance == 0 {
let reject_active_vote_account_close = clock
.zip(vote_state.epoch_credits.last())
.map(|(clock, (last_epoch_with_credits, _, _))| {
let reject_active_vote_account_close = vote_state
.epoch_credits
.last()
.map(|(last_epoch_with_credits, _, _)| {
let current_epoch = clock.epoch;
// if current_epoch - last_epoch_with_credits < 2 then the validator has received credits
// either in the current epoch or the previous epoch. If it's >= 2 then it has been at least

0 comments on commit f6ebd82

Please sign in to comment.