Skip to content

Commit

Permalink
Refactor - Adds CLI parameter "--with-compute-unit-price" to program-…
Browse files Browse the repository at this point in the history
…v4 (#5086)

* Changes underscore to dash for consistency.

* Adds helper closure for constructing messages.

* Removes the closure parameter from calculate_max_chunk_size().

* Adds "--with-compute-unit-price".

* Sends both instructions of process_close_program() in a single transaction.

* Factors redundant code into a message_factory().
  • Loading branch information
Lichtso authored Feb 28, 2025
1 parent 844c1b3 commit 62f5b70
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 99 deletions.
1 change: 1 addition & 0 deletions cargo-registry/src/crate_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ impl Program {
None..None,
Some(signer),
false,
None,
)
.map_err(|e| {
error!("Failed to deploy the program: {}", e);
Expand Down
12 changes: 4 additions & 8 deletions cli/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2551,11 +2551,7 @@ fn process_migrate_program(
}))
}

pub fn calculate_max_chunk_size<F>(create_msg: &F) -> usize
where
F: Fn(u32, Vec<u8>) -> Message,
{
let baseline_msg = create_msg(0, Vec::new());
pub fn calculate_max_chunk_size(baseline_msg: Message) -> usize {
let tx_size = bincode::serialized_size(&Transaction {
signatures: vec![
Signature::default();
Expand Down Expand Up @@ -2637,7 +2633,7 @@ fn do_process_program_deploy(
};

let mut write_messages = vec![];
let chunk_size = calculate_max_chunk_size(&create_msg);
let chunk_size = calculate_max_chunk_size(create_msg(0, Vec::new()));
for (chunk, i) in program_data.chunks(chunk_size).zip(0usize..) {
let offset = i.saturating_mul(chunk_size);
if chunk != &buffer_program_data[offset..offset.saturating_add(chunk.len())] {
Expand Down Expand Up @@ -2770,7 +2766,7 @@ fn do_process_write_buffer(
};

let mut write_messages = vec![];
let chunk_size = calculate_max_chunk_size(&create_msg);
let chunk_size = calculate_max_chunk_size(create_msg(0, Vec::new()));
for (chunk, i) in program_data.chunks(chunk_size).zip(0usize..) {
let offset = i.saturating_mul(chunk_size);
if chunk != &buffer_program_data[offset..offset.saturating_add(chunk.len())] {
Expand Down Expand Up @@ -2895,7 +2891,7 @@ fn do_process_program_upgrade(

// Create and add write messages
let mut write_messages = vec![];
let chunk_size = calculate_max_chunk_size(&create_msg);
let chunk_size = calculate_max_chunk_size(create_msg(0, Vec::new()));
for (chunk, i) in program_data.chunks(chunk_size).zip(0usize..) {
let offset = i.saturating_mul(chunk_size);
if chunk != &buffer_program_data[offset..offset.saturating_add(chunk.len())] {
Expand Down
Loading

0 comments on commit 62f5b70

Please sign in to comment.