Skip to content

Commit

Permalink
review pass
Browse files Browse the repository at this point in the history
  • Loading branch information
norwnd committed Dec 13, 2023
1 parent d71d785 commit 621297f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 45 deletions.
28 changes: 10 additions & 18 deletions cli/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
];

Expand Down Expand Up @@ -1291,7 +1283,7 @@ fn process_program_upgrade(
rpc_client: Arc<RpcClient>,
config: &CliConfig,
fee_payer_signer_index: SignerIndex,
program_pubkey: Pubkey,
program_id: Pubkey,
buffer_pubkey: Pubkey,
upgrade_authority_signer_index: SignerIndex,
sign_only: bool,
Expand All @@ -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(),
Expand All @@ -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,
Expand All @@ -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))
}
Expand Down
16 changes: 2 additions & 14 deletions cli/tests/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
26 changes: 13 additions & 13 deletions docs/src/cli/examples/deploy-a-program.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <PROGRAM_FILEPATH>

# (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 <BUFFER_PUBKEY> --new-buffer-authority <OFFLINE_SIGNER_PUBKEY>
```

(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 <BUFFER_PUBKEY> <PROGRAM_ID> --sign-only --fee-payer <ONLINE_SIGNER_PUBKEY> --upgrade-authority <OFFLINE_SIGNER> --blockhash <VALUE>

# 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 <BUFFER_PUBKEY> <PROGRAM_ID> --fee-payer <ONLINE_SIGNER> --upgrade-authority <OFFLINE_SIGNER_PUBKEY> --blockhash <VALUE> --signer <OFFLINE_SIGNER_PUBKEY>:<OFFLINE_SIGNER_SIGNATURE>
```
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).

0 comments on commit 621297f

Please sign in to comment.