Skip to content

Commit 51d34fd

Browse files
committed
Adjusts CLI manual extend and auto extend.
1 parent 87adb5d commit 51d34fd

File tree

2 files changed

+57
-25
lines changed

2 files changed

+57
-25
lines changed

cli/src/program.rs

+55-23
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ pub enum ProgramCliCommand {
169169
use_lamports_unit: bool,
170170
bypass_warning: bool,
171171
},
172-
ExtendProgram {
172+
ExtendProgramChecked {
173173
program_pubkey: Pubkey,
174174
additional_bytes: u32,
175175
},
@@ -1018,7 +1018,7 @@ pub fn parse_program_subcommand(
10181018
)?;
10191019

10201020
CliCommandInfo {
1021-
command: CliCommand::Program(ProgramCliCommand::ExtendProgram {
1021+
command: CliCommand::Program(ProgramCliCommand::ExtendProgramChecked {
10221022
program_pubkey,
10231023
additional_bytes,
10241024
}),
@@ -1231,7 +1231,7 @@ pub fn process_program_subcommand(
12311231
*use_lamports_unit,
12321232
*bypass_warning,
12331233
),
1234-
ProgramCliCommand::ExtendProgram {
1234+
ProgramCliCommand::ExtendProgramChecked {
12351235
program_pubkey,
12361236
additional_bytes,
12371237
} => process_extend_program(&rpc_client, config, *program_pubkey, *additional_bytes),
@@ -2411,21 +2411,28 @@ fn process_extend_program(
24112411
_ => Err(format!("Program {program_pubkey} is closed")),
24122412
}?;
24132413

2414-
match upgrade_authority_address {
2415-
None => Err(format!("Program {program_pubkey} is not upgradeable")),
2416-
_ => Ok(()),
2417-
}?;
2414+
let upgrade_authority_address = upgrade_authority_address
2415+
.ok_or_else(|| format!("Program {program_pubkey} is not upgradeable"))?;
24182416

24192417
let blockhash = rpc_client.get_latest_blockhash()?;
2420-
2421-
let mut tx = Transaction::new_unsigned(Message::new(
2422-
&[loader_v3_instruction::extend_program(
2423-
&program_pubkey,
2424-
Some(&payer_pubkey),
2425-
additional_bytes,
2426-
)],
2427-
Some(&payer_pubkey),
2428-
));
2418+
let feature_set = fetch_feature_set(rpc_client)?;
2419+
2420+
let instruction =
2421+
if feature_set.is_active(&agave_feature_set::enable_extend_program_checked::id()) {
2422+
loader_v3_instruction::extend_program_checked(
2423+
&program_pubkey,
2424+
&upgrade_authority_address,
2425+
Some(&payer_pubkey),
2426+
additional_bytes,
2427+
)
2428+
} else {
2429+
loader_v3_instruction::extend_program(
2430+
&program_pubkey,
2431+
Some(&payer_pubkey),
2432+
additional_bytes,
2433+
)
2434+
};
2435+
let mut tx = Transaction::new_unsigned(Message::new(&[instruction], Some(&payer_pubkey)));
24292436

24302437
tx.try_sign(&[config.signers[0]], blockhash)?;
24312438
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config(
@@ -2972,6 +2979,17 @@ fn extend_program_data_if_needed(
29722979
return Ok(());
29732980
};
29742981

2982+
let upgrade_authority_address = match program_data_account.state() {
2983+
Ok(UpgradeableLoaderState::ProgramData {
2984+
slot: _,
2985+
upgrade_authority_address,
2986+
}) => Ok(upgrade_authority_address),
2987+
_ => Err(format!("Program {program_id} is closed")),
2988+
}?;
2989+
2990+
let upgrade_authority_address = upgrade_authority_address
2991+
.ok_or_else(|| format!("Program {program_id} is not upgradeable"))?;
2992+
29752993
let required_len = UpgradeableLoaderState::size_of_programdata(program_len);
29762994
let max_permitted_data_length = usize::try_from(MAX_PERMITTED_DATA_LENGTH).unwrap();
29772995
if required_len > max_permitted_data_length {
@@ -2993,11 +3011,20 @@ fn extend_program_data_if_needed(
29933011

29943012
let additional_bytes =
29953013
u32::try_from(additional_bytes).expect("`u32` is big enough to hold an account size");
2996-
initial_instructions.push(loader_v3_instruction::extend_program(
2997-
program_id,
2998-
Some(fee_payer),
2999-
additional_bytes,
3000-
));
3014+
3015+
let feature_set = fetch_feature_set(rpc_client)?;
3016+
let instruction =
3017+
if feature_set.is_active(&agave_feature_set::enable_extend_program_checked::id()) {
3018+
loader_v3_instruction::extend_program_checked(
3019+
program_id,
3020+
&upgrade_authority_address,
3021+
Some(fee_payer),
3022+
additional_bytes,
3023+
)
3024+
} else {
3025+
loader_v3_instruction::extend_program(program_id, Some(fee_payer), additional_bytes)
3026+
};
3027+
initial_instructions.push(instruction);
30013028

30023029
Ok(())
30033030
}
@@ -3096,7 +3123,12 @@ fn send_deploy_messages(
30963123
// account to sign the transaction. One (transfer) only requires the fee-payer signature.
30973124
// This check is to ensure signing does not fail on a KeypairPubkeyMismatch error from an
30983125
// extraneous signature.
3099-
if message.header.num_required_signatures == 2 {
3126+
if message.header.num_required_signatures == 3 {
3127+
initial_transaction.try_sign(
3128+
&[fee_payer_signer, initial_signer, write_signer.unwrap()],
3129+
blockhash,
3130+
)?;
3131+
} else if message.header.num_required_signatures == 2 {
31003132
initial_transaction.try_sign(&[fee_payer_signer, initial_signer], blockhash)?;
31013133
} else {
31023134
initial_transaction.try_sign(&[fee_payer_signer], blockhash)?;
@@ -4406,7 +4438,7 @@ mod tests {
44064438
assert_eq!(
44074439
parse_command(&test_command, &default_signer, &mut None).unwrap(),
44084440
CliCommandInfo {
4409-
command: CliCommand::Program(ProgramCliCommand::ExtendProgram {
4441+
command: CliCommand::Program(ProgramCliCommand::ExtendProgramChecked {
44104442
program_pubkey,
44114443
additional_bytes
44124444
}),

cli/tests/program.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1444,7 +1444,7 @@ fn test_cli_program_extend_program() {
14441444
let new_max_len = new_program_data.len();
14451445
let additional_bytes = (new_max_len - max_len) as u32;
14461446
config.signers = vec![&keypair];
1447-
config.command = CliCommand::Program(ProgramCliCommand::ExtendProgram {
1447+
config.command = CliCommand::Program(ProgramCliCommand::ExtendProgramChecked {
14481448
program_pubkey: program_keypair.pubkey(),
14491449
additional_bytes: additional_bytes - 1,
14501450
});
@@ -1492,7 +1492,7 @@ fn test_cli_program_extend_program() {
14921492

14931493
// Extend 1 last byte
14941494
config.signers = vec![&keypair];
1495-
config.command = CliCommand::Program(ProgramCliCommand::ExtendProgram {
1495+
config.command = CliCommand::Program(ProgramCliCommand::ExtendProgramChecked {
14961496
program_pubkey: program_keypair.pubkey(),
14971497
additional_bytes: 1,
14981498
});

0 commit comments

Comments
 (0)