clean feature: require_custodian_for_locked_stake_authorize (#34075)

This commit is contained in:
Justin Starry 2023-11-16 20:36:24 +08:00 committed by GitHub
parent f349d71605
commit 87d20aecbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 90 deletions

View File

@ -12,7 +12,6 @@ use {
declare_process_instruction, sysvar_cache::get_sysvar_with_account_check,
},
solana_sdk::{
clock::Clock,
feature_set,
instruction::InstructionError,
program_utils::limited_deserialize,
@ -78,78 +77,41 @@ declare_process_instruction!(Entrypoint, DEFAULT_COMPUTE_UNITS, |invoke_context|
}
Ok(StakeInstruction::Authorize(authorized_pubkey, stake_authorize)) => {
let mut me = get_stake_account()?;
let require_custodian_for_locked_stake_authorize = invoke_context
.feature_set
.is_active(&feature_set::require_custodian_for_locked_stake_authorize::id());
let clock =
get_sysvar_with_account_check::clock(invoke_context, instruction_context, 1)?;
instruction_context.check_number_of_instruction_accounts(3)?;
let custodian_pubkey =
get_optional_pubkey(transaction_context, instruction_context, 3, false)?;
if require_custodian_for_locked_stake_authorize {
let clock =
get_sysvar_with_account_check::clock(invoke_context, instruction_context, 1)?;
instruction_context.check_number_of_instruction_accounts(3)?;
let custodian_pubkey =
get_optional_pubkey(transaction_context, instruction_context, 3, false)?;
authorize(
&mut me,
&signers,
&authorized_pubkey,
stake_authorize,
require_custodian_for_locked_stake_authorize,
&clock,
custodian_pubkey,
)
} else {
authorize(
&mut me,
&signers,
&authorized_pubkey,
stake_authorize,
require_custodian_for_locked_stake_authorize,
&Clock::default(),
None,
)
}
authorize(
&mut me,
&signers,
&authorized_pubkey,
stake_authorize,
&clock,
custodian_pubkey,
)
}
Ok(StakeInstruction::AuthorizeWithSeed(args)) => {
let mut me = get_stake_account()?;
instruction_context.check_number_of_instruction_accounts(2)?;
let require_custodian_for_locked_stake_authorize = invoke_context
.feature_set
.is_active(&feature_set::require_custodian_for_locked_stake_authorize::id());
if require_custodian_for_locked_stake_authorize {
let clock =
get_sysvar_with_account_check::clock(invoke_context, instruction_context, 2)?;
let custodian_pubkey =
get_optional_pubkey(transaction_context, instruction_context, 3, false)?;
let clock =
get_sysvar_with_account_check::clock(invoke_context, instruction_context, 2)?;
let custodian_pubkey =
get_optional_pubkey(transaction_context, instruction_context, 3, false)?;
authorize_with_seed(
transaction_context,
instruction_context,
&mut me,
1,
&args.authority_seed,
&args.authority_owner,
&args.new_authorized_pubkey,
args.stake_authorize,
require_custodian_for_locked_stake_authorize,
&clock,
custodian_pubkey,
)
} else {
authorize_with_seed(
transaction_context,
instruction_context,
&mut me,
1,
&args.authority_seed,
&args.authority_owner,
&args.new_authorized_pubkey,
args.stake_authorize,
require_custodian_for_locked_stake_authorize,
&Clock::default(),
None,
)
}
authorize_with_seed(
transaction_context,
instruction_context,
&mut me,
1,
&args.authority_seed,
&args.authority_owner,
&args.new_authorized_pubkey,
args.stake_authorize,
&clock,
custodian_pubkey,
)
}
Ok(StakeInstruction::DelegateStake) => {
let me = get_stake_account()?;
@ -316,7 +278,6 @@ declare_process_instruction!(Entrypoint, DEFAULT_COMPUTE_UNITS, |invoke_context|
&signers,
authorized_pubkey,
stake_authorize,
true,
&clock,
custodian_pubkey,
)
@ -352,7 +313,6 @@ declare_process_instruction!(Entrypoint, DEFAULT_COMPUTE_UNITS, |invoke_context|
&args.authority_owner,
authorized_pubkey,
args.stake_authorize,
true,
&clock,
custodian_pubkey,
)
@ -460,7 +420,7 @@ mod tests {
WritableAccount,
},
account_utils::StateMut,
clock::{Epoch, UnixTimestamp},
clock::{Clock, Epoch, UnixTimestamp},
epoch_schedule::EpochSchedule,
feature_set::FeatureSet,
instruction::{AccountMeta, Instruction},

View File

@ -506,7 +506,6 @@ pub fn authorize(
signers: &HashSet<Pubkey>,
new_authority: &Pubkey,
stake_authorize: StakeAuthorize,
require_custodian_for_locked_stake_authorize: bool,
clock: &Clock,
custodian: Option<&Pubkey>,
) -> Result<(), InstructionError> {
@ -516,11 +515,7 @@ pub fn authorize(
signers,
new_authority,
stake_authorize,
if require_custodian_for_locked_stake_authorize {
Some((&meta.lockup, clock, custodian))
} else {
None
},
Some((&meta.lockup, clock, custodian)),
)?;
stake_account.set_state(&StakeStateV2::Stake(meta, stake, stake_flags))
}
@ -529,11 +524,7 @@ pub fn authorize(
signers,
new_authority,
stake_authorize,
if require_custodian_for_locked_stake_authorize {
Some((&meta.lockup, clock, custodian))
} else {
None
},
Some((&meta.lockup, clock, custodian)),
)?;
stake_account.set_state(&StakeStateV2::Initialized(meta))
}
@ -551,7 +542,6 @@ pub fn authorize_with_seed(
authority_owner: &Pubkey,
new_authority: &Pubkey,
stake_authorize: StakeAuthorize,
require_custodian_for_locked_stake_authorize: bool,
clock: &Clock,
custodian: Option<&Pubkey>,
) -> Result<(), InstructionError> {
@ -572,7 +562,6 @@ pub fn authorize_with_seed(
&signers,
new_authority,
stake_authorize,
require_custodian_for_locked_stake_authorize,
clock,
custodian,
)
@ -1865,13 +1854,6 @@ mod tests {
..Clock::default()
};
// Legacy behaviour when the `require_custodian_for_locked_stake_authorize` feature is
// inactive
assert_eq!(
authorized.authorize(&signers, &staker, StakeAuthorize::Withdrawer, None),
Ok(())
);
// No lockup, no custodian
assert_eq!(
authorized.authorize(