Feature-gate stake program (#13394)
* Add legacy stake-program handling * Strip out duplicative legacy code * Add feature for stake-program-fix * Feature-deploy new stake program * Expand comment
This commit is contained in:
parent
84b139cc94
commit
1b1d9f6b0c
|
@ -0,0 +1,88 @@
|
|||
use crate::{config, legacy_stake_state::StakeAccount, stake_instruction::StakeInstruction};
|
||||
use log::*;
|
||||
use solana_sdk::{
|
||||
instruction::InstructionError,
|
||||
keyed_account::{from_keyed_account, get_signers, next_keyed_account, KeyedAccount},
|
||||
process_instruction::InvokeContext,
|
||||
program_utils::limited_deserialize,
|
||||
pubkey::Pubkey,
|
||||
sysvar::{clock::Clock, rent::Rent, stake_history::StakeHistory},
|
||||
};
|
||||
|
||||
pub fn process_instruction(
|
||||
_program_id: &Pubkey,
|
||||
keyed_accounts: &[KeyedAccount],
|
||||
data: &[u8],
|
||||
_invoke_context: &mut dyn InvokeContext,
|
||||
) -> Result<(), InstructionError> {
|
||||
trace!("process_instruction: {:?}", data);
|
||||
trace!("keyed_accounts: {:?}", keyed_accounts);
|
||||
|
||||
let signers = get_signers(keyed_accounts);
|
||||
|
||||
let keyed_accounts = &mut keyed_accounts.iter();
|
||||
let me = &next_keyed_account(keyed_accounts)?;
|
||||
|
||||
match limited_deserialize(data)? {
|
||||
StakeInstruction::Initialize(authorized, lockup) => me.initialize(
|
||||
&authorized,
|
||||
&lockup,
|
||||
&from_keyed_account::<Rent>(next_keyed_account(keyed_accounts)?)?,
|
||||
),
|
||||
StakeInstruction::Authorize(authorized_pubkey, stake_authorize) => {
|
||||
me.authorize(&signers, &authorized_pubkey, stake_authorize)
|
||||
}
|
||||
StakeInstruction::AuthorizeWithSeed(args) => {
|
||||
let authority_base = next_keyed_account(keyed_accounts)?;
|
||||
me.authorize_with_seed(
|
||||
&authority_base,
|
||||
&args.authority_seed,
|
||||
&args.authority_owner,
|
||||
&args.new_authorized_pubkey,
|
||||
args.stake_authorize,
|
||||
)
|
||||
}
|
||||
StakeInstruction::DelegateStake => {
|
||||
let vote = next_keyed_account(keyed_accounts)?;
|
||||
|
||||
me.delegate(
|
||||
&vote,
|
||||
&from_keyed_account::<Clock>(next_keyed_account(keyed_accounts)?)?,
|
||||
&from_keyed_account::<StakeHistory>(next_keyed_account(keyed_accounts)?)?,
|
||||
&config::from_keyed_account(next_keyed_account(keyed_accounts)?)?,
|
||||
&signers,
|
||||
)
|
||||
}
|
||||
StakeInstruction::Split(lamports) => {
|
||||
let split_stake = &next_keyed_account(keyed_accounts)?;
|
||||
me.split(lamports, split_stake, &signers)
|
||||
}
|
||||
StakeInstruction::Merge => {
|
||||
let source_stake = &next_keyed_account(keyed_accounts)?;
|
||||
me.merge(
|
||||
source_stake,
|
||||
&from_keyed_account::<Clock>(next_keyed_account(keyed_accounts)?)?,
|
||||
&from_keyed_account::<StakeHistory>(next_keyed_account(keyed_accounts)?)?,
|
||||
&signers,
|
||||
)
|
||||
}
|
||||
|
||||
StakeInstruction::Withdraw(lamports) => {
|
||||
let to = &next_keyed_account(keyed_accounts)?;
|
||||
me.withdraw(
|
||||
lamports,
|
||||
to,
|
||||
&from_keyed_account::<Clock>(next_keyed_account(keyed_accounts)?)?,
|
||||
&from_keyed_account::<StakeHistory>(next_keyed_account(keyed_accounts)?)?,
|
||||
next_keyed_account(keyed_accounts)?,
|
||||
keyed_accounts.next(),
|
||||
)
|
||||
}
|
||||
StakeInstruction::Deactivate => me.deactivate(
|
||||
&from_keyed_account::<Clock>(next_keyed_account(keyed_accounts)?)?,
|
||||
&signers,
|
||||
),
|
||||
|
||||
StakeInstruction::SetLockup(lockup) => me.set_lockup(&lockup, &signers),
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -2,6 +2,8 @@
|
|||
use solana_sdk::genesis_config::GenesisConfig;
|
||||
|
||||
pub mod config;
|
||||
pub mod legacy_stake_processor;
|
||||
pub mod legacy_stake_state;
|
||||
pub mod stake_instruction;
|
||||
pub mod stake_state;
|
||||
|
||||
|
|
|
@ -17,10 +17,12 @@ fn genesis_builtins() -> Vec<Builtin> {
|
|||
solana_vote_program::id(),
|
||||
solana_vote_program::vote_instruction::process_instruction,
|
||||
),
|
||||
// Remove legacy_stake_processor and move stake_instruction::process_instruction back to
|
||||
// genesis_builtins around the v1.6 timeframe
|
||||
Builtin::new(
|
||||
"stake_program",
|
||||
solana_stake_program::id(),
|
||||
solana_stake_program::stake_instruction::process_instruction,
|
||||
solana_stake_program::legacy_stake_processor::process_instruction,
|
||||
),
|
||||
Builtin::new(
|
||||
"config_program",
|
||||
|
@ -37,16 +39,34 @@ pub enum ActivationType {
|
|||
}
|
||||
|
||||
/// Builtin programs activated dynamically by feature
|
||||
///
|
||||
/// Note: If the feature_builtin is intended to replace another builtin program, it must have a new
|
||||
/// name.
|
||||
/// This is to enable the runtime to determine categorically whether the builtin update has
|
||||
/// occurred, and preserve idempotency in Bank::add_native_program across genesis, snapshot, and
|
||||
/// normal child Bank creation.
|
||||
/// https://github.com/solana-labs/solana/blob/84b139cc94b5be7c9e0c18c2ad91743231b85a0d/runtime/src/bank.rs#L1723
|
||||
fn feature_builtins() -> Vec<(Builtin, Pubkey, ActivationType)> {
|
||||
vec![(
|
||||
Builtin::new(
|
||||
"secp256k1_program",
|
||||
solana_sdk::secp256k1_program::id(),
|
||||
solana_secp256k1_program::process_instruction,
|
||||
vec![
|
||||
(
|
||||
Builtin::new(
|
||||
"secp256k1_program",
|
||||
solana_sdk::secp256k1_program::id(),
|
||||
solana_secp256k1_program::process_instruction,
|
||||
),
|
||||
feature_set::secp256k1_program_enabled::id(),
|
||||
ActivationType::NewProgram,
|
||||
),
|
||||
feature_set::secp256k1_program_enabled::id(),
|
||||
ActivationType::NewProgram,
|
||||
)]
|
||||
(
|
||||
Builtin::new(
|
||||
"stake_program_v2",
|
||||
solana_stake_program::id(),
|
||||
solana_stake_program::stake_instruction::process_instruction,
|
||||
),
|
||||
feature_set::stake_program_v2::id(),
|
||||
ActivationType::NewVersion,
|
||||
),
|
||||
]
|
||||
}
|
||||
|
||||
pub(crate) fn get() -> Builtins {
|
||||
|
|
|
@ -82,6 +82,10 @@ pub mod timestamp_bounding {
|
|||
solana_sdk::declare_id!("8FyEA6ABYiMxX7Az6AopQN3mavLD8Rz3N4bvKnbbBFFq");
|
||||
}
|
||||
|
||||
pub mod stake_program_v2 {
|
||||
solana_sdk::declare_id!("Gvd9gGJZDHGMNf1b3jkxrfBQSR5etrfTQSBNKCvLSFJN");
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
/// Map of feature identifiers to user-visible description
|
||||
pub static ref FEATURE_NAMES: HashMap<Pubkey, &'static str> = [
|
||||
|
@ -104,6 +108,7 @@ lazy_static! {
|
|||
(pubkey_log_syscall_enabled::id(), "pubkey log syscall"),
|
||||
(pull_request_ping_pong_check::id(), "ping-pong packet check #12794"),
|
||||
(timestamp_bounding::id(), "add timestamp-correction bounding #13120"),
|
||||
(stake_program_v2::id(), "solana_stake_program v2"),
|
||||
/*************** ADD NEW FEATURES HERE ***************/
|
||||
]
|
||||
.iter()
|
||||
|
|
Loading…
Reference in New Issue