Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement VoteInstruction::AuthorizeWithSeed & VoteInstruction::AuthorizeWithSeedChecked #25928

Merged
merged 11 commits into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/src/cluster/stake-delegation-and-rewards.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ VoteState is the current state of all the votes the validator has submitted to t

Updates the account with a new authorized voter or withdrawer, according to the VoteAuthorize parameter \(`Voter` or `Withdrawer`\). The transaction must be signed by the Vote account's current `authorized_voter` or `authorized_withdrawer`.

- `account[0]` - RW - The VoteState.
`VoteState::authorized_voter` or `authorized_withdrawer` is set to `Pubkey`.

### VoteInstruction::AuthorizeWithSeed\(VoteAuthorizeWithSeedArgs\)

Updates the account with a new authorized voter or withdrawer, according to the VoteAuthorize parameter \(`Voter` or `Withdrawer`\). Unlike `VoteInstruction::Authorize` this instruction is for use when the Vote account's current `authorized_voter` or `authorized_withdrawer` is a derived key. The transaction must be signed by someone who can sign for the base key of that derived key.

- `account[0]` - RW - The VoteState.
`VoteState::authorized_voter` or `authorized_withdrawer` is set to `Pubkey`.

Expand Down
81 changes: 80 additions & 1 deletion programs/vote/src/vote_instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
use {
crate::{
id,
vote_state::{Vote, VoteAuthorize, VoteInit, VoteState, VoteStateUpdate},
vote_state::{
Vote, VoteAuthorize, VoteAuthorizeCheckedWithSeedArgs, VoteAuthorizeWithSeedArgs,
VoteInit, VoteState, VoteStateUpdate,
},
},
serde_derive::{Deserialize, Serialize},
solana_sdk::{
Expand Down Expand Up @@ -99,6 +102,30 @@ pub enum VoteInstruction {
/// 0. `[Write]` Vote account to vote with
/// 1. `[SIGNER]` Vote authority
UpdateVoteStateSwitch(VoteStateUpdate, Hash),

/// Given that the current Voter or Withdrawer authority is a derived key,
/// this instruction allows someone who can sign for that derived key's
/// base key to authorize a new Voter or Withdrawer for a vote account.
///
/// # Account references
/// 0. `[Write]` Vote account to be updated
/// 1. `[]` Clock sysvar
/// 2. `[SIGNER]` Base key of current Voter or Withdrawer authority's derived key
AuthorizeWithSeed(VoteAuthorizeWithSeedArgs),

/// Given that the current Voter or Withdrawer authority is a derived key,
/// this instruction allows someone who can sign for that derived key's
/// base key to authorize a new Voter or Withdrawer for a vote account.
///
/// This instruction behaves like `AuthorizeWithSeed` with the additional requirement
/// that the new vote or withdraw authority must also be a signer.
///
/// # Account references
/// 0. `[Write]` Vote account to be updated
/// 1. `[]` Clock sysvar
/// 2. `[SIGNER]` Base key of current Voter or Withdrawer authority's derived key
/// 3. `[SIGNER]` New vote or withdraw authority
AuthorizeCheckedWithSeed(VoteAuthorizeCheckedWithSeedArgs),
}

fn initialize_account(vote_pubkey: &Pubkey, vote_init: &VoteInit) -> Instruction {
Expand Down Expand Up @@ -190,6 +217,58 @@ pub fn authorize_checked(
)
}

pub fn authorize_with_seed(
vote_pubkey: &Pubkey,
current_authority_base_key: &Pubkey,
current_authority_derived_key_owner: &Pubkey,
current_authority_derived_key_seed: &str,
new_authority: &Pubkey,
authorization_type: VoteAuthorize,
) -> Instruction {
let account_metas = vec![
AccountMeta::new(*vote_pubkey, false),
AccountMeta::new_readonly(sysvar::clock::id(), false),
AccountMeta::new_readonly(*current_authority_base_key, true),
];

Instruction::new_with_bincode(
id(),
&VoteInstruction::AuthorizeWithSeed(VoteAuthorizeWithSeedArgs {
authorization_type,
current_authority_derived_key_owner: *current_authority_derived_key_owner,
current_authority_derived_key_seed: current_authority_derived_key_seed.to_string(),
new_authority: *new_authority,
}),
account_metas,
)
}

pub fn authorize_checked_with_seed(
vote_pubkey: &Pubkey,
current_authority_base_key: &Pubkey,
current_authority_derived_key_owner: &Pubkey,
current_authority_derived_key_seed: &str,
new_authority: &Pubkey,
authorization_type: VoteAuthorize,
) -> Instruction {
let account_metas = vec![
AccountMeta::new(*vote_pubkey, false),
AccountMeta::new_readonly(sysvar::clock::id(), false),
AccountMeta::new_readonly(*current_authority_base_key, true),
AccountMeta::new_readonly(*new_authority, true),
];

Instruction::new_with_bincode(
id(),
&VoteInstruction::AuthorizeCheckedWithSeed(VoteAuthorizeCheckedWithSeedArgs {
authorization_type,
current_authority_derived_key_owner: *current_authority_derived_key_owner,
current_authority_derived_key_seed: current_authority_derived_key_seed.to_string(),
}),
account_metas,
)
}

pub fn update_validator_identity(
vote_pubkey: &Pubkey,
authorized_withdrawer_pubkey: &Pubkey,
Expand Down
Loading