Skip to content

Commit

Permalink
cli: skip no-op program deploy write txs
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarry committed Mar 16, 2024
1 parent e682fec commit 12e5f66
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions cli/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2213,11 +2213,12 @@ fn do_process_program_write_and_deploy(
let blockhash = rpc_client.get_latest_blockhash()?;

// Initialize buffer account or complete if already partially initialized
let (initial_instructions, balance_needed) = if let Some(account) = rpc_client
.get_account_with_commitment(buffer_pubkey, config.commitment)?
.value
let (initial_instructions, balance_needed, buffer_program_data) = if let Some(mut account) =
rpc_client
.get_account_with_commitment(buffer_pubkey, config.commitment)?
.value
{
complete_partial_program_init(
let (ixs, balance_needed) = complete_partial_program_init(
loader_id,
&fee_payer_signer.pubkey(),
buffer_pubkey,
Expand All @@ -2229,7 +2230,11 @@ fn do_process_program_write_and_deploy(
},
min_rent_exempt_program_data_balance,
allow_excessive_balance,
)?
)?;
let buffer_program_data = account
.data
.split_off(UpgradeableLoaderState::size_of_buffer_metadata());
(ixs, balance_needed, buffer_program_data)
} else if loader_id == &bpf_loader_upgradeable::id() {
(
bpf_loader_upgradeable::create_buffer(
Expand All @@ -2240,6 +2245,7 @@ fn do_process_program_write_and_deploy(
program_len,
)?,
min_rent_exempt_program_data_balance,
vec![0; program_len],
)
} else {
(
Expand All @@ -2251,6 +2257,7 @@ fn do_process_program_write_and_deploy(
loader_id,
)],
min_rent_exempt_program_data_balance,
vec![0; program_len],
)
};
let initial_message = if !initial_instructions.is_empty() {
Expand Down Expand Up @@ -2281,7 +2288,10 @@ fn do_process_program_write_and_deploy(
let mut write_messages = vec![];
let chunk_size = calculate_max_chunk_size(&create_msg);
for (chunk, i) in program_data.chunks(chunk_size).zip(0..) {
write_messages.push(create_msg((i * chunk_size) as u32, chunk.to_vec()));
let offset = i * chunk_size;
if chunk != &buffer_program_data[offset..offset + chunk.len()] {
write_messages.push(create_msg(offset as u32, chunk.to_vec()));
}
}

// Create and add final message
Expand Down

0 comments on commit 12e5f66

Please sign in to comment.