Close buffer accounts (bp #15887) (#15971)

* Add Close instrruction and tooling to upgradeable loader (#15887)

(cherry picked from commit 7f500d610c)

# Conflicts:
#	cli/src/program.rs
#	programs/bpf_loader/src/lib.rs

* resolve conflicts

* slice fill not supported on older rust

Co-authored-by: Jack May <jack@solana.com>
This commit is contained in:
mergify[bot]
2021-03-18 07:33:40 +00:00
committed by GitHub
parent 9c596cfd6c
commit e0119e7de7
9 changed files with 980 additions and 60 deletions

View File

@@ -227,6 +227,20 @@ pub fn set_upgrade_authority(
Instruction::new(id(), &UpgradeableLoaderInstruction::SetAuthority, metas)
}
/// Returns the instructions required to close an account
pub fn close(
close_address: &Pubkey,
recipient_address: &Pubkey,
authority_address: &Pubkey,
) -> Instruction {
let metas = vec![
AccountMeta::new(*close_address, false),
AccountMeta::new(*recipient_address, false),
AccountMeta::new_readonly(*authority_address, true),
];
Instruction::new_with_bincode(id(), &UpgradeableLoaderInstruction::Close, metas)
}
#[cfg(test)]
mod tests {
use super::*;

View File

@@ -107,4 +107,13 @@ pub enum UpgradeableLoaderInstruction {
/// 2. `[]` The new authority, optional, if omitted then the program will
/// not be upgradeable.
SetAuthority,
/// Closes an account owned by the upgradeable loader of all lamports and
/// withdraws all the lamports
///
/// # Account references
/// 0. `[writable]` The account to close.
/// 1. `[writable]` The account to deposit the closed account's lamports.
/// 2. `[signer]` The account's authority.
Close,
}

View File

@@ -175,6 +175,10 @@ pub mod cpi_data_cost {
solana_sdk::declare_id!("Hrg5bXePPGiAVWZfDHbvjqytSeyBDPAGAQ7v6N5i4gCX");
}
pub mod upgradeable_close_instruction {
solana_sdk::declare_id!("FsPaByos3gA9bUEhp3EimQpQPCoSvCEigHod496NmABQ");
}
lazy_static! {
/// Map of feature identifiers to user-visible description
pub static ref FEATURE_NAMES: HashMap<Pubkey, &'static str> = [
@@ -219,6 +223,7 @@ lazy_static! {
(check_init_vote_data::id(), "check initialized Vote data"),
(check_program_owner::id(), "limit programs to operating on accounts owned by itself"),
(cpi_data_cost::id(), "charge the compute budget for data passed via CPI"),
(upgradeable_close_instruction::id(), "close upgradeable buffer accounts"),
/*************** ADD NEW FEATURES HERE ***************/
]
.iter()