CLI: Fix vote blind indexing (bp #11045) (#11050)

* CLI: Fix explicitly plumb withdraw_authority through vote-update-commission

(cherry picked from commit 3392ecc310)

* CLI: Fix explicitly plumb withdraw_authority through vote-update-validator

(cherry picked from commit 2284699889)

* CLI: Fix explicitly plumb vote_account through create-vote-account

(cherry picked from commit 14ac233d01)

Co-authored-by: Trent Nelson <trent@solana.com>
This commit is contained in:
mergify[bot]
2020-07-14 15:35:46 +00:00
committed by GitHub
parent f44f94fe23
commit 121418dad2
4 changed files with 42 additions and 7 deletions

View File

@ -382,6 +382,7 @@ pub enum CliCommand {
}, },
// Vote Commands // Vote Commands
CreateVoteAccount { CreateVoteAccount {
vote_account: SignerIndex,
seed: Option<String>, seed: Option<String>,
identity_account: SignerIndex, identity_account: SignerIndex,
authorized_voter: Option<Pubkey>, authorized_voter: Option<Pubkey>,
@ -407,10 +408,12 @@ pub enum CliCommand {
VoteUpdateValidator { VoteUpdateValidator {
vote_account_pubkey: Pubkey, vote_account_pubkey: Pubkey,
new_identity_account: SignerIndex, new_identity_account: SignerIndex,
withdraw_authority: SignerIndex,
}, },
VoteUpdateCommission { VoteUpdateCommission {
vote_account_pubkey: Pubkey, vote_account_pubkey: Pubkey,
commission: u8, commission: u8,
withdraw_authority: SignerIndex,
}, },
// Wallet Commands // Wallet Commands
Address, Address,
@ -2128,6 +2131,7 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
// Create vote account // Create vote account
CliCommand::CreateVoteAccount { CliCommand::CreateVoteAccount {
vote_account,
seed, seed,
identity_account, identity_account,
authorized_voter, authorized_voter,
@ -2136,6 +2140,7 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
} => process_create_vote_account( } => process_create_vote_account(
&rpc_client, &rpc_client,
config, config,
*vote_account,
seed, seed,
*identity_account, *identity_account,
authorized_voter, authorized_voter,
@ -2180,16 +2185,25 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
CliCommand::VoteUpdateValidator { CliCommand::VoteUpdateValidator {
vote_account_pubkey, vote_account_pubkey,
new_identity_account, new_identity_account,
withdraw_authority,
} => process_vote_update_validator( } => process_vote_update_validator(
&rpc_client, &rpc_client,
config, config,
&vote_account_pubkey, &vote_account_pubkey,
*new_identity_account, *new_identity_account,
*withdraw_authority,
), ),
CliCommand::VoteUpdateCommission { CliCommand::VoteUpdateCommission {
vote_account_pubkey, vote_account_pubkey,
commission, commission,
} => process_vote_update_commission(&rpc_client, config, &vote_account_pubkey, *commission), withdraw_authority,
} => process_vote_update_commission(
&rpc_client,
config,
&vote_account_pubkey,
*commission,
*withdraw_authority,
),
// Wallet Commands // Wallet Commands
@ -3417,6 +3431,7 @@ mod tests {
let bob_pubkey = bob_keypair.pubkey(); let bob_pubkey = bob_keypair.pubkey();
let identity_keypair = Keypair::new(); let identity_keypair = Keypair::new();
config.command = CliCommand::CreateVoteAccount { config.command = CliCommand::CreateVoteAccount {
vote_account: 1,
seed: None, seed: None,
identity_account: 2, identity_account: 2,
authorized_voter: Some(bob_pubkey), authorized_voter: Some(bob_pubkey),
@ -3442,6 +3457,7 @@ mod tests {
config.command = CliCommand::VoteUpdateValidator { config.command = CliCommand::VoteUpdateValidator {
vote_account_pubkey: bob_pubkey, vote_account_pubkey: bob_pubkey,
new_identity_account: 2, new_identity_account: 2,
withdraw_authority: 1,
}; };
let result = process_command(&config); let result = process_command(&config);
assert!(result.is_ok()); assert!(result.is_ok());
@ -3659,6 +3675,7 @@ mod tests {
let bob_keypair = Keypair::new(); let bob_keypair = Keypair::new();
let identity_keypair = Keypair::new(); let identity_keypair = Keypair::new();
config.command = CliCommand::CreateVoteAccount { config.command = CliCommand::CreateVoteAccount {
vote_account: 1,
seed: None, seed: None,
identity_account: 2, identity_account: 2,
authorized_voter: Some(bob_pubkey), authorized_voter: Some(bob_pubkey),
@ -3678,6 +3695,7 @@ mod tests {
config.command = CliCommand::VoteUpdateValidator { config.command = CliCommand::VoteUpdateValidator {
vote_account_pubkey: bob_pubkey, vote_account_pubkey: bob_pubkey,
new_identity_account: 1, new_identity_account: 1,
withdraw_authority: 1,
}; };
assert!(process_command(&config).is_err()); assert!(process_command(&config).is_err());

View File

@ -253,7 +253,7 @@ pub fn parse_create_vote_account(
default_signer_path: &str, default_signer_path: &str,
wallet_manager: &mut Option<Arc<RemoteWalletManager>>, wallet_manager: &mut Option<Arc<RemoteWalletManager>>,
) -> Result<CliCommandInfo, CliError> { ) -> Result<CliCommandInfo, CliError> {
let (vote_account, _) = signer_of(matches, "vote_account", wallet_manager)?; let (vote_account, vote_account_pubkey) = signer_of(matches, "vote_account", wallet_manager)?;
let seed = matches.value_of("seed").map(|s| s.to_string()); let seed = matches.value_of("seed").map(|s| s.to_string());
let (identity_account, identity_pubkey) = let (identity_account, identity_pubkey) =
signer_of(matches, "identity_account", wallet_manager)?; signer_of(matches, "identity_account", wallet_manager)?;
@ -271,6 +271,7 @@ pub fn parse_create_vote_account(
Ok(CliCommandInfo { Ok(CliCommandInfo {
command: CliCommand::CreateVoteAccount { command: CliCommand::CreateVoteAccount {
vote_account: signer_info.index_of(vote_account_pubkey).unwrap(),
seed, seed,
identity_account: signer_info.index_of(identity_pubkey).unwrap(), identity_account: signer_info.index_of(identity_pubkey).unwrap(),
authorized_voter, authorized_voter,
@ -320,7 +321,8 @@ pub fn parse_vote_update_validator(
pubkey_of_signer(matches, "vote_account_pubkey", wallet_manager)?.unwrap(); pubkey_of_signer(matches, "vote_account_pubkey", wallet_manager)?.unwrap();
let (new_identity_account, new_identity_pubkey) = let (new_identity_account, new_identity_pubkey) =
signer_of(matches, "new_identity_account", wallet_manager)?; signer_of(matches, "new_identity_account", wallet_manager)?;
let (authorized_withdrawer, _) = signer_of(matches, "authorized_withdrawer", wallet_manager)?; let (authorized_withdrawer, authorized_withdrawer_pubkey) =
signer_of(matches, "authorized_withdrawer", wallet_manager)?;
let payer_provided = None; let payer_provided = None;
let signer_info = generate_unique_signers( let signer_info = generate_unique_signers(
@ -334,6 +336,7 @@ pub fn parse_vote_update_validator(
command: CliCommand::VoteUpdateValidator { command: CliCommand::VoteUpdateValidator {
vote_account_pubkey, vote_account_pubkey,
new_identity_account: signer_info.index_of(new_identity_pubkey).unwrap(), new_identity_account: signer_info.index_of(new_identity_pubkey).unwrap(),
withdraw_authority: signer_info.index_of(authorized_withdrawer_pubkey).unwrap(),
}, },
signers: signer_info.signers, signers: signer_info.signers,
}) })
@ -346,7 +349,8 @@ pub fn parse_vote_update_commission(
) -> Result<CliCommandInfo, CliError> { ) -> Result<CliCommandInfo, CliError> {
let vote_account_pubkey = let vote_account_pubkey =
pubkey_of_signer(matches, "vote_account_pubkey", wallet_manager)?.unwrap(); pubkey_of_signer(matches, "vote_account_pubkey", wallet_manager)?.unwrap();
let (authorized_withdrawer, _) = signer_of(matches, "authorized_withdrawer", wallet_manager)?; let (authorized_withdrawer, authorized_withdrawer_pubkey) =
signer_of(matches, "authorized_withdrawer", wallet_manager)?;
let commission = value_t_or_exit!(matches, "commission", u8); let commission = value_t_or_exit!(matches, "commission", u8);
let payer_provided = None; let payer_provided = None;
@ -361,6 +365,7 @@ pub fn parse_vote_update_commission(
command: CliCommand::VoteUpdateCommission { command: CliCommand::VoteUpdateCommission {
vote_account_pubkey, vote_account_pubkey,
commission, commission,
withdraw_authority: signer_info.index_of(authorized_withdrawer_pubkey).unwrap(),
}, },
signers: signer_info.signers, signers: signer_info.signers,
}) })
@ -420,13 +425,14 @@ pub fn parse_withdraw_from_vote_account(
pub fn process_create_vote_account( pub fn process_create_vote_account(
rpc_client: &RpcClient, rpc_client: &RpcClient,
config: &CliConfig, config: &CliConfig,
vote_account: SignerIndex,
seed: &Option<String>, seed: &Option<String>,
identity_account: SignerIndex, identity_account: SignerIndex,
authorized_voter: &Option<Pubkey>, authorized_voter: &Option<Pubkey>,
authorized_withdrawer: &Option<Pubkey>, authorized_withdrawer: &Option<Pubkey>,
commission: u8, commission: u8,
) -> ProcessResult { ) -> ProcessResult {
let vote_account = config.signers[1]; let vote_account = config.signers[vote_account];
let vote_account_pubkey = vote_account.pubkey(); let vote_account_pubkey = vote_account.pubkey();
let vote_account_address = if let Some(seed) = seed { let vote_account_address = if let Some(seed) = seed {
Pubkey::create_with_seed(&vote_account_pubkey, &seed, &solana_vote_program::id())? Pubkey::create_with_seed(&vote_account_pubkey, &seed, &solana_vote_program::id())?
@ -551,8 +557,9 @@ pub fn process_vote_update_validator(
config: &CliConfig, config: &CliConfig,
vote_account_pubkey: &Pubkey, vote_account_pubkey: &Pubkey,
new_identity_account: SignerIndex, new_identity_account: SignerIndex,
withdraw_authority: SignerIndex,
) -> ProcessResult { ) -> ProcessResult {
let authorized_withdrawer = config.signers[1]; let authorized_withdrawer = config.signers[withdraw_authority];
let new_identity_account = config.signers[new_identity_account]; let new_identity_account = config.signers[new_identity_account];
let new_identity_pubkey = new_identity_account.pubkey(); let new_identity_pubkey = new_identity_account.pubkey();
check_unique_pubkeys( check_unique_pubkeys(
@ -584,8 +591,9 @@ pub fn process_vote_update_commission(
config: &CliConfig, config: &CliConfig,
vote_account_pubkey: &Pubkey, vote_account_pubkey: &Pubkey,
commission: u8, commission: u8,
withdraw_authority: SignerIndex,
) -> ProcessResult { ) -> ProcessResult {
let authorized_withdrawer = config.signers[1]; let authorized_withdrawer = config.signers[withdraw_authority];
let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?; let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
let ixs = vec![vote_instruction::update_commission( let ixs = vec![vote_instruction::update_commission(
vote_account_pubkey, vote_account_pubkey,
@ -817,6 +825,7 @@ mod tests {
parse_command(&test_create_vote_account, &default_keypair_file, &mut None).unwrap(), parse_command(&test_create_vote_account, &default_keypair_file, &mut None).unwrap(),
CliCommandInfo { CliCommandInfo {
command: CliCommand::CreateVoteAccount { command: CliCommand::CreateVoteAccount {
vote_account: 1,
seed: None, seed: None,
identity_account: 2, identity_account: 2,
authorized_voter: None, authorized_voter: None,
@ -845,6 +854,7 @@ mod tests {
parse_command(&test_create_vote_account2, &default_keypair_file, &mut None).unwrap(), parse_command(&test_create_vote_account2, &default_keypair_file, &mut None).unwrap(),
CliCommandInfo { CliCommandInfo {
command: CliCommand::CreateVoteAccount { command: CliCommand::CreateVoteAccount {
vote_account: 1,
seed: None, seed: None,
identity_account: 2, identity_account: 2,
authorized_voter: None, authorized_voter: None,
@ -877,6 +887,7 @@ mod tests {
parse_command(&test_create_vote_account3, &default_keypair_file, &mut None).unwrap(), parse_command(&test_create_vote_account3, &default_keypair_file, &mut None).unwrap(),
CliCommandInfo { CliCommandInfo {
command: CliCommand::CreateVoteAccount { command: CliCommand::CreateVoteAccount {
vote_account: 1,
seed: None, seed: None,
identity_account: 2, identity_account: 2,
authorized_voter: Some(authed), authorized_voter: Some(authed),
@ -907,6 +918,7 @@ mod tests {
parse_command(&test_create_vote_account4, &default_keypair_file, &mut None).unwrap(), parse_command(&test_create_vote_account4, &default_keypair_file, &mut None).unwrap(),
CliCommandInfo { CliCommandInfo {
command: CliCommand::CreateVoteAccount { command: CliCommand::CreateVoteAccount {
vote_account: 1,
seed: None, seed: None,
identity_account: 2, identity_account: 2,
authorized_voter: None, authorized_voter: None,
@ -934,6 +946,7 @@ mod tests {
command: CliCommand::VoteUpdateValidator { command: CliCommand::VoteUpdateValidator {
vote_account_pubkey: pubkey, vote_account_pubkey: pubkey,
new_identity_account: 2, new_identity_account: 2,
withdraw_authority: 1,
}, },
signers: vec![ signers: vec![
read_keypair_file(&default_keypair_file).unwrap().into(), read_keypair_file(&default_keypair_file).unwrap().into(),
@ -956,6 +969,7 @@ mod tests {
command: CliCommand::VoteUpdateCommission { command: CliCommand::VoteUpdateCommission {
vote_account_pubkey: pubkey, vote_account_pubkey: pubkey,
commission: 42, commission: 42,
withdraw_authority: 1,
}, },
signers: vec![ signers: vec![
read_keypair_file(&default_keypair_file).unwrap().into(), read_keypair_file(&default_keypair_file).unwrap().into(),

View File

@ -57,6 +57,7 @@ fn test_stake_delegation_force() {
let vote_keypair = Keypair::new(); let vote_keypair = Keypair::new();
config.signers = vec![&default_signer, &vote_keypair]; config.signers = vec![&default_signer, &vote_keypair];
config.command = CliCommand::CreateVoteAccount { config.command = CliCommand::CreateVoteAccount {
vote_account: 1,
seed: None, seed: None,
identity_account: 0, identity_account: 0,
authorized_voter: None, authorized_voter: None,

View File

@ -49,6 +49,7 @@ fn test_vote_authorize_and_withdraw() {
let vote_account_pubkey = vote_account_keypair.pubkey(); let vote_account_pubkey = vote_account_keypair.pubkey();
config.signers = vec![&default_signer, &vote_account_keypair]; config.signers = vec![&default_signer, &vote_account_keypair];
config.command = CliCommand::CreateVoteAccount { config.command = CliCommand::CreateVoteAccount {
vote_account: 1,
seed: None, seed: None,
identity_account: 0, identity_account: 0,
authorized_voter: None, authorized_voter: None,
@ -120,6 +121,7 @@ fn test_vote_authorize_and_withdraw() {
config.command = CliCommand::VoteUpdateValidator { config.command = CliCommand::VoteUpdateValidator {
vote_account_pubkey, vote_account_pubkey,
new_identity_account: 2, new_identity_account: 2,
withdraw_authority: 1,
}; };
process_command(&config).unwrap(); process_command(&config).unwrap();