* Allow closing upgradeable program accounts (#19319)
(cherry picked from commit a89f180145
)
# Conflicts:
# programs/bpf_loader/src/lib.rs
# programs/bpf_loader/src/syscalls.rs
# sdk/src/feature_set.rs
* resolve conflicts
Co-authored-by: Jack May <jack@solana.com>
Co-authored-by: Justin Starry <justin@solana.com>
This commit is contained in:
@@ -527,6 +527,8 @@ fn build_bpf_package(config: &Config, target_directory: &Path, package: &cargo_m
|
||||
println!();
|
||||
println!("To deploy this program:");
|
||||
println!(" $ solana program deploy {}", program_so.display());
|
||||
println!("The program address will default to this keypair (override with --program-id):");
|
||||
println!(" {}", program_keypair.display());
|
||||
} else if config.dump {
|
||||
println!("Note: --dump is only available for crates with a cdylib target");
|
||||
}
|
||||
|
@@ -196,6 +196,10 @@ pub fn is_set_authority_instruction(instruction_data: &[u8]) -> bool {
|
||||
!instruction_data.is_empty() && 4 == instruction_data[0]
|
||||
}
|
||||
|
||||
pub fn is_close_instruction(instruction_data: &[u8]) -> bool {
|
||||
!instruction_data.is_empty() && 5 == instruction_data[0]
|
||||
}
|
||||
|
||||
/// Returns the instructions required to set a buffers's authority.
|
||||
pub fn set_buffer_authority(
|
||||
buffer_address: &Pubkey,
|
||||
@@ -231,17 +235,37 @@ pub fn set_upgrade_authority(
|
||||
Instruction::new_with_bincode(id(), &UpgradeableLoaderInstruction::SetAuthority, metas)
|
||||
}
|
||||
|
||||
/// Returns the instructions required to close an account
|
||||
/// Returns the instructions required to close a buffer account
|
||||
pub fn close(
|
||||
close_address: &Pubkey,
|
||||
recipient_address: &Pubkey,
|
||||
authority_address: &Pubkey,
|
||||
) -> Instruction {
|
||||
let metas = vec![
|
||||
close_any(
|
||||
close_address,
|
||||
recipient_address,
|
||||
Some(authority_address),
|
||||
None,
|
||||
)
|
||||
}
|
||||
|
||||
/// Returns the instructions required to close program, buffer, or uninitialized account
|
||||
pub fn close_any(
|
||||
close_address: &Pubkey,
|
||||
recipient_address: &Pubkey,
|
||||
authority_address: Option<&Pubkey>,
|
||||
program_address: Option<&Pubkey>,
|
||||
) -> Instruction {
|
||||
let mut metas = vec![
|
||||
AccountMeta::new(*close_address, false),
|
||||
AccountMeta::new(*recipient_address, false),
|
||||
AccountMeta::new_readonly(*authority_address, true),
|
||||
];
|
||||
if let Some(authority_address) = authority_address {
|
||||
metas.push(AccountMeta::new(*authority_address, true));
|
||||
}
|
||||
if let Some(program_address) = program_address {
|
||||
metas.push(AccountMeta::new(*program_address, false));
|
||||
}
|
||||
Instruction::new_with_bincode(id(), &UpgradeableLoaderInstruction::Close, metas)
|
||||
}
|
||||
|
||||
|
@@ -112,8 +112,12 @@ pub enum UpgradeableLoaderInstruction {
|
||||
/// withdraws all the lamports
|
||||
///
|
||||
/// # Account references
|
||||
/// 0. `[writable]` The account to close.
|
||||
/// 0. `[writable]` The account to close, if closing a program must be the
|
||||
/// ProgramData account.
|
||||
/// 1. `[writable]` The account to deposit the closed account's lamports.
|
||||
/// 2. `[signer]` The account's authority.
|
||||
/// 2. `[signer]` The account's authority, Optional, required for
|
||||
/// initialized accounts.
|
||||
/// 3. `[writable]` The associated Program account if the account to close
|
||||
/// is a ProgramData account.
|
||||
Close,
|
||||
}
|
||||
|
@@ -179,6 +179,10 @@ pub mod mem_overlap_fix {
|
||||
solana_sdk::declare_id!("vXDCFK7gphrEmyf5VnKgLmqbdJ4UxD2eZH1qbdouYKF");
|
||||
}
|
||||
|
||||
pub mod close_upgradeable_program_accounts {
|
||||
solana_sdk::declare_id!("EQMtCuSAkMVF9ZdhGuABtgvyXJLtSRF5AQKv1RNsrhj7");
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
/// Map of feature identifiers to user-visible description
|
||||
pub static ref FEATURE_NAMES: HashMap<Pubkey, &'static str> = [
|
||||
@@ -224,6 +228,7 @@ lazy_static! {
|
||||
(stake_merge_with_unmatched_credits_observed::id(), "allow merging active stakes with unmatched credits_observed #18985"),
|
||||
(gate_large_block::id(), "validator checks block cost against max limit in realtime, reject if exceeds."),
|
||||
(mem_overlap_fix::id(), "Memory overlap fix"),
|
||||
(close_upgradeable_program_accounts::id(), "enable closing upgradeable program accounts"),
|
||||
/*************** ADD NEW FEATURES HERE ***************/
|
||||
]
|
||||
.iter()
|
||||
|
Reference in New Issue
Block a user