From 621297fba77f51494b89621486b75f558a39fe42 Mon Sep 17 00:00:00 2001 From: norwnd Date: Wed, 13 Dec 2023 15:32:01 +0000 Subject: [PATCH] review pass --- cli/src/program.rs | 28 ++++++++--------------- cli/tests/program.rs | 16 ++----------- docs/src/cli/examples/deploy-a-program.md | 26 ++++++++++----------- 3 files changed, 25 insertions(+), 45 deletions(-) diff --git a/cli/src/program.rs b/cli/src/program.rs index 06f5c2ad844705..04863c108cb9d5 100644 --- a/cli/src/program.rs +++ b/cli/src/program.rs @@ -618,25 +618,17 @@ pub fn parse_program_subcommand( let dump_transaction_message = matches.is_present(DUMP_TRANSACTION_MESSAGE.name); let blockhash_query = BlockhashQuery::new_from_matches(matches); - let Ok(Some(buffer_pubkey)) = pubkey_of_signer(matches, "buffer", wallet_manager) - else { - return Err(CliError::BadParameter( - "`BUFFER_PUBKEY` must be specified when doing program upgrade".into(), - )); - }; - - let Ok(Some(program_pubkey)) = pubkey_of_signer(matches, "program_id", wallet_manager) - else { - return Err(CliError::BadParameter( - "`PROGRAM_ID` must be specified when doing program upgrade".into(), - )); - }; + let buffer_pubkey = pubkey_of_signer(matches, "buffer", wallet_manager) + .unwrap() + .unwrap(); + let program_pubkey = pubkey_of_signer(matches, "program_id", wallet_manager) + .unwrap() + .unwrap(); let (fee_payer, fee_payer_pubkey) = signer_of(matches, FEE_PAYER_ARG.name, wallet_manager)?; let mut bulk_signers = vec![ - Some(default_signer.signer_from_path(matches, wallet_manager)?), fee_payer, // if None, default signer will be supplied ]; @@ -1291,7 +1283,7 @@ fn process_program_upgrade( rpc_client: Arc, config: &CliConfig, fee_payer_signer_index: SignerIndex, - program_pubkey: Pubkey, + program_id: Pubkey, buffer_pubkey: Pubkey, upgrade_authority_signer_index: SignerIndex, sign_only: bool, @@ -1304,7 +1296,7 @@ fn process_program_upgrade( let blockhash = blockhash_query.get_blockhash(&rpc_client, config.commitment)?; let message = Message::new_with_blockhash( &[bpf_loader_upgradeable::upgrade( - &program_pubkey, + &program_id, &buffer_pubkey, &upgrade_authority_signer.pubkey(), &fee_payer_signer.pubkey(), @@ -1317,7 +1309,7 @@ fn process_program_upgrade( let mut tx = Transaction::new_unsigned(message); let signers = &[fee_payer_signer, upgrade_authority_signer]; // Using try_partial_sign here because fee_payer_signer might not be the fee payer we - // end up using for this transaction (it might be NullSigner in `--sing-only` mode). + // end up using for this transaction (it might be NullSigner in `--sign-only` mode). tx.try_partial_sign(signers, blockhash)?; return_signers_with_config( &tx, @@ -1342,7 +1334,7 @@ fn process_program_upgrade( .send_and_confirm_transaction_with_spinner(&tx) .map_err(|e| format!("Upgrading program failed: {e}"))?; let program_id = CliProgramId { - program_id: program_pubkey.to_string(), + program_id: program_id.to_string(), }; Ok(config.output_format.formatted_string(&program_id)) } diff --git a/cli/tests/program.rs b/cli/tests/program.rs index 2e50bd6a7d3bf9..153cb0c11e07d3 100644 --- a/cli/tests/program.rs +++ b/cli/tests/program.rs @@ -1909,26 +1909,14 @@ fn create_buffer_with_offline_authority<'a>( } // Set buffer authority to offline signer - config.signers = vec![online_signer, buffer_signer]; + config.signers = vec![online_signer]; config.command = CliCommand::Program(ProgramCliCommand::SetBufferAuthority { buffer_pubkey: buffer_signer.pubkey(), buffer_authority_index: Some(0), new_buffer_authority: offline_signer.pubkey(), }); config.output_format = OutputFormat::JsonCompact; - let response = process_command(config); - let json: Value = serde_json::from_str(&response.unwrap()).unwrap(); - let offline_signer_authority_str = json - .as_object() - .unwrap() - .get("authority") - .unwrap() - .as_str() - .unwrap(); - assert_eq!( - Pubkey::from_str(offline_signer_authority_str).unwrap(), - offline_signer.pubkey() - ); + process_command(config).unwrap(); let buffer_account = rpc_client.get_account(&buffer_signer.pubkey()).unwrap(); if let UpgradeableLoaderState::Buffer { authority_address } = buffer_account.state().unwrap() { assert_eq!(authority_address, Some(offline_signer.pubkey())); diff --git a/docs/src/cli/examples/deploy-a-program.md b/docs/src/cli/examples/deploy-a-program.md index 50c1149903f540..34955dbd0550d3 100644 --- a/docs/src/cli/examples/deploy-a-program.md +++ b/docs/src/cli/examples/deploy-a-program.md @@ -336,35 +336,35 @@ a typical setup would consist of 2 different signers: The general process is as follows: 1. (online) create buffer and write new program to it -2. (online) upgrade buffer authority to offline signer -3. (optional, online) verify the actual buffer on-chain contents +2. (online) set buffer authority to offline signer +3. (optional, online) verify the buffer's on-chain contents 4. (offline) sign a transaction to upgrade the program -5. (online) use this signature to broadcast upgrade transaction +5. (online) use this signature to broadcast the upgrade transaction ```bash # (1) (use online machine) create buffer solana program write-buffer -# (2) (use online machine) upgrade buffer authority to offline signer +# (2) (use online machine) set buffer authority to offline signer solana program set-buffer-authority --new-buffer-authority ``` -(3) (optional) You may verify that the uploaded program matches the built binary. See +(3) (optional) You may verify that the uploaded program matches the built binary. See [dumping a program to a file](deploy-a-program.md#dumping-a-program-to-a-file) for more information and details. ```bash -# or (4) (use offline machine) get a signature for your intent to upgrade program +# (4) (use offline machine) get a signature for your intent to upgrade program solana program upgrade --sign-only --fee-payer --upgrade-authority --blockhash -# or (5) (use online machine) use this signature to build and broadcast upgrade transactions on-chain +# (5) (use online machine) use this signature to build and broadcast the upgrade transaction on-chain solana program upgrade --fee-payer --upgrade-authority --blockhash --signer : ``` Note: -- typically, the output of the previous command(s) will contain some values useful in subsequent commands, e.g. +- typically, the output of the previous command(s) will contain some values useful in subsequent commands, e.g. `--program-id`, `--buffer`, `--signer` -- you need to specify matching (or corresponding) values for params with same names (`--fee-payer`, `--program-id`, +- you need to specify matching (or corresponding) values for params with same names (`--fee-payer`, `--program-id`, `--upgrade-authority`, `--buffer`, `--blockhash`) in offline/online modes -- you should pre-fill every value except for `blockhash` ahead of time, and once you are ready to act - you'll need to - look up fresh `blockhash` and paste it in quickly + do your signing, you have ~60 seconds before `blockhash` expires. - If you didn't make it in time - just get another fresh hash and repeat until you succeed, or consider using - [durable transaction nonces](../offline-signing/durable-nonce.md). +- you should pre-fill every value except for `blockhash` ahead of time, and once you are ready to act - you'll need to + look up a recent `blockhash` and paste it in to generate the offline transaction signature. The `blockhash` expires + after ~60 seconds. If you didn't make it in time - just get another fresh hash and repeat until you succeed, or + consider using [durable transaction nonces](../offline-signing/durable-nonce.md).