From 42a86660daf5e933141941c00526e209a8ffae2f Mon Sep 17 00:00:00 2001 From: hanako mumei <81144685+2501babe@users.noreply.github.com> Date: Tue, 4 Jun 2024 13:44:56 -0700 Subject: [PATCH] add feature gate --- programs/stake/src/stake_instruction.rs | 98 ++++++++++++++----------- sdk/src/feature_set.rs | 5 ++ 2 files changed, 61 insertions(+), 42 deletions(-) diff --git a/programs/stake/src/stake_instruction.rs b/programs/stake/src/stake_instruction.rs index 270f5f13ef8932..e6cf2a2320c22e 100644 --- a/programs/stake/src/stake_instruction.rs +++ b/programs/stake/src/stake_instruction.rs @@ -355,51 +355,65 @@ declare_process_instruction!(Entrypoint, DEFAULT_COMPUTE_UNITS, |invoke_context| } StakeInstruction::MoveStake(lamports) => { let me = get_stake_account()?; - instruction_context.check_number_of_instruction_accounts(2)?; - let clock = - get_sysvar_with_account_check::clock(invoke_context, instruction_context, 2)?; - let stake_history = get_sysvar_with_account_check::stake_history( - invoke_context, - instruction_context, - 3, - )?; - instruction_context.check_number_of_instruction_accounts(5)?; - drop(me); - move_stake( - invoke_context, - transaction_context, - instruction_context, - 0, - lamports, - 1, - &clock, - &stake_history, - 4, - ) + if invoke_context + .get_feature_set() + .is_active(&feature_set::move_stake_and_move_lamports_ixs::id()) + { + instruction_context.check_number_of_instruction_accounts(2)?; + let clock = + get_sysvar_with_account_check::clock(invoke_context, instruction_context, 2)?; + let stake_history = get_sysvar_with_account_check::stake_history( + invoke_context, + instruction_context, + 3, + )?; + instruction_context.check_number_of_instruction_accounts(5)?; + drop(me); + move_stake( + invoke_context, + transaction_context, + instruction_context, + 0, + lamports, + 1, + &clock, + &stake_history, + 4, + ) + } else { + Err(InstructionError::InvalidInstructionData) + } } StakeInstruction::MoveLamports(lamports) => { let me = get_stake_account()?; - instruction_context.check_number_of_instruction_accounts(2)?; - let clock = - get_sysvar_with_account_check::clock(invoke_context, instruction_context, 2)?; - let stake_history = get_sysvar_with_account_check::stake_history( - invoke_context, - instruction_context, - 3, - )?; - instruction_context.check_number_of_instruction_accounts(5)?; - drop(me); - move_lamports( - invoke_context, - transaction_context, - instruction_context, - 0, - lamports, - 1, - &clock, - &stake_history, - 4, - ) + if invoke_context + .get_feature_set() + .is_active(&feature_set::move_stake_and_move_lamports_ixs::id()) + { + instruction_context.check_number_of_instruction_accounts(2)?; + let clock = + get_sysvar_with_account_check::clock(invoke_context, instruction_context, 2)?; + let stake_history = get_sysvar_with_account_check::stake_history( + invoke_context, + instruction_context, + 3, + )?; + instruction_context.check_number_of_instruction_accounts(5)?; + drop(me); + move_lamports( + invoke_context, + transaction_context, + instruction_context, + 0, + lamports, + 1, + &clock, + &stake_history, + 4, + ) + } else { + Err(InstructionError::InvalidInstructionData) + } } } }); diff --git a/sdk/src/feature_set.rs b/sdk/src/feature_set.rs index ed3a7ff5162341..7d7574ef845ac4 100644 --- a/sdk/src/feature_set.rs +++ b/sdk/src/feature_set.rs @@ -817,6 +817,10 @@ pub mod migrate_config_program_to_core_bpf { solana_sdk::declare_id!("2Fr57nzzkLYXW695UdDxDeR5fhnZWSttZeZYemrnpGFV"); } +pub mod move_stake_and_move_lamports_ixs { + solana_sdk::declare_id!("7bTK6Jis8Xpfrs8ZoUfiMDPazTcdPcTWheZFJTA5Z6X4"); +} + lazy_static! { /// Map of feature identifiers to user-visible description pub static ref FEATURE_NAMES: HashMap = [ @@ -1016,6 +1020,7 @@ lazy_static! { (migrate_feature_gate_program_to_core_bpf::id(), "Migrate Feature Gate program to Core BPF (programify) #1003"), (vote_only_full_fec_sets::id(), "vote only full fec sets"), (migrate_config_program_to_core_bpf::id(), "Migrate Config program to Core BPF #1378"), + (move_stake_and_move_lamports_ixs::id(), "Enable MoveStake and MoveLamports stake program instructions #XXX HANA"), /*************** ADD NEW FEATURES HERE ***************/ ] .iter()