Skip to content

Commit

Permalink
add feature gate
Browse files Browse the repository at this point in the history
  • Loading branch information
2501babe committed Jun 4, 2024
1 parent 83a0040 commit 42a8666
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 42 deletions.
98 changes: 56 additions & 42 deletions programs/stake/src/stake_instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
});
Expand Down
5 changes: 5 additions & 0 deletions sdk/src/feature_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Pubkey, &'static str> = [
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 42a8666

Please sign in to comment.