Cleanup - reject_vote_account_close_unless_zero_credit_epoch (#31761)
reject_vote_account_close_unless_zero_credit_epoch
This commit is contained in:
parent
91a57039d0
commit
f6ebd8218d
|
@ -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()),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue