Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
Reduce payer balance needed to deploy programs
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarry committed Sep 4, 2021
1 parent 497b6c1 commit af0d25c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
24 changes: 17 additions & 7 deletions programs/bpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ use solana_sdk::{
clock::Clock,
entrypoint::{HEAP_LENGTH, SUCCESS},
feature_set::{
add_missing_program_error_mappings, close_upgradeable_program_accounts,
stop_verify_mul64_imm_nonzero,
add_missing_program_error_mappings, cheaper_upgradeable_program_deploys,
close_upgradeable_program_accounts, stop_verify_mul64_imm_nonzero,
},
ic_logger_msg, ic_msg,
instruction::InstructionError,
Expand Down Expand Up @@ -390,6 +390,14 @@ fn process_loader_upgradeable_instruction(
return Err(InstructionError::InvalidArgument);
}

if invoke_context.is_feature_active(&cheaper_upgradeable_program_deploys::id()) {
// Drain the Buffer account to payer before paying for programdata account
payer
.try_account_ref_mut()?
.checked_add_lamports(buffer.lamports()?)?;
buffer.try_account_ref_mut()?.set_lamports(0);
}

let instruction = system_instruction::create_account(
payer.unsigned_key(),
programdata.unsigned_key(),
Expand Down Expand Up @@ -434,11 +442,13 @@ fn process_loader_upgradeable_instruction(
})?;
program.try_account_ref_mut()?.set_executable(true);

// Drain the Buffer account back to the payer
payer
.try_account_ref_mut()?
.checked_add_lamports(buffer.lamports()?)?;
buffer.try_account_ref_mut()?.set_lamports(0);
if !invoke_context.is_feature_active(&cheaper_upgradeable_program_deploys::id()) {
// Drain the Buffer account back to the payer
payer
.try_account_ref_mut()?
.checked_add_lamports(buffer.lamports()?)?;
buffer.try_account_ref_mut()?.set_lamports(0);
}

ic_logger_msg!(logger, "Deployed program {:?}", new_program_id);
}
Expand Down
4 changes: 4 additions & 0 deletions sdk/src/feature_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ pub mod demote_program_write_locks {
solana_sdk::declare_id!("3E3jV7v9VcdJL8iYZUMax9DiDno8j7EWUVbhm9RtShj2");
}

pub mod cheaper_upgradeable_program_deploys {
solana_sdk::declare_id!("8wxKohKFPEFZto3o2HuLzqewmy45Bvgq5KPYrm5AtFwi");
}

lazy_static! {
/// Map of feature identifiers to user-visible description
pub static ref FEATURE_NAMES: HashMap<Pubkey, &'static str> = [
Expand Down

0 comments on commit af0d25c

Please sign in to comment.