Skip to content

Commit

Permalink
loader-v3: Add UpgradeableLoaderInstruction::Migrate (#9)
Browse files Browse the repository at this point in the history
* loader-v3: Add `UpgradeableLoaderInstruction::Migrate`

#### Problem

The SDK changes from anza-xyz/agave#4661 need to
be applied here.

See [SIMD-0167](solana-foundation/solana-improvement-documents#167).

#### Summary of Changes

Feature Gate Issue: anza-xyz/feature-gate-tracker#78

* Avoid change in solana-program

---------

Co-authored-by: Alexander Meißner <[email protected]>
  • Loading branch information
joncinque and Lichtso authored Feb 10, 2025
1 parent 558a507 commit c776990
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion loader-v3-interface/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use {
crate::{get_program_data_address, state::UpgradeableLoaderState},
solana_instruction::{error::InstructionError, AccountMeta, Instruction},
solana_pubkey::Pubkey,
solana_sdk_ids::{bpf_loader_upgradeable::id, sysvar},
solana_sdk_ids::{bpf_loader_upgradeable::id, loader_v4, sysvar},
solana_system_interface::instruction as system_instruction,
};

Expand Down Expand Up @@ -171,6 +171,14 @@ pub enum UpgradeableLoaderInstruction {
/// 1. `[signer]` The current authority.
/// 2. `[signer]` The new authority.
SetAuthorityChecked,

/// Migrate the program to loader-v4.
///
/// # Account references
/// 0. `[writable]` The ProgramData account.
/// 1. `[writable]` The Program account.
/// 2. `[signer]` The current authority.
Migrate,
}

#[cfg(feature = "bincode")]
Expand Down Expand Up @@ -299,6 +307,10 @@ pub fn is_set_authority_checked_instruction(instruction_data: &[u8]) -> bool {
!instruction_data.is_empty() && 7 == instruction_data[0]
}

pub fn is_migrate_instruction(instruction_data: &[u8]) -> bool {
!instruction_data.is_empty() && 8 == instruction_data[0]
}

#[cfg(feature = "bincode")]
/// Returns the instructions required to set a buffers's authority.
pub fn set_buffer_authority(
Expand Down Expand Up @@ -440,6 +452,23 @@ pub fn extend_program(
)
}

/// Returns the instructions required to migrate a program to loader-v4.
#[cfg(feature = "bincode")]
pub fn migrate_program(
programdata_address: &Pubkey,
program_address: &Pubkey,
authority: &Pubkey,
) -> Instruction {
let accounts = vec![
AccountMeta::new(*programdata_address, false),
AccountMeta::new(*program_address, false),
AccountMeta::new_readonly(*authority, true),
AccountMeta::new_readonly(loader_v4::id(), false),
];

Instruction::new_with_bincode(id(), &UpgradeableLoaderInstruction::Migrate, accounts)
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -533,4 +562,13 @@ mod tests {
UpgradeableLoaderInstruction::Upgrade {},
);
}

#[test]
fn test_is_migrate_instruction() {
assert!(!is_migrate_instruction(&[]));
assert_is_instruction(
is_migrate_instruction,
UpgradeableLoaderInstruction::Migrate {},
);
}
}

0 comments on commit c776990

Please sign in to comment.