From 9e4f190633532126b6f384fc624ea53f5b4c4239 Mon Sep 17 00:00:00 2001 From: Jon Cinque Date: Tue, 30 Mar 2021 23:54:06 +0200 Subject: [PATCH] stake-pool: Rename instructions / structs (#1536) * stake-pool: Rename instructions / structs * Cargo fmt * Fix proptest --- docs/src/stake-pool.md | 4 +- stake-pool/cli/src/main.rs | 86 +++++----- .../program/proptest-regressions/state.txt | 1 + stake-pool/program/src/instruction.rs | 64 +++---- stake-pool/program/src/processor.rs | 161 +++++++++--------- stake-pool/program/src/state.rs | 51 +++--- stake-pool/program/tests/deposit.rs | 36 ++-- stake-pool/program/tests/helpers/mod.rs | 46 ++--- stake-pool/program/tests/initialize.rs | 95 +++++------ ...alance.rs => update_stake_pool_balance.rs} | 10 +- ...ce.rs => update_validator_list_balance.rs} | 23 ++- stake-pool/program/tests/vsa_add.rs | 73 ++++---- stake-pool/program/tests/vsa_remove.rs | 71 ++++---- stake-pool/program/tests/withdraw.rs | 36 ++-- 14 files changed, 370 insertions(+), 387 deletions(-) create mode 100644 stake-pool/program/proptest-regressions/state.txt rename stake-pool/program/tests/{update_pool_balance.rs => update_stake_pool_balance.rs} (85%) rename stake-pool/program/tests/{update_list_balance.rs => update_validator_list_balance.rs} (76%) diff --git a/docs/src/stake-pool.md b/docs/src/stake-pool.md index 2b4a96c0..e1c98c09 100644 --- a/docs/src/stake-pool.md +++ b/docs/src/stake-pool.md @@ -235,7 +235,7 @@ We created new validator stake accounts in the last step and staked them. Once the stake activates, we can add them to the stake pool. ```sh -$ spl-stake-pool add-validator-stake 3CLwo9CntMi4D1enHEFBe3pRJQzGJBCAYe66xFuEbmhC FYQB64aEzSmECvnG8RVvdAXBxRnzrLvcA3R22aGH2hUN +$ spl-stake-pool add-validator 3CLwo9CntMi4D1enHEFBe3pRJQzGJBCAYe66xFuEbmhC FYQB64aEzSmECvnG8RVvdAXBxRnzrLvcA3R22aGH2hUN Creating account to receive tokens Gu8xqzYFg2sPHWHhUivKNBeF9uikiauihLs9hLzziKu7 Signature: 3N1K89rGV9gWueTTrPGTDBwKAp8BikQhKHMFoREw98Q1piXFeZSSxqfnRQexrfAZQfrpYH9qwsaPWRruwkVeBivV ``` @@ -265,7 +265,7 @@ totally remove the validator stake account from the stake pool by providing staking derivatives, just like `withdraw`. ```sh -$ spl-stake-pool remove-validator-stake 3CLwo9CntMi4D1enHEFBe3pRJQzGJBCAYe66xFuEbmhC CrStLEWfme37kDc3nubK9HsmWR5dsuVUuqEKqTR4Mc5E --withdraw-from 34XMHa3JUPv46ftU4dGHvemZ9oKVjnciRePYMcX3rjEF +$ spl-stake-pool remove-validator 3CLwo9CntMi4D1enHEFBe3pRJQzGJBCAYe66xFuEbmhC CrStLEWfme37kDc3nubK9HsmWR5dsuVUuqEKqTR4Mc5E --withdraw-from 34XMHa3JUPv46ftU4dGHvemZ9oKVjnciRePYMcX3rjEF Signature: 5rrQ3xhDWyiPkUTAQkNAeq31n6sMf1xsg2x9hVY8Vj1NonwBnhxuTv87nADLkwC8Xzc4CGTNCTX2Vph9esWnXk2d ``` diff --git a/stake-pool/cli/src/main.rs b/stake-pool/cli/src/main.rs index 01067341..2802119e 100644 --- a/stake-pool/cli/src/main.rs +++ b/stake-pool/cli/src/main.rs @@ -34,9 +34,9 @@ use { spl_stake_pool::{ borsh::{get_instance_packed_len, try_from_slice_unchecked}, instruction::{ - add_validator_stake_account, create_validator_stake_account, deposit, - initialize as initialize_pool, remove_validator_stake_account, set_owner, - update_list_balance, update_pool_balance, withdraw, Fee as PoolFee, + add_validator_to_pool, create_validator_stake_account, deposit, + initialize as initialize_pool, remove_validator_from_pool, set_owner, + update_stake_pool_balance, update_validator_list_balance, withdraw, Fee as PoolFee, }, processor::Processor as PoolProcessor, stake::authorize as authorize_stake, @@ -44,7 +44,7 @@ use { stake::StakeAuthorize, stake::StakeState, state::StakePool, - state::ValidatorStakeList, + state::ValidatorList, }, spl_token::{ self, instruction::approve as approve_token, instruction::initialize_account, @@ -145,7 +145,7 @@ fn command_create_pool(config: &Config, fee: PoolFee, max_validators: u32) -> Co let pool_account = Keypair::new(); println!("Creating stake pool {}", pool_account.pubkey()); - let validator_stake_list = Keypair::new(); + let validator_list = Keypair::new(); let mint_account_balance = config .rpc_client @@ -156,15 +156,15 @@ fn command_create_pool(config: &Config, fee: PoolFee, max_validators: u32) -> Co let pool_account_balance = config .rpc_client .get_minimum_balance_for_rent_exemption(get_packed_len::())?; - let empty_validator_list = ValidatorStakeList::new_with_max_validators(max_validators); - let validator_stake_list_size = get_instance_packed_len(&empty_validator_list)?; - let validator_stake_list_balance = config + let empty_validator_list = ValidatorList::new_with_max_validators(max_validators); + let validator_list_size = get_instance_packed_len(&empty_validator_list)?; + let validator_list_balance = config .rpc_client - .get_minimum_balance_for_rent_exemption(validator_stake_list_size)?; + .get_minimum_balance_for_rent_exemption(validator_list_size)?; let total_rent_free_balances = mint_account_balance + pool_fee_account_balance + pool_account_balance - + validator_stake_list_balance; + + validator_list_balance; let default_decimals = native_mint::DECIMALS; @@ -208,9 +208,9 @@ fn command_create_pool(config: &Config, fee: PoolFee, max_validators: u32) -> Co // Validator stake account list storage system_instruction::create_account( &config.fee_payer.pubkey(), - &validator_stake_list.pubkey(), - validator_stake_list_balance, - validator_stake_list_size as u64, + &validator_list.pubkey(), + validator_list_balance, + validator_list_size as u64, &spl_stake_pool::id(), ), // Initialize pool token mint account @@ -233,7 +233,7 @@ fn command_create_pool(config: &Config, fee: PoolFee, max_validators: u32) -> Co &spl_stake_pool::id(), &pool_account.pubkey(), &config.owner.pubkey(), - &validator_stake_list.pubkey(), + &validator_list.pubkey(), &mint_account.pubkey(), &pool_fee_account.pubkey(), &spl_token::id(), @@ -252,7 +252,7 @@ fn command_create_pool(config: &Config, fee: PoolFee, max_validators: u32) -> Co let mut signers = vec![ config.fee_payer.as_ref(), &pool_account, - &validator_stake_list, + &validator_list, &mint_account, &pool_fee_account, config.owner.as_ref(), @@ -367,13 +367,13 @@ fn command_vsa_add( StakeAuthorize::Staker, ), // Add validator stake account to the pool - add_validator_stake_account( + add_validator_to_pool( &spl_stake_pool::id(), &pool, &config.owner.pubkey(), &pool_deposit_authority, &pool_withdraw_authority, - &pool_data.validator_stake_list, + &pool_data.validator_list, &stake, &token_receiver, &pool_data.pool_mint, @@ -458,13 +458,13 @@ fn command_vsa_remove( tokens_to_withdraw, )?, // Create new validator stake account address - remove_validator_stake_account( + remove_validator_from_pool( &spl_stake_pool::id(), &pool, &config.owner.pubkey(), &pool_withdraw_authority, &new_authority, - &pool_data.validator_stake_list, + &pool_data.validator_list, &stake, &withdraw_from, &pool_data.pool_mint, @@ -559,12 +559,12 @@ fn command_deposit( }?; // Check if this vote account has staking account in the pool - let validator_stake_list_data = config + let validator_list_data = config .rpc_client - .get_account_data(&pool_data.validator_stake_list)?; - let validator_stake_list_data = - try_from_slice_unchecked::(&validator_stake_list_data.as_slice())?; - if !validator_stake_list_data.contains(&vote_account) { + .get_account_data(&pool_data.validator_list)?; + let validator_list_data = + try_from_slice_unchecked::(&validator_list_data.as_slice())?; + if !validator_list_data.contains(&vote_account) { return Err("Stake account for this validator does not exist in the pool.".into()); } @@ -637,7 +637,7 @@ fn command_deposit( deposit( &spl_stake_pool::id(), &pool, - &pool_data.validator_stake_list, + &pool_data.validator_list, &pool_deposit_authority, &pool_withdraw_authority, &stake, @@ -672,11 +672,11 @@ fn command_list(config: &Config, pool: &Pubkey) -> CommandResult { if config.verbose { let validator_list = config .rpc_client - .get_account_data(&pool_data.validator_stake_list)?; - let validator_stake_list_data = - try_from_slice_unchecked::(&validator_list.as_slice())?; + .get_account_data(&pool_data.validator_list)?; + let validator_list_data = + try_from_slice_unchecked::(&validator_list.as_slice())?; println!("Current validator list"); - for validator in validator_stake_list_data.validators { + for validator in validator_list_data.validators { println!( "Vote Account: {}\tBalance: {}\tEpoch: {}", validator.validator_account, validator.balance, validator.last_update_epoch @@ -720,15 +720,15 @@ fn command_update(config: &Config, pool: &Pubkey) -> CommandResult { // Get stake pool state let pool_data = config.rpc_client.get_account_data(&pool)?; let pool_data = StakePool::try_from_slice(pool_data.as_slice()).unwrap(); - let validator_stake_list_data = config + let validator_list_data = config .rpc_client - .get_account_data(&pool_data.validator_stake_list)?; - let validator_stake_list_data = - try_from_slice_unchecked::(&validator_stake_list_data.as_slice())?; + .get_account_data(&pool_data.validator_list)?; + let validator_list_data = + try_from_slice_unchecked::(&validator_list_data.as_slice())?; let epoch_info = config.rpc_client.get_epoch_info()?; - let accounts_to_update: Vec = validator_stake_list_data + let accounts_to_update: Vec = validator_list_data .validators .iter() .filter_map(|item| { @@ -748,9 +748,9 @@ fn command_update(config: &Config, pool: &Pubkey) -> CommandResult { let mut instructions: Vec = vec![]; for chunk in accounts_to_update.chunks(MAX_ACCOUNTS_TO_UPDATE) { - instructions.push(update_list_balance( + instructions.push(update_validator_list_balance( &spl_stake_pool::id(), - &pool_data.validator_stake_list, + &pool_data.validator_list, &chunk, )?); } @@ -760,10 +760,10 @@ fn command_update(config: &Config, pool: &Pubkey) -> CommandResult { Ok(()) } else { println!("Updating stake pool..."); - instructions.push(update_pool_balance( + instructions.push(update_stake_pool_balance( &spl_stake_pool::id(), pool, - &pool_data.validator_stake_list, + &pool_data.validator_list, )?); let mut transaction = @@ -976,7 +976,7 @@ fn command_withdraw( instructions.push(withdraw( &spl_stake_pool::id(), &pool, - &pool_data.validator_stake_list, + &pool_data.validator_list, &pool_withdraw_authority, &withdraw_stake.pubkey, &stake_receiver.unwrap(), // Cannot be none at this point @@ -1183,7 +1183,7 @@ fn main() { .help("The validator vote account that this stake will be delegated to"), ) ) - .subcommand(SubCommand::with_name("add-validator-stake").about("Add validator stake account to the stake pool. Must be signed by the pool owner.") + .subcommand(SubCommand::with_name("add-validator").about("Add validator account to the stake pool. Must be signed by the pool owner.") .arg( Arg::with_name("pool") .index(1) @@ -1211,7 +1211,7 @@ fn main() { .help("Account to receive pool token. Must be initialized account of the stake pool token. Defaults to the new pool token account."), ) ) - .subcommand(SubCommand::with_name("remove-validator-stake").about("Add validator stake account to the stake pool. Must be signed by the pool owner.") + .subcommand(SubCommand::with_name("remove-validator").about("Remove validator account from the stake pool. Must be signed by the pool owner.") .arg( Arg::with_name("pool") .index(1) @@ -1435,13 +1435,13 @@ fn main() { let vote_account: Pubkey = pubkey_of(arg_matches, "vote_account").unwrap(); command_vsa_create(&config, &pool_account, &vote_account) } - ("add-validator-stake", Some(arg_matches)) => { + ("add-validator", Some(arg_matches)) => { let pool_account: Pubkey = pubkey_of(arg_matches, "pool").unwrap(); let stake_account: Pubkey = pubkey_of(arg_matches, "stake_account").unwrap(); let token_receiver: Option = pubkey_of(arg_matches, "token_receiver"); command_vsa_add(&config, &pool_account, &stake_account, &token_receiver) } - ("remove-validator-stake", Some(arg_matches)) => { + ("remove-validator", Some(arg_matches)) => { let pool_account: Pubkey = pubkey_of(arg_matches, "pool").unwrap(); let stake_account: Pubkey = pubkey_of(arg_matches, "stake_account").unwrap(); let withdraw_from: Pubkey = pubkey_of(arg_matches, "withdraw_from").unwrap(); diff --git a/stake-pool/program/proptest-regressions/state.txt b/stake-pool/program/proptest-regressions/state.txt new file mode 100644 index 00000000..769e8a16 --- /dev/null +++ b/stake-pool/program/proptest-regressions/state.txt @@ -0,0 +1 @@ +cc 41ce1c46341336993e5e5d5aa94c30865e63f9e00d31d397aef88ec79fc312ca diff --git a/stake-pool/program/src/instruction.rs b/stake-pool/program/src/instruction.rs index 40ff18ad..eb2881a5 100644 --- a/stake-pool/program/src/instruction.rs +++ b/stake-pool/program/src/instruction.rs @@ -72,7 +72,7 @@ pub enum StakePoolInstruction { /// 9. '[]' Sysvar stake history account /// 10. `[]` Pool token program id, /// 11. `[]` Stake program id, - AddValidatorStakeAccount, + AddValidatorToPool, /// Removes validator stake account from the pool /// @@ -87,21 +87,21 @@ pub enum StakePoolInstruction { /// 8. '[]' Sysvar clock account (required) /// 9. `[]` Pool token program id /// 10. `[]` Stake program id, - RemoveValidatorStakeAccount, + RemoveValidatorFromPool, /// Updates balances of validator stake accounts in the pool /// /// 0. `[w]` Validator stake list storage account /// 1. `[]` Sysvar clock account /// 2. ..2+N ` [] N validator stake accounts to update balances - UpdateListBalance, + UpdateValidatorListBalance, /// Updates total pool balance based on balances in validator stake account list storage /// /// 0. `[w]` Stake pool /// 1. `[]` Validator stake list storage account /// 2. `[]` Sysvar clock account - UpdatePoolBalance, + UpdateStakePoolBalance, /// Deposit some stake into the pool. The output is a "pool" token representing ownership /// into the pool. Inputs are converted to the current ratio. @@ -152,7 +152,7 @@ pub fn initialize( program_id: &Pubkey, stake_pool: &Pubkey, owner: &Pubkey, - validator_stake_list: &Pubkey, + validator_list: &Pubkey, pool_mint: &Pubkey, owner_pool_account: &Pubkey, token_program_id: &Pubkey, @@ -167,7 +167,7 @@ pub fn initialize( let accounts = vec![ AccountMeta::new(*stake_pool, true), AccountMeta::new_readonly(*owner, true), - AccountMeta::new(*validator_stake_list, false), + AccountMeta::new(*validator_list, false), AccountMeta::new_readonly(*pool_mint, false), AccountMeta::new_readonly(*owner_pool_account, false), AccountMeta::new_readonly(sysvar::clock::id(), false), @@ -211,14 +211,14 @@ pub fn create_validator_stake_account( }) } -/// Creates `AddValidatorStakeAccount` instruction (add new validator stake account to the pool) -pub fn add_validator_stake_account( +/// Creates `AddValidatorToPool` instruction (add new validator stake account to the pool) +pub fn add_validator_to_pool( program_id: &Pubkey, stake_pool: &Pubkey, owner: &Pubkey, stake_pool_deposit: &Pubkey, stake_pool_withdraw: &Pubkey, - validator_stake_list: &Pubkey, + validator_list: &Pubkey, stake_account: &Pubkey, pool_tokens_to: &Pubkey, pool_mint: &Pubkey, @@ -230,7 +230,7 @@ pub fn add_validator_stake_account( AccountMeta::new_readonly(*owner, true), AccountMeta::new_readonly(*stake_pool_deposit, false), AccountMeta::new_readonly(*stake_pool_withdraw, false), - AccountMeta::new(*validator_stake_list, false), + AccountMeta::new(*validator_list, false), AccountMeta::new(*stake_account, false), AccountMeta::new(*pool_tokens_to, false), AccountMeta::new(*pool_mint, false), @@ -242,18 +242,18 @@ pub fn add_validator_stake_account( Ok(Instruction { program_id: *program_id, accounts, - data: StakePoolInstruction::AddValidatorStakeAccount.try_to_vec()?, + data: StakePoolInstruction::AddValidatorToPool.try_to_vec()?, }) } -/// Creates `RemoveValidatorStakeAccount` instruction (remove validator stake account from the pool) -pub fn remove_validator_stake_account( +/// Creates `RemoveValidatorFromPool` instruction (remove validator stake account from the pool) +pub fn remove_validator_from_pool( program_id: &Pubkey, stake_pool: &Pubkey, owner: &Pubkey, stake_pool_withdraw: &Pubkey, new_stake_authority: &Pubkey, - validator_stake_list: &Pubkey, + validator_list: &Pubkey, stake_account: &Pubkey, burn_from: &Pubkey, pool_mint: &Pubkey, @@ -265,7 +265,7 @@ pub fn remove_validator_stake_account( AccountMeta::new_readonly(*owner, true), AccountMeta::new_readonly(*stake_pool_withdraw, false), AccountMeta::new_readonly(*new_stake_authority, false), - AccountMeta::new(*validator_stake_list, false), + AccountMeta::new(*validator_list, false), AccountMeta::new(*stake_account, false), AccountMeta::new(*burn_from, false), AccountMeta::new(*pool_mint, false), @@ -276,44 +276,44 @@ pub fn remove_validator_stake_account( Ok(Instruction { program_id: *program_id, accounts, - data: StakePoolInstruction::RemoveValidatorStakeAccount.try_to_vec()?, + data: StakePoolInstruction::RemoveValidatorFromPool.try_to_vec()?, }) } -/// Creates `UpdateListBalance` instruction (update validator stake account balances) -pub fn update_list_balance( +/// Creates `UpdateValidatorListBalance` instruction (update validator stake account balances) +pub fn update_validator_list_balance( program_id: &Pubkey, - validator_stake_list_storage: &Pubkey, - validator_stake_list: &[Pubkey], + validator_list_storage: &Pubkey, + validator_list: &[Pubkey], ) -> Result { - let mut accounts: Vec = validator_stake_list + let mut accounts: Vec = validator_list .iter() .map(|pubkey| AccountMeta::new_readonly(*pubkey, false)) .collect(); - accounts.insert(0, AccountMeta::new(*validator_stake_list_storage, false)); + accounts.insert(0, AccountMeta::new(*validator_list_storage, false)); accounts.insert(1, AccountMeta::new_readonly(sysvar::clock::id(), false)); Ok(Instruction { program_id: *program_id, accounts, - data: StakePoolInstruction::UpdateListBalance.try_to_vec()?, + data: StakePoolInstruction::UpdateValidatorListBalance.try_to_vec()?, }) } -/// Creates `UpdatePoolBalance` instruction (pool balance from the stake account list balances) -pub fn update_pool_balance( +/// Creates `UpdateStakePoolBalance` instruction (pool balance from the stake account list balances) +pub fn update_stake_pool_balance( program_id: &Pubkey, stake_pool: &Pubkey, - validator_stake_list_storage: &Pubkey, + validator_list_storage: &Pubkey, ) -> Result { let accounts = vec![ AccountMeta::new(*stake_pool, false), - AccountMeta::new(*validator_stake_list_storage, false), + AccountMeta::new(*validator_list_storage, false), AccountMeta::new_readonly(sysvar::clock::id(), false), ]; Ok(Instruction { program_id: *program_id, accounts, - data: StakePoolInstruction::UpdatePoolBalance.try_to_vec()?, + data: StakePoolInstruction::UpdateStakePoolBalance.try_to_vec()?, }) } @@ -321,7 +321,7 @@ pub fn update_pool_balance( pub fn deposit( program_id: &Pubkey, stake_pool: &Pubkey, - validator_stake_list_storage: &Pubkey, + validator_list_storage: &Pubkey, stake_pool_deposit: &Pubkey, stake_pool_withdraw: &Pubkey, stake_to_join: &Pubkey, @@ -334,7 +334,7 @@ pub fn deposit( ) -> Result { let accounts = vec![ AccountMeta::new(*stake_pool, false), - AccountMeta::new(*validator_stake_list_storage, false), + AccountMeta::new(*validator_list_storage, false), AccountMeta::new_readonly(*stake_pool_deposit, false), AccountMeta::new_readonly(*stake_pool_withdraw, false), AccountMeta::new(*stake_to_join, false), @@ -358,7 +358,7 @@ pub fn deposit( pub fn withdraw( program_id: &Pubkey, stake_pool: &Pubkey, - validator_stake_list_storage: &Pubkey, + validator_list_storage: &Pubkey, stake_pool_withdraw: &Pubkey, stake_to_split: &Pubkey, stake_to_receive: &Pubkey, @@ -371,7 +371,7 @@ pub fn withdraw( ) -> Result { let accounts = vec![ AccountMeta::new(*stake_pool, false), - AccountMeta::new(*validator_stake_list_storage, false), + AccountMeta::new(*validator_list_storage, false), AccountMeta::new_readonly(*stake_pool_withdraw, false), AccountMeta::new(*stake_to_split, false), AccountMeta::new(*stake_to_receive, false), diff --git a/stake-pool/program/src/processor.rs b/stake-pool/program/src/processor.rs index ee1140a6..ad1e790b 100644 --- a/stake-pool/program/src/processor.rs +++ b/stake-pool/program/src/processor.rs @@ -6,7 +6,7 @@ use { error::StakePoolError, instruction::{Fee, StakePoolInstruction}, stake, - state::{AccountType, StakePool, ValidatorStakeInfo, ValidatorStakeList}, + state::{AccountType, StakePool, ValidatorList, ValidatorStakeInfo}, }, bincode::deserialize, borsh::{BorshDeserialize, BorshSerialize}, @@ -281,7 +281,7 @@ impl Processor { let account_info_iter = &mut accounts.iter(); let stake_pool_info = next_account_info(account_info_iter)?; let owner_info = next_account_info(account_info_iter)?; - let validator_stake_list_info = next_account_info(account_info_iter)?; + let validator_list_info = next_account_info(account_info_iter)?; let pool_mint_info = next_account_info(account_info_iter)?; let owner_fee_info = next_account_info(account_info_iter)?; // Clock sysvar account @@ -305,21 +305,20 @@ impl Processor { } // Check if validator stake list storage is unitialized - let mut validator_stake_list = try_from_slice_unchecked::( - &validator_stake_list_info.data.borrow(), - )?; - if !validator_stake_list.is_uninitialized() { + let mut validator_list = + try_from_slice_unchecked::(&validator_list_info.data.borrow())?; + if !validator_list.is_uninitialized() { return Err(StakePoolError::AlreadyInUse.into()); } // Check validator list size - let data_length = validator_stake_list_info.data_len(); - let expected_max_validators = ValidatorStakeList::calculate_max_validators(data_length); + let data_length = validator_list_info.data_len(); + let expected_max_validators = ValidatorList::calculate_max_validators(data_length); if expected_max_validators != max_validators as usize || max_validators == 0 { return Err(StakePoolError::UnexpectedValidatorListAccountSize.into()); } - validator_stake_list.account_type = AccountType::ValidatorStakeList; - validator_stake_list.validators.clear(); - validator_stake_list.max_validators = max_validators; + validator_list.account_type = AccountType::ValidatorList; + validator_list.validators.clear(); + validator_list.max_validators = max_validators; // Check if stake pool account is rent-exempt if !rent.is_exempt(stake_pool_info.lamports(), stake_pool_info.data_len()) { @@ -329,8 +328,8 @@ impl Processor { // Check if validator stake list account is rent-exempt if !rent.is_exempt( - validator_stake_list_info.lamports(), - validator_stake_list_info.data_len(), + validator_list_info.lamports(), + validator_list_info.data_len(), ) { msg!("Validator stake list not rent-exempt"); return Err(ProgramError::AccountNotRentExempt); @@ -375,7 +374,7 @@ impl Processor { return Err(StakePoolError::WrongMintingAuthority.into()); } - validator_stake_list.serialize(&mut *validator_stake_list_info.data.borrow_mut())?; + validator_list.serialize(&mut *validator_list_info.data.borrow_mut())?; msg!("Clock data: {:?}", clock_info.data.borrow()); msg!("Epoch: {}", clock.epoch); @@ -384,7 +383,7 @@ impl Processor { stake_pool.owner = *owner_info.key; stake_pool.deposit_bump_seed = deposit_bump_seed; stake_pool.withdraw_bump_seed = withdraw_bump_seed; - stake_pool.validator_stake_list = *validator_stake_list_info.key; + stake_pool.validator_list = *validator_list_info.key; stake_pool.pool_mint = *pool_mint_info.key; stake_pool.owner_fee_account = *owner_fee_info.key; stake_pool.token_program_id = *token_program_info.key; @@ -480,8 +479,8 @@ impl Processor { ) } - /// Processes `AddValidatorStakeAccount` instruction. - pub fn process_add_validator_stake_account( + /// Processes `AddValidatorToPool` instruction. + pub fn process_add_validator_to_pool( program_id: &Pubkey, accounts: &[AccountInfo], ) -> ProgramResult { @@ -495,7 +494,7 @@ impl Processor { // Stake pool withdraw authority let withdraw_info = next_account_info(account_info_iter)?; // Account storing validator stake list - let validator_stake_list_info = next_account_info(account_info_iter)?; + let validator_list_info = next_account_info(account_info_iter)?; // Stake account to add to the pool let stake_account_info = next_account_info(account_info_iter)?; // User account to receive pool tokens @@ -544,25 +543,24 @@ impl Processor { } // Check validator stake account list storage - if *validator_stake_list_info.key != stake_pool.validator_stake_list { + if *validator_list_info.key != stake_pool.validator_list { return Err(StakePoolError::InvalidValidatorStakeList.into()); } // Read validator stake list account and check if it is valid - let mut validator_stake_list = try_from_slice_unchecked::( - &validator_stake_list_info.data.borrow(), - )?; - if !validator_stake_list.is_valid() { + let mut validator_list = + try_from_slice_unchecked::(&validator_list_info.data.borrow())?; + if !validator_list.is_valid() { return Err(StakePoolError::InvalidState.into()); } - if validator_stake_list.max_validators as usize == validator_stake_list.validators.len() { + if validator_list.max_validators as usize == validator_list.validators.len() { return Err(ProgramError::AccountDataTooSmall); } let validator_account = Self::get_validator_checked(program_id, stake_pool_info, stake_account_info)?; - if validator_stake_list.contains(&validator_account) { + if validator_list.contains(&validator_account) { return Err(StakePoolError::ValidatorAlreadyAdded.into()); } @@ -604,12 +602,12 @@ impl Processor { Self::check_stake_activation(stake_account_info, clock, stake_history)?; // Add validator to the list and save - validator_stake_list.validators.push(ValidatorStakeInfo { + validator_list.validators.push(ValidatorStakeInfo { validator_account, balance: stake_lamports, last_update_epoch: clock.epoch, }); - validator_stake_list.serialize(&mut *validator_stake_list_info.data.borrow_mut())?; + validator_list.serialize(&mut *validator_list_info.data.borrow_mut())?; // Save amounts to the stake pool state stake_pool.pool_total += token_amount; @@ -620,8 +618,8 @@ impl Processor { Ok(()) } - /// Processes `RemoveValidatorStakeAccount` instruction. - pub fn process_remove_validator_stake_account( + /// Processes `RemoveValidatorFromPool` instruction. + pub fn process_remove_validator_from_pool( program_id: &Pubkey, accounts: &[AccountInfo], ) -> ProgramResult { @@ -635,7 +633,7 @@ impl Processor { // New stake authority let new_stake_authority_info = next_account_info(account_info_iter)?; // Account storing validator stake list - let validator_stake_list_info = next_account_info(account_info_iter)?; + let validator_list_info = next_account_info(account_info_iter)?; // Stake account to remove from the pool let stake_account_info = next_account_info(account_info_iter)?; // User account with pool tokens to burn from @@ -680,22 +678,21 @@ impl Processor { } // Check validator stake account list storage - if *validator_stake_list_info.key != stake_pool.validator_stake_list { + if *validator_list_info.key != stake_pool.validator_list { return Err(StakePoolError::InvalidValidatorStakeList.into()); } // Read validator stake list account and check if it is valid - let mut validator_stake_list = try_from_slice_unchecked::( - &validator_stake_list_info.data.borrow(), - )?; - if !validator_stake_list.is_valid() { + let mut validator_list = + try_from_slice_unchecked::(&validator_list_info.data.borrow())?; + if !validator_list.is_valid() { return Err(StakePoolError::InvalidState.into()); } let validator_account = Self::get_validator_checked(program_id, stake_pool_info, stake_account_info)?; - if !validator_stake_list.contains(&validator_account) { + if !validator_list.contains(&validator_account) { return Err(StakePoolError::ValidatorNotFound.into()); } @@ -734,10 +731,10 @@ impl Processor { )?; // Remove validator from the list and save - validator_stake_list + validator_list .validators .retain(|item| item.validator_account != validator_account); - validator_stake_list.serialize(&mut *validator_stake_list_info.data.borrow_mut())?; + validator_list.serialize(&mut *validator_list_info.data.borrow_mut())?; // Save amounts to the stake pool state stake_pool.pool_total -= token_amount; @@ -748,14 +745,14 @@ impl Processor { Ok(()) } - /// Processes `UpdateListBalance` instruction. - pub fn process_update_list_balance( + /// Processes `UpdateValidatorListBalance` instruction. + pub fn process_update_validator_list_balance( _program_id: &Pubkey, accounts: &[AccountInfo], ) -> ProgramResult { let account_info_iter = &mut accounts.iter(); // Account storing validator stake list - let validator_stake_list_info = next_account_info(account_info_iter)?; + let validator_list_info = next_account_info(account_info_iter)?; // Clock sysvar account let clock_info = next_account_info(account_info_iter)?; let clock = &Clock::from_account_info(clock_info)?; @@ -763,10 +760,9 @@ impl Processor { let validator_stake_accounts = account_info_iter.as_slice(); // Read validator stake list account and check if it is valid - let mut validator_stake_list = try_from_slice_unchecked::( - &validator_stake_list_info.data.borrow(), - )?; - if !validator_stake_list.is_valid() { + let mut validator_list = + try_from_slice_unchecked::(&validator_list_info.data.borrow())?; + if !validator_list.is_valid() { return Err(StakePoolError::InvalidState.into()); } @@ -777,7 +773,7 @@ impl Processor { let mut changes = false; // Do a brute iteration through the list, optimize if necessary - for validator_stake_record in &mut validator_stake_list.validators { + for validator_stake_record in &mut validator_list.validators { if validator_stake_record.last_update_epoch >= clock.epoch { continue; } @@ -797,14 +793,14 @@ impl Processor { } if changes { - validator_stake_list.serialize(&mut *validator_stake_list_info.data.borrow_mut())?; + validator_list.serialize(&mut *validator_list_info.data.borrow_mut())?; } Ok(()) } - /// Processes `UpdatePoolBalance` instruction. - pub fn process_update_pool_balance( + /// Processes `UpdateStakePoolBalance` instruction. + pub fn process_update_stake_pool_balance( _program_id: &Pubkey, accounts: &[AccountInfo], ) -> ProgramResult { @@ -812,7 +808,7 @@ impl Processor { // Stake pool account let stake_pool_info = next_account_info(account_info_iter)?; // Account storing validator stake list - let validator_stake_list_info = next_account_info(account_info_iter)?; + let validator_list_info = next_account_info(account_info_iter)?; // Clock sysvar account let clock_info = next_account_info(account_info_iter)?; let clock = &Clock::from_account_info(clock_info)?; @@ -824,20 +820,19 @@ impl Processor { } // Check validator stake account list storage - if *validator_stake_list_info.key != stake_pool.validator_stake_list { + if *validator_list_info.key != stake_pool.validator_list { return Err(StakePoolError::InvalidValidatorStakeList.into()); } // Read validator stake list account and check if it is valid - let validator_stake_list = try_from_slice_unchecked::( - &validator_stake_list_info.data.borrow(), - )?; - if !validator_stake_list.is_valid() { + let validator_list = + try_from_slice_unchecked::(&validator_list_info.data.borrow())?; + if !validator_list.is_valid() { return Err(StakePoolError::InvalidState.into()); } let mut total_balance: u64 = 0; - for validator_stake_record in validator_stake_list.validators { + for validator_stake_record in validator_list.validators { if validator_stake_record.last_update_epoch < clock.epoch { return Err(StakePoolError::StakeListOutOfDate.into()); } @@ -886,7 +881,7 @@ impl Processor { // Stake pool let stake_pool_info = next_account_info(account_info_iter)?; // Account storing validator stake list - let validator_stake_list_info = next_account_info(account_info_iter)?; + let validator_list_info = next_account_info(account_info_iter)?; // Stake pool deposit authority let deposit_info = next_account_info(account_info_iter)?; // Stake pool withdraw authority @@ -937,7 +932,7 @@ impl Processor { } // Check validator stake account list storage - if *validator_stake_list_info.key != stake_pool.validator_stake_list { + if *validator_list_info.key != stake_pool.validator_list { return Err(StakePoolError::InvalidValidatorStakeList.into()); } @@ -947,17 +942,16 @@ impl Processor { } // Read validator stake list account and check if it is valid - let mut validator_stake_list = try_from_slice_unchecked::( - &validator_stake_list_info.data.borrow(), - )?; - if !validator_stake_list.is_valid() { + let mut validator_list = + try_from_slice_unchecked::(&validator_list_info.data.borrow())?; + if !validator_list.is_valid() { return Err(StakePoolError::InvalidState.into()); } let validator_account = Self::get_validator_checked(program_id, stake_pool_info, validator_stake_account_info)?; - let validator_list_item = validator_stake_list + let validator_list_item = validator_list .find_mut(&validator_account) .ok_or(StakePoolError::ValidatorNotFound)?; @@ -1036,7 +1030,7 @@ impl Processor { stake_pool.serialize(&mut *stake_pool_info.data.borrow_mut())?; validator_list_item.balance = **validator_stake_account_info.lamports.borrow(); - validator_stake_list.serialize(&mut *validator_stake_list_info.data.borrow_mut())?; + validator_list.serialize(&mut *validator_list_info.data.borrow_mut())?; Ok(()) } @@ -1051,7 +1045,7 @@ impl Processor { // Stake pool let stake_pool_info = next_account_info(account_info_iter)?; // Account storing validator stake list - let validator_stake_list_info = next_account_info(account_info_iter)?; + let validator_list_info = next_account_info(account_info_iter)?; // Stake pool withdraw authority let withdraw_info = next_account_info(account_info_iter)?; // Stake account to split @@ -1090,7 +1084,7 @@ impl Processor { } // Check validator stake account list storage - if *validator_stake_list_info.key != stake_pool.validator_stake_list { + if *validator_list_info.key != stake_pool.validator_list { return Err(StakePoolError::InvalidValidatorStakeList.into()); } @@ -1100,17 +1094,16 @@ impl Processor { } // Read validator stake list account and check if it is valid - let mut validator_stake_list = try_from_slice_unchecked::( - &validator_stake_list_info.data.borrow(), - )?; - if !validator_stake_list.is_valid() { + let mut validator_list = + try_from_slice_unchecked::(&validator_list_info.data.borrow())?; + if !validator_list.is_valid() { return Err(StakePoolError::InvalidState.into()); } let validator_account = Self::get_validator_checked(program_id, stake_pool_info, stake_split_from)?; - let validator_list_item = validator_stake_list + let validator_list_item = validator_list .find_mut(&validator_account) .ok_or(StakePoolError::ValidatorNotFound)?; @@ -1168,7 +1161,7 @@ impl Processor { stake_pool.serialize(&mut *stake_pool_info.data.borrow_mut())?; validator_list_item.balance = **stake_split_from.lamports.borrow(); - validator_stake_list.serialize(&mut *validator_stake_list_info.data.borrow_mut())?; + validator_list.serialize(&mut *validator_list_info.data.borrow_mut())?; Ok(()) } @@ -1216,21 +1209,21 @@ impl Processor { msg!("Instruction: CreateValidatorStakeAccount"); Self::process_create_validator_stake_account(program_id, accounts) } - StakePoolInstruction::AddValidatorStakeAccount => { - msg!("Instruction: AddValidatorStakeAccount"); - Self::process_add_validator_stake_account(program_id, accounts) + StakePoolInstruction::AddValidatorToPool => { + msg!("Instruction: AddValidatorToPool"); + Self::process_add_validator_to_pool(program_id, accounts) } - StakePoolInstruction::RemoveValidatorStakeAccount => { - msg!("Instruction: RemoveValidatorStakeAccount"); - Self::process_remove_validator_stake_account(program_id, accounts) + StakePoolInstruction::RemoveValidatorFromPool => { + msg!("Instruction: RemoveValidatorFromPool"); + Self::process_remove_validator_from_pool(program_id, accounts) } - StakePoolInstruction::UpdateListBalance => { - msg!("Instruction: UpdateListBalance"); - Self::process_update_list_balance(program_id, accounts) + StakePoolInstruction::UpdateValidatorListBalance => { + msg!("Instruction: UpdateValidatorListBalance"); + Self::process_update_validator_list_balance(program_id, accounts) } - StakePoolInstruction::UpdatePoolBalance => { - msg!("Instruction: UpdatePoolBalance"); - Self::process_update_pool_balance(program_id, accounts) + StakePoolInstruction::UpdateStakePoolBalance => { + msg!("Instruction: UpdateStakePoolBalance"); + Self::process_update_stake_pool_balance(program_id, accounts) } StakePoolInstruction::Deposit => { msg!("Instruction: Deposit"); diff --git a/stake-pool/program/src/state.rs b/stake-pool/program/src/state.rs index 868bef6e..d23dcc4b 100644 --- a/stake-pool/program/src/state.rs +++ b/stake-pool/program/src/state.rs @@ -16,7 +16,7 @@ pub enum AccountType { /// Stake pool StakePool, /// Validator stake list - ValidatorStakeList, + ValidatorList, } impl Default for AccountType { @@ -41,7 +41,7 @@ pub struct StakePool { /// for `create_program_address(&[state::StakePool account, "withdrawal"])` pub withdraw_bump_seed: u8, /// Validator stake list storage account - pub validator_stake_list: Pubkey, + pub validator_list: Pubkey, /// Pool Mint pub pool_mint: Pubkey, /// Owner fee account @@ -155,8 +155,8 @@ impl StakePool { /// Storage list for all validator stake accounts in the pool. #[repr(C)] #[derive(Clone, Debug, Default, PartialEq, BorshDeserialize, BorshSerialize, BorshSchema)] -pub struct ValidatorStakeList { - /// Account type, must be ValidatorStakeList currently +pub struct ValidatorList { + /// Account type, must be ValidatorList currently pub account_type: AccountType, /// Maximum allowable number of validators @@ -180,11 +180,11 @@ pub struct ValidatorStakeInfo { pub last_update_epoch: u64, } -impl ValidatorStakeList { +impl ValidatorList { /// Create an empty instance containing space for `max_validators` pub fn new_with_max_validators(max_validators: u32) -> Self { Self { - account_type: AccountType::ValidatorStakeList, + account_type: AccountType::ValidatorList, max_validators, validators: vec![ValidatorStakeInfo::default(); max_validators as usize], } @@ -192,7 +192,8 @@ impl ValidatorStakeList { /// Calculate the number of validator entries that fit in the provided length pub fn calculate_max_validators(buffer_length: usize) -> usize { - (buffer_length - 1 - 4 - 4) / 48 + let header_size = 1 + 4 + 4; + buffer_length.saturating_sub(header_size) / 48 } /// Check if contains validator with particular pubkey @@ -217,7 +218,7 @@ impl ValidatorStakeList { /// Check if validator stake list is actually initialized as a validator stake list pub fn is_valid(&self) -> bool { - self.account_type == AccountType::ValidatorStakeList + self.account_type == AccountType::ValidatorList } /// Check if the validator stake list is uninitialized @@ -238,11 +239,10 @@ mod test { #[test] fn test_state_packing() { let max_validators = 10_000; - let size = - get_instance_packed_len(&ValidatorStakeList::new_with_max_validators(max_validators)) - .unwrap(); + let size = get_instance_packed_len(&ValidatorList::new_with_max_validators(max_validators)) + .unwrap(); // Not initialized - let stake_list = ValidatorStakeList { + let stake_list = ValidatorList { account_type: AccountType::Uninitialized, max_validators: 0, validators: vec![], @@ -250,26 +250,24 @@ mod test { let mut byte_vec = vec![0u8; size]; let mut bytes = byte_vec.as_mut_slice(); stake_list.serialize(&mut bytes).unwrap(); - let stake_list_unpacked = - try_from_slice_unchecked::(&byte_vec).unwrap(); + let stake_list_unpacked = try_from_slice_unchecked::(&byte_vec).unwrap(); assert_eq!(stake_list_unpacked, stake_list); // Empty - let stake_list = ValidatorStakeList { - account_type: AccountType::ValidatorStakeList, + let stake_list = ValidatorList { + account_type: AccountType::ValidatorList, max_validators: 0, validators: vec![], }; let mut byte_vec = vec![0u8; size]; let mut bytes = byte_vec.as_mut_slice(); stake_list.serialize(&mut bytes).unwrap(); - let stake_list_unpacked = - try_from_slice_unchecked::(&byte_vec).unwrap(); + let stake_list_unpacked = try_from_slice_unchecked::(&byte_vec).unwrap(); assert_eq!(stake_list_unpacked, stake_list); // With several accounts - let stake_list = ValidatorStakeList { - account_type: AccountType::ValidatorStakeList, + let stake_list = ValidatorList { + account_type: AccountType::ValidatorList, max_validators, validators: vec![ ValidatorStakeInfo { @@ -292,20 +290,19 @@ mod test { let mut byte_vec = vec![0u8; size]; let mut bytes = byte_vec.as_mut_slice(); stake_list.serialize(&mut bytes).unwrap(); - let stake_list_unpacked = - try_from_slice_unchecked::(&byte_vec).unwrap(); + let stake_list_unpacked = try_from_slice_unchecked::(&byte_vec).unwrap(); assert_eq!(stake_list_unpacked, stake_list); } proptest! { #[test] fn stake_list_size_calculation(test_amount in 0..=100_000_u32) { - let validators = ValidatorStakeList::new_with_max_validators(test_amount); + let validators = ValidatorList::new_with_max_validators(test_amount); let size = get_instance_packed_len(&validators).unwrap(); - assert_eq!(ValidatorStakeList::calculate_max_validators(size), test_amount as usize); - assert_eq!(ValidatorStakeList::calculate_max_validators(size + 1), test_amount as usize); - assert_eq!(ValidatorStakeList::calculate_max_validators(size + get_packed_len::()), (test_amount + 1)as usize); - assert_eq!(ValidatorStakeList::calculate_max_validators(size - 1), (test_amount - 1) as usize); + assert_eq!(ValidatorList::calculate_max_validators(size), test_amount as usize); + assert_eq!(ValidatorList::calculate_max_validators(size.saturating_add(1)), test_amount as usize); + assert_eq!(ValidatorList::calculate_max_validators(size.saturating_add(get_packed_len::())), (test_amount + 1)as usize); + assert_eq!(ValidatorList::calculate_max_validators(size.saturating_sub(1)), (test_amount.saturating_sub(1)) as usize); } } } diff --git a/stake-pool/program/tests/deposit.rs b/stake-pool/program/tests/deposit.rs index 55f477da..e750bd3e 100644 --- a/stake-pool/program/tests/deposit.rs +++ b/stake-pool/program/tests/deposit.rs @@ -32,7 +32,7 @@ async fn setup() -> ( .await .unwrap(); - let validator_stake_account: ValidatorStakeAccount = simple_add_validator_stake_account( + let validator_stake_account: ValidatorStakeAccount = simple_add_validator_to_pool( &mut banks_client, &payer, &recent_blockhash, @@ -134,15 +134,14 @@ async fn test_stake_pool_deposit() { state::StakePool::try_from_slice(&stake_pool_before.data.as_slice()).unwrap(); // Save validator stake account record before depositing - let validator_stake_list = get_account( + let validator_list = get_account( &mut banks_client, - &stake_pool_accounts.validator_stake_list.pubkey(), + &stake_pool_accounts.validator_list.pubkey(), ) .await; - let validator_stake_list = - try_from_slice_unchecked::(validator_stake_list.data.as_slice()) - .unwrap(); - let validator_stake_item_before = validator_stake_list + let validator_list = + try_from_slice_unchecked::(validator_list.data.as_slice()).unwrap(); + let validator_stake_item_before = validator_list .find(&validator_stake_account.vote.pubkey()) .unwrap(); @@ -192,15 +191,14 @@ async fn test_stake_pool_deposit() { assert_eq!(pool_fee_token_balance, fee); // Check balances in validator stake account list storage - let validator_stake_list = get_account( + let validator_list = get_account( &mut banks_client, - &stake_pool_accounts.validator_stake_list.pubkey(), + &stake_pool_accounts.validator_list.pubkey(), ) .await; - let validator_stake_list = - try_from_slice_unchecked::(validator_stake_list.data.as_slice()) - .unwrap(); - let validator_stake_item = validator_stake_list + let validator_list = + try_from_slice_unchecked::(validator_list.data.as_slice()).unwrap(); + let validator_stake_item = validator_list .find(&validator_stake_account.vote.pubkey()) .unwrap(); assert_eq!( @@ -245,7 +243,7 @@ async fn test_stake_pool_deposit_with_wrong_stake_program_id() { &[instruction::deposit( &id(), &stake_pool_accounts.stake_pool.pubkey(), - &stake_pool_accounts.validator_stake_list.pubkey(), + &stake_pool_accounts.validator_list.pubkey(), &stake_pool_accounts.deposit_authority, &stake_pool_accounts.withdraw_authority, &user_stake.pubkey(), @@ -385,7 +383,7 @@ async fn test_stake_pool_deposit_with_wrong_token_program_id() { &[instruction::deposit( &id(), &stake_pool_accounts.stake_pool.pubkey(), - &stake_pool_accounts.validator_stake_list.pubkey(), + &stake_pool_accounts.validator_list.pubkey(), &stake_pool_accounts.deposit_authority, &stake_pool_accounts.withdraw_authority, &user_stake.pubkey(), @@ -415,7 +413,7 @@ async fn test_stake_pool_deposit_with_wrong_token_program_id() { } #[tokio::test] -async fn test_stake_pool_deposit_with_wrong_validator_stake_list_account() { +async fn test_stake_pool_deposit_with_wrong_validator_list_account() { let ( mut banks_client, payer, @@ -455,8 +453,8 @@ async fn test_stake_pool_deposit_with_wrong_validator_stake_list_account() { .await .unwrap(); - let wrong_validator_stake_list = Keypair::new(); - stake_pool_accounts.validator_stake_list = wrong_validator_stake_list; + let wrong_validator_list = Keypair::new(); + stake_pool_accounts.validator_list = wrong_validator_list; let transaction_error = stake_pool_accounts .deposit_stake( @@ -907,7 +905,7 @@ async fn test_stake_pool_deposit_with_wrong_mint_for_receiver_acc() { } #[tokio::test] -async fn test_deposit_with_uninitialized_validator_stake_list() {} // TODO +async fn test_deposit_with_uninitialized_validator_list() {} // TODO #[tokio::test] async fn test_deposit_with_out_of_dated_pool_balances() {} // TODO diff --git a/stake-pool/program/tests/helpers/mod.rs b/stake-pool/program/tests/helpers/mod.rs index aadd29a0..0ca4dbe4 100644 --- a/stake-pool/program/tests/helpers/mod.rs +++ b/stake-pool/program/tests/helpers/mod.rs @@ -165,7 +165,7 @@ pub async fn create_stake_pool( payer: &Keypair, recent_blockhash: &Hash, stake_pool: &Keypair, - validator_stake_list: &Keypair, + validator_list: &Keypair, pool_mint: &Pubkey, pool_token_account: &Pubkey, owner: &Keypair, @@ -174,11 +174,11 @@ pub async fn create_stake_pool( ) -> Result<(), TransportError> { let rent = banks_client.get_rent().await.unwrap(); let rent_stake_pool = rent.minimum_balance(get_packed_len::()); - let validator_stake_list_size = get_instance_packed_len( - &state::ValidatorStakeList::new_with_max_validators(max_validators), + let validator_list_size = get_instance_packed_len( + &state::ValidatorList::new_with_max_validators(max_validators), ) .unwrap(); - let rent_validator_stake_list = rent.minimum_balance(validator_stake_list_size); + let rent_validator_list = rent.minimum_balance(validator_list_size); let mut transaction = Transaction::new_with_payer( &[ @@ -191,16 +191,16 @@ pub async fn create_stake_pool( ), system_instruction::create_account( &payer.pubkey(), - &validator_stake_list.pubkey(), - rent_validator_stake_list, - validator_stake_list_size as u64, + &validator_list.pubkey(), + rent_validator_list, + validator_list_size as u64, &id(), ), instruction::initialize( &id(), &stake_pool.pubkey(), &owner.pubkey(), - &validator_stake_list.pubkey(), + &validator_list.pubkey(), pool_mint, pool_token_account, &spl_token::id(), @@ -212,7 +212,7 @@ pub async fn create_stake_pool( Some(&payer.pubkey()), ); transaction.sign( - &[payer, stake_pool, validator_stake_list, owner], + &[payer, stake_pool, validator_list, owner], *recent_blockhash, ); banks_client.process_transaction(transaction).await?; @@ -434,7 +434,7 @@ impl ValidatorStakeAccount { pub struct StakePoolAccounts { pub stake_pool: Keypair, - pub validator_stake_list: Keypair, + pub validator_list: Keypair, pub pool_mint: Keypair, pub pool_fee_account: Keypair, pub owner: Keypair, @@ -447,7 +447,7 @@ pub struct StakePoolAccounts { impl StakePoolAccounts { pub fn new() -> Self { let stake_pool = Keypair::new(); - let validator_stake_list = Keypair::new(); + let validator_list = Keypair::new(); let stake_pool_address = &stake_pool.pubkey(); let (withdraw_authority, _) = Pubkey::find_program_address( &[&stake_pool_address.to_bytes()[..32], b"withdraw"], @@ -463,7 +463,7 @@ impl StakePoolAccounts { Self { stake_pool, - validator_stake_list, + validator_list, pool_mint, pool_fee_account, owner, @@ -509,7 +509,7 @@ impl StakePoolAccounts { &payer, &recent_blockhash, &self.stake_pool, - &self.validator_stake_list, + &self.validator_list, &self.pool_mint.pubkey(), &self.pool_fee_account.pubkey(), &self.owner, @@ -533,7 +533,7 @@ impl StakePoolAccounts { &[instruction::deposit( &id(), &self.stake_pool.pubkey(), - &self.validator_stake_list.pubkey(), + &self.validator_list.pubkey(), &self.deposit_authority, &self.withdraw_authority, stake, @@ -567,7 +567,7 @@ impl StakePoolAccounts { &[instruction::withdraw( &id(), &self.stake_pool.pubkey(), - &self.validator_stake_list.pubkey(), + &self.validator_list.pubkey(), &self.withdraw_authority, validator_stake_account, stake_recipient, @@ -586,7 +586,7 @@ impl StakePoolAccounts { Ok(()) } - pub async fn add_validator_stake_account( + pub async fn add_validator_to_pool( &self, banks_client: &mut BanksClient, payer: &Keypair, @@ -595,13 +595,13 @@ impl StakePoolAccounts { pool_account: &Pubkey, ) -> Option { let mut transaction = Transaction::new_with_payer( - &[instruction::add_validator_stake_account( + &[instruction::add_validator_to_pool( &id(), &self.stake_pool.pubkey(), &self.owner.pubkey(), &self.deposit_authority, &self.withdraw_authority, - &self.validator_stake_list.pubkey(), + &self.validator_list.pubkey(), stake, pool_account, &self.pool_mint.pubkey(), @@ -615,7 +615,7 @@ impl StakePoolAccounts { banks_client.process_transaction(transaction).await.err() } - pub async fn remove_validator_stake_account( + pub async fn remove_validator_from_pool( &self, banks_client: &mut BanksClient, payer: &Keypair, @@ -625,13 +625,13 @@ impl StakePoolAccounts { new_authority: &Pubkey, ) -> Option { let mut transaction = Transaction::new_with_payer( - &[instruction::remove_validator_stake_account( + &[instruction::remove_validator_from_pool( &id(), &self.stake_pool.pubkey(), &self.owner.pubkey(), &self.withdraw_authority, &new_authority, - &self.validator_stake_list.pubkey(), + &self.validator_list.pubkey(), stake, pool_account, &self.pool_mint.pubkey(), @@ -646,7 +646,7 @@ impl StakePoolAccounts { } } -pub async fn simple_add_validator_stake_account( +pub async fn simple_add_validator_to_pool( banks_client: &mut BanksClient, payer: &Keypair, recent_blockhash: &Hash, @@ -673,7 +673,7 @@ pub async fn simple_add_validator_stake_account( .await .unwrap(); let error = stake_pool_accounts - .add_validator_stake_account( + .add_validator_to_pool( banks_client, &payer, &recent_blockhash, diff --git a/stake-pool/program/tests/initialize.rs b/stake-pool/program/tests/initialize.rs index 9a1d7a3b..bdc7c919 100644 --- a/stake-pool/program/tests/initialize.rs +++ b/stake-pool/program/tests/initialize.rs @@ -66,15 +66,14 @@ async fn test_stake_pool_initialize() { assert_eq!(stake_pool.owner, id()); // Validator stake list storage initialized - let validator_stake_list = get_account( + let validator_list = get_account( &mut banks_client, - &stake_pool_accounts.validator_stake_list.pubkey(), + &stake_pool_accounts.validator_list.pubkey(), ) .await; - let validator_stake_list = - try_from_slice_unchecked::(validator_stake_list.data.as_slice()) - .unwrap(); - assert_eq!(validator_stake_list.is_valid(), true); + let validator_list = + try_from_slice_unchecked::(validator_list.data.as_slice()).unwrap(); + assert_eq!(validator_list.is_valid(), true); } #[tokio::test] @@ -120,7 +119,7 @@ async fn test_initialize_stake_pool_with_already_initialized_stake_list_storage( let latest_blockhash = banks_client.get_recent_blockhash().await.unwrap(); let mut second_stake_pool_accounts = StakePoolAccounts::new(); - second_stake_pool_accounts.validator_stake_list = stake_pool_accounts.validator_stake_list; + second_stake_pool_accounts.validator_list = stake_pool_accounts.validator_list; let transaction_error = second_stake_pool_accounts .initialize_stake_pool(&mut banks_client, &payer, &latest_blockhash) @@ -180,11 +179,11 @@ async fn test_initialize_stake_pool_with_wrong_max_validators() { let rent = banks_client.get_rent().await.unwrap(); let rent_stake_pool = rent.minimum_balance(get_packed_len::()); - let validator_stake_list_size = get_instance_packed_len( - &state::ValidatorStakeList::new_with_max_validators(stake_pool_accounts.max_validators - 1), + let validator_list_size = get_instance_packed_len( + &state::ValidatorList::new_with_max_validators(stake_pool_accounts.max_validators - 1), ) .unwrap(); - let rent_validator_stake_list = rent.minimum_balance(validator_stake_list_size); + let rent_validator_list = rent.minimum_balance(validator_list_size); let mut transaction = Transaction::new_with_payer( &[ @@ -197,16 +196,16 @@ async fn test_initialize_stake_pool_with_wrong_max_validators() { ), system_instruction::create_account( &payer.pubkey(), - &stake_pool_accounts.validator_stake_list.pubkey(), - rent_validator_stake_list, - validator_stake_list_size as u64, + &stake_pool_accounts.validator_list.pubkey(), + rent_validator_list, + validator_list_size as u64, &id(), ), instruction::initialize( &id(), &stake_pool_accounts.stake_pool.pubkey(), &stake_pool_accounts.owner.pubkey(), - &stake_pool_accounts.validator_stake_list.pubkey(), + &stake_pool_accounts.validator_list.pubkey(), &stake_pool_accounts.pool_mint.pubkey(), &stake_pool_accounts.pool_fee_account.pubkey(), &spl_token::id(), @@ -221,7 +220,7 @@ async fn test_initialize_stake_pool_with_wrong_max_validators() { &[ &payer, &stake_pool_accounts.stake_pool, - &stake_pool_accounts.validator_stake_list, + &stake_pool_accounts.validator_list, &stake_pool_accounts.owner, ], recent_blockhash, @@ -274,7 +273,7 @@ async fn test_initialize_stake_pool_with_wrong_mint_authority() { &payer, &recent_blockhash, &stake_pool_accounts.stake_pool, - &stake_pool_accounts.validator_stake_list, + &stake_pool_accounts.validator_list, &wrong_mint.pubkey(), &stake_pool_accounts.pool_fee_account.pubkey(), &stake_pool_accounts.owner, @@ -334,11 +333,11 @@ async fn test_initialize_stake_pool_with_wrong_token_program_id() { banks_client.process_transaction(transaction).await.unwrap(); let rent_stake_pool = rent.minimum_balance(get_packed_len::()); - let validator_stake_list_size = get_instance_packed_len( - &state::ValidatorStakeList::new_with_max_validators(stake_pool_accounts.max_validators), + let validator_list_size = get_instance_packed_len( + &state::ValidatorList::new_with_max_validators(stake_pool_accounts.max_validators), ) .unwrap(); - let rent_validator_stake_list = rent.minimum_balance(validator_stake_list_size); + let rent_validator_list = rent.minimum_balance(validator_list_size); let mut transaction = Transaction::new_with_payer( &[ @@ -351,16 +350,16 @@ async fn test_initialize_stake_pool_with_wrong_token_program_id() { ), system_instruction::create_account( &payer.pubkey(), - &stake_pool_accounts.validator_stake_list.pubkey(), - rent_validator_stake_list, - validator_stake_list_size as u64, + &stake_pool_accounts.validator_list.pubkey(), + rent_validator_list, + validator_list_size as u64, &id(), ), instruction::initialize( &id(), &stake_pool_accounts.stake_pool.pubkey(), &stake_pool_accounts.owner.pubkey(), - &stake_pool_accounts.validator_stake_list.pubkey(), + &stake_pool_accounts.validator_list.pubkey(), &stake_pool_accounts.pool_mint.pubkey(), &stake_pool_accounts.pool_fee_account.pubkey(), &wrong_token_program.pubkey(), @@ -375,7 +374,7 @@ async fn test_initialize_stake_pool_with_wrong_token_program_id() { &[ &payer, &stake_pool_accounts.stake_pool, - &stake_pool_accounts.validator_stake_list, + &stake_pool_accounts.validator_list, &stake_pool_accounts.owner, ], recent_blockhash, @@ -434,7 +433,7 @@ async fn test_initialize_stake_pool_with_wrong_fee_accounts_owner() { &payer, &recent_blockhash, &stake_pool_accounts.stake_pool, - &stake_pool_accounts.validator_stake_list, + &stake_pool_accounts.validator_list, &stake_pool_accounts.pool_mint.pubkey(), &stake_pool_accounts.pool_fee_account.pubkey(), &stake_pool_accounts.owner, @@ -500,11 +499,11 @@ async fn test_initialize_stake_pool_with_not_rent_exempt_pool() { .await; let rent = banks_client.get_rent().await.unwrap(); - let validator_stake_list_size = get_instance_packed_len( - &state::ValidatorStakeList::new_with_max_validators(stake_pool_accounts.max_validators), + let validator_list_size = get_instance_packed_len( + &state::ValidatorList::new_with_max_validators(stake_pool_accounts.max_validators), ) .unwrap(); - let rent_validator_stake_list = rent.minimum_balance(validator_stake_list_size); + let rent_validator_list = rent.minimum_balance(validator_list_size); let mut transaction = Transaction::new_with_payer( &[ @@ -517,16 +516,16 @@ async fn test_initialize_stake_pool_with_not_rent_exempt_pool() { ), system_instruction::create_account( &payer.pubkey(), - &stake_pool_accounts.validator_stake_list.pubkey(), - rent_validator_stake_list, - validator_stake_list_size as u64, + &stake_pool_accounts.validator_list.pubkey(), + rent_validator_list, + validator_list_size as u64, &id(), ), instruction::initialize( &id(), &stake_pool_accounts.stake_pool.pubkey(), &stake_pool_accounts.owner.pubkey(), - &stake_pool_accounts.validator_stake_list.pubkey(), + &stake_pool_accounts.validator_list.pubkey(), &stake_pool_accounts.pool_mint.pubkey(), &stake_pool_accounts.pool_fee_account.pubkey(), &spl_token::id(), @@ -541,7 +540,7 @@ async fn test_initialize_stake_pool_with_not_rent_exempt_pool() { &[ &payer, &stake_pool_accounts.stake_pool, - &stake_pool_accounts.validator_stake_list, + &stake_pool_accounts.validator_list, &stake_pool_accounts.owner, ], recent_blockhash, @@ -562,7 +561,7 @@ async fn test_initialize_stake_pool_with_not_rent_exempt_pool() { } #[tokio::test] -async fn test_initialize_stake_pool_with_not_rent_exempt_validator_stake_list() { +async fn test_initialize_stake_pool_with_not_rent_exempt_validator_list() { let (mut banks_client, payer, recent_blockhash) = program_test().start().await; let stake_pool_accounts = StakePoolAccounts::new(); @@ -576,8 +575,8 @@ async fn test_initialize_stake_pool_with_not_rent_exempt_validator_stake_list() let rent = banks_client.get_rent().await.unwrap(); let rent_stake_pool = rent.minimum_balance(get_packed_len::()); - let validator_stake_list_size = get_instance_packed_len( - &state::ValidatorStakeList::new_with_max_validators(stake_pool_accounts.max_validators), + let validator_list_size = get_instance_packed_len( + &state::ValidatorList::new_with_max_validators(stake_pool_accounts.max_validators), ) .unwrap(); @@ -592,16 +591,16 @@ async fn test_initialize_stake_pool_with_not_rent_exempt_validator_stake_list() ), system_instruction::create_account( &payer.pubkey(), - &stake_pool_accounts.validator_stake_list.pubkey(), + &stake_pool_accounts.validator_list.pubkey(), 1, - validator_stake_list_size as u64, + validator_list_size as u64, &id(), ), instruction::initialize( &id(), &stake_pool_accounts.stake_pool.pubkey(), &stake_pool_accounts.owner.pubkey(), - &stake_pool_accounts.validator_stake_list.pubkey(), + &stake_pool_accounts.validator_list.pubkey(), &stake_pool_accounts.pool_mint.pubkey(), &stake_pool_accounts.pool_fee_account.pubkey(), &spl_token::id(), @@ -616,7 +615,7 @@ async fn test_initialize_stake_pool_with_not_rent_exempt_validator_stake_list() &[ &payer, &stake_pool_accounts.stake_pool, - &stake_pool_accounts.validator_stake_list, + &stake_pool_accounts.validator_list, &stake_pool_accounts.owner, ], recent_blockhash, @@ -652,11 +651,11 @@ async fn test_initialize_stake_pool_without_owner_signature() { let rent = banks_client.get_rent().await.unwrap(); let rent_stake_pool = rent.minimum_balance(get_packed_len::()); - let validator_stake_list_size = get_instance_packed_len( - &state::ValidatorStakeList::new_with_max_validators(stake_pool_accounts.max_validators), + let validator_list_size = get_instance_packed_len( + &state::ValidatorList::new_with_max_validators(stake_pool_accounts.max_validators), ) .unwrap(); - let rent_validator_stake_list = rent.minimum_balance(validator_stake_list_size); + let rent_validator_list = rent.minimum_balance(validator_list_size); let init_data = instruction::StakePoolInstruction::Initialize { fee: stake_pool_accounts.fee.clone(), @@ -666,7 +665,7 @@ async fn test_initialize_stake_pool_without_owner_signature() { let accounts = vec![ AccountMeta::new(stake_pool_accounts.stake_pool.pubkey(), true), AccountMeta::new_readonly(stake_pool_accounts.owner.pubkey(), false), - AccountMeta::new(stake_pool_accounts.validator_stake_list.pubkey(), false), + AccountMeta::new(stake_pool_accounts.validator_list.pubkey(), false), AccountMeta::new_readonly(stake_pool_accounts.pool_mint.pubkey(), false), AccountMeta::new_readonly(stake_pool_accounts.pool_fee_account.pubkey(), false), AccountMeta::new_readonly(sysvar::clock::id(), false), @@ -690,9 +689,9 @@ async fn test_initialize_stake_pool_without_owner_signature() { ), system_instruction::create_account( &payer.pubkey(), - &stake_pool_accounts.validator_stake_list.pubkey(), - rent_validator_stake_list, - validator_stake_list_size as u64, + &stake_pool_accounts.validator_list.pubkey(), + rent_validator_list, + validator_list_size as u64, &id(), ), stake_pool_init_instruction, @@ -703,7 +702,7 @@ async fn test_initialize_stake_pool_without_owner_signature() { &[ &payer, &stake_pool_accounts.stake_pool, - &stake_pool_accounts.validator_stake_list, + &stake_pool_accounts.validator_list, ], recent_blockhash, ); diff --git a/stake-pool/program/tests/update_pool_balance.rs b/stake-pool/program/tests/update_stake_pool_balance.rs similarity index 85% rename from stake-pool/program/tests/update_pool_balance.rs rename to stake-pool/program/tests/update_stake_pool_balance.rs index 1a1a2f6d..2fb1790a 100644 --- a/stake-pool/program/tests/update_pool_balance.rs +++ b/stake-pool/program/tests/update_stake_pool_balance.rs @@ -13,7 +13,7 @@ use { }; #[tokio::test] -async fn test_update_pool_balance() { +async fn test_update_stake_pool_balance() { let (mut banks_client, payer, recent_blockhash) = program_test().start().await; let stake_pool_accounts = StakePoolAccounts::new(); stake_pool_accounts @@ -25,7 +25,7 @@ async fn test_update_pool_balance() { } #[tokio::test] -async fn test_update_pool_balance_with_wrong_validator_stake_list() { +async fn test_update_stake_pool_balance_with_wrong_validator_list() { let (mut banks_client, payer, recent_blockhash) = program_test().start().await; let stake_pool_accounts = StakePoolAccounts::new(); stake_pool_accounts @@ -35,7 +35,7 @@ async fn test_update_pool_balance_with_wrong_validator_stake_list() { let wrong_stake_list_storage = Keypair::new(); let mut transaction = Transaction::new_with_payer( - &[instruction::update_pool_balance( + &[instruction::update_stake_pool_balance( &id(), &stake_pool_accounts.stake_pool.pubkey(), &wrong_stake_list_storage.pubkey(), @@ -64,7 +64,7 @@ async fn test_update_pool_balance_with_wrong_validator_stake_list() { } #[tokio::test] -async fn test_update_pool_balance_with_uninitialized_validator_stake_list() {} // TODO +async fn test_update_stake_pool_balance_with_uninitialized_validator_list() {} // TODO #[tokio::test] -async fn test_update_pool_balance_with_out_of_dated_validators_balances() {} // TODO +async fn test_update_stake_pool_balance_with_out_of_dated_validators_balances() {} // TODO diff --git a/stake-pool/program/tests/update_list_balance.rs b/stake-pool/program/tests/update_validator_list_balance.rs similarity index 76% rename from stake-pool/program/tests/update_list_balance.rs rename to stake-pool/program/tests/update_validator_list_balance.rs index 56b75db8..ecbca99f 100644 --- a/stake-pool/program/tests/update_list_balance.rs +++ b/stake-pool/program/tests/update_validator_list_balance.rs @@ -11,17 +11,16 @@ use { spl_stake_pool::{borsh::try_from_slice_unchecked, stake, state}, }; -async fn get_list_sum(banks_client: &mut BanksClient, validator_stake_list_key: &Pubkey) -> u64 { - let validator_stake_list = banks_client - .get_account(*validator_stake_list_key) +async fn get_list_sum(banks_client: &mut BanksClient, validator_list_key: &Pubkey) -> u64 { + let validator_list = banks_client + .get_account(*validator_list_key) .await .expect("get_account") .expect("validator stake list not none"); - let validator_stake_list = - try_from_slice_unchecked::(validator_stake_list.data.as_slice()) - .unwrap(); + let validator_list = + try_from_slice_unchecked::(validator_list.data.as_slice()).unwrap(); - validator_stake_list + validator_list .validators .iter() .map(|info| info.balance) @@ -29,7 +28,7 @@ async fn get_list_sum(banks_client: &mut BanksClient, validator_stake_list_key: } #[tokio::test] -async fn test_update_list_balance() { +async fn test_update_validator_list_balance() { let (mut banks_client, payer, recent_blockhash) = program_test().start().await; let stake_pool_accounts = StakePoolAccounts::new(); stake_pool_accounts @@ -42,7 +41,7 @@ async fn test_update_list_balance() { const STAKE_ACCOUNTS: u64 = 3; for _ in 0..STAKE_ACCOUNTS { stake_accounts.push( - simple_add_validator_stake_account( + simple_add_validator_to_pool( &mut banks_client, &payer, &recent_blockhash, @@ -74,7 +73,7 @@ async fn test_update_list_balance() { assert_eq!( get_list_sum( &mut banks_client, - &stake_pool_accounts.validator_stake_list.pubkey() + &stake_pool_accounts.validator_list.pubkey() ) .await, STAKE_ACCOUNTS * (stake_rent + TEST_STAKE_AMOUNT) @@ -84,7 +83,7 @@ async fn test_update_list_balance() { } #[tokio::test] -async fn test_update_list_balance_with_uninitialized_validator_stake_list() {} // TODO +async fn test_update_validator_list_balance_with_uninitialized_validator_list() {} // TODO #[tokio::test] -async fn test_update_list_balance_with_wrong_stake_state() {} // TODO +async fn test_update_validator_list_balance_with_wrong_stake_state() {} // TODO diff --git a/stake-pool/program/tests/vsa_add.rs b/stake-pool/program/tests/vsa_add.rs index 26c9dcd7..048f0ef1 100644 --- a/stake-pool/program/tests/vsa_add.rs +++ b/stake-pool/program/tests/vsa_add.rs @@ -70,7 +70,7 @@ async fn setup() -> ( } #[tokio::test] -async fn test_add_validator_stake_account() { +async fn test_add_validator_to_pool() { let ( mut banks_client, payer, @@ -81,7 +81,7 @@ async fn test_add_validator_stake_account() { ) = setup().await; let error = stake_pool_accounts - .add_validator_stake_account( + .add_validator_to_pool( &mut banks_client, &payer, &recent_blockhash, @@ -109,18 +109,17 @@ async fn test_add_validator_stake_account() { assert_eq!(pool_fee_token_balance, 0); // No fee when adding validator stake accounts // Check if validator account was added to the list - let validator_stake_list = get_account( + let validator_list = get_account( &mut banks_client, - &stake_pool_accounts.validator_stake_list.pubkey(), + &stake_pool_accounts.validator_list.pubkey(), ) .await; - let validator_stake_list = - try_from_slice_unchecked::(validator_stake_list.data.as_slice()) - .unwrap(); + let validator_list = + try_from_slice_unchecked::(validator_list.data.as_slice()).unwrap(); assert_eq!( - validator_stake_list, - state::ValidatorStakeList { - account_type: state::AccountType::ValidatorStakeList, + validator_list, + state::ValidatorList { + account_type: state::AccountType::ValidatorList, max_validators: stake_pool_accounts.max_validators, validators: vec![state::ValidatorStakeInfo { validator_account: user_stake.vote.pubkey(), @@ -149,7 +148,7 @@ async fn test_add_validator_stake_account() { } #[tokio::test] -async fn test_add_validator_stake_account_with_wrong_token_program_id() { +async fn test_add_validator_to_pool_with_wrong_token_program_id() { let ( mut banks_client, payer, @@ -160,13 +159,13 @@ async fn test_add_validator_stake_account_with_wrong_token_program_id() { ) = setup().await; let mut transaction = Transaction::new_with_payer( - &[instruction::add_validator_stake_account( + &[instruction::add_validator_to_pool( &id(), &stake_pool_accounts.stake_pool.pubkey(), &stake_pool_accounts.owner.pubkey(), &stake_pool_accounts.deposit_authority, &stake_pool_accounts.withdraw_authority, - &stake_pool_accounts.validator_stake_list.pubkey(), + &stake_pool_accounts.validator_list.pubkey(), &user_stake.stake_account, &user_pool_account.pubkey(), &stake_pool_accounts.pool_mint.pubkey(), @@ -192,7 +191,7 @@ async fn test_add_validator_stake_account_with_wrong_token_program_id() { } #[tokio::test] -async fn test_add_validator_stake_account_with_wrong_pool_mint_account() { +async fn test_add_validator_to_pool_with_wrong_pool_mint_account() { let ( mut banks_client, payer, @@ -205,13 +204,13 @@ async fn test_add_validator_stake_account_with_wrong_pool_mint_account() { let wrong_pool_mint = Keypair::new(); let mut transaction = Transaction::new_with_payer( - &[instruction::add_validator_stake_account( + &[instruction::add_validator_to_pool( &id(), &stake_pool_accounts.stake_pool.pubkey(), &stake_pool_accounts.owner.pubkey(), &stake_pool_accounts.deposit_authority, &stake_pool_accounts.withdraw_authority, - &stake_pool_accounts.validator_stake_list.pubkey(), + &stake_pool_accounts.validator_list.pubkey(), &user_stake.stake_account, &user_pool_account.pubkey(), &wrong_pool_mint.pubkey(), @@ -241,7 +240,7 @@ async fn test_add_validator_stake_account_with_wrong_pool_mint_account() { } #[tokio::test] -async fn test_add_validator_stake_account_with_wrong_validator_stake_list_account() { +async fn test_add_validator_to_pool_with_wrong_validator_list_account() { let ( mut banks_client, payer, @@ -251,16 +250,16 @@ async fn test_add_validator_stake_account_with_wrong_validator_stake_list_accoun user_pool_account, ) = setup().await; - let wrong_validator_stake_list = Keypair::new(); + let wrong_validator_list = Keypair::new(); let mut transaction = Transaction::new_with_payer( - &[instruction::add_validator_stake_account( + &[instruction::add_validator_to_pool( &id(), &stake_pool_accounts.stake_pool.pubkey(), &stake_pool_accounts.owner.pubkey(), &stake_pool_accounts.deposit_authority, &stake_pool_accounts.withdraw_authority, - &wrong_validator_stake_list.pubkey(), + &wrong_validator_list.pubkey(), &user_stake.stake_account, &user_pool_account.pubkey(), &stake_pool_accounts.pool_mint.pubkey(), @@ -301,7 +300,7 @@ async fn test_try_to_add_already_added_validator_stake_account() { ) = setup().await; stake_pool_accounts - .add_validator_stake_account( + .add_validator_to_pool( &mut banks_client, &payer, &recent_blockhash, @@ -313,7 +312,7 @@ async fn test_try_to_add_already_added_validator_stake_account() { let latest_blockhash = banks_client.get_recent_blockhash().await.unwrap(); let transaction_error = stake_pool_accounts - .add_validator_stake_account( + .add_validator_to_pool( &mut banks_client, &payer, &latest_blockhash, @@ -336,7 +335,7 @@ async fn test_try_to_add_already_added_validator_stake_account() { } #[tokio::test] -async fn test_not_owner_try_to_add_validator_stake_account() { +async fn test_not_owner_try_to_add_validator_to_pool() { let ( mut banks_client, payer, @@ -349,13 +348,13 @@ async fn test_not_owner_try_to_add_validator_stake_account() { let malicious = Keypair::new(); let mut transaction = Transaction::new_with_payer( - &[instruction::add_validator_stake_account( + &[instruction::add_validator_to_pool( &id(), &stake_pool_accounts.stake_pool.pubkey(), &malicious.pubkey(), &stake_pool_accounts.deposit_authority, &stake_pool_accounts.withdraw_authority, - &stake_pool_accounts.validator_stake_list.pubkey(), + &stake_pool_accounts.validator_list.pubkey(), &user_stake.stake_account, &user_pool_account.pubkey(), &stake_pool_accounts.pool_mint.pubkey(), @@ -385,7 +384,7 @@ async fn test_not_owner_try_to_add_validator_stake_account() { } #[tokio::test] -async fn test_not_owner_try_to_add_validator_stake_account_without_signature() { +async fn test_not_owner_try_to_add_validator_to_pool_without_signature() { let ( mut banks_client, payer, @@ -400,7 +399,7 @@ async fn test_not_owner_try_to_add_validator_stake_account_without_signature() { AccountMeta::new_readonly(stake_pool_accounts.owner.pubkey(), false), AccountMeta::new_readonly(stake_pool_accounts.deposit_authority, false), AccountMeta::new_readonly(stake_pool_accounts.withdraw_authority, false), - AccountMeta::new(stake_pool_accounts.validator_stake_list.pubkey(), false), + AccountMeta::new(stake_pool_accounts.validator_list.pubkey(), false), AccountMeta::new(user_stake.stake_account, false), AccountMeta::new(user_pool_account.pubkey(), false), AccountMeta::new(stake_pool_accounts.pool_mint.pubkey(), false), @@ -412,7 +411,7 @@ async fn test_not_owner_try_to_add_validator_stake_account_without_signature() { let instruction = Instruction { program_id: id(), accounts, - data: instruction::StakePoolInstruction::AddValidatorStakeAccount + data: instruction::StakePoolInstruction::AddValidatorToPool .try_to_vec() .unwrap(), }; @@ -438,7 +437,7 @@ async fn test_not_owner_try_to_add_validator_stake_account_without_signature() { } #[tokio::test] -async fn test_add_validator_stake_account_when_stake_acc_not_in_stake_state() { +async fn test_add_validator_to_pool_when_stake_acc_not_in_stake_state() { let (mut banks_client, payer, recent_blockhash) = program_test().start().await; let stake_pool_accounts = StakePoolAccounts::new(); stake_pool_accounts @@ -478,7 +477,7 @@ async fn test_add_validator_stake_account_when_stake_acc_not_in_stake_state() { .unwrap(); let transaction_error = stake_pool_accounts - .add_validator_stake_account( + .add_validator_to_pool( &mut banks_client, &payer, &recent_blockhash, @@ -501,7 +500,7 @@ async fn test_add_validator_stake_account_when_stake_acc_not_in_stake_state() { } #[tokio::test] -async fn test_add_validator_stake_account_with_wrong_stake_program_id() { +async fn test_add_validator_to_pool_with_wrong_stake_program_id() { let ( mut banks_client, payer, @@ -514,13 +513,13 @@ async fn test_add_validator_stake_account_with_wrong_stake_program_id() { let wrong_stake_program = Keypair::new(); let mut transaction = Transaction::new_with_payer( - &[instruction::add_validator_stake_account( + &[instruction::add_validator_to_pool( &id(), &stake_pool_accounts.stake_pool.pubkey(), &stake_pool_accounts.owner.pubkey(), &stake_pool_accounts.deposit_authority, &stake_pool_accounts.withdraw_authority, - &stake_pool_accounts.validator_stake_list.pubkey(), + &stake_pool_accounts.validator_list.pubkey(), &user_stake.stake_account, &user_pool_account.pubkey(), &stake_pool_accounts.pool_mint.pubkey(), @@ -581,7 +580,7 @@ async fn test_add_too_many_validator_stake_accounts() { .unwrap(); let error = stake_pool_accounts - .add_validator_stake_account( + .add_validator_to_pool( &mut banks_client, &payer, &recent_blockhash, @@ -599,7 +598,7 @@ async fn test_add_too_many_validator_stake_accounts() { .create_and_delegate(&mut banks_client, &payer, &recent_blockhash) .await; let error = stake_pool_accounts - .add_validator_stake_account( + .add_validator_to_pool( &mut banks_client, &payer, &recent_blockhash, @@ -616,7 +615,7 @@ async fn test_add_too_many_validator_stake_accounts() { } #[tokio::test] -async fn test_add_validator_stake_account_to_unupdated_stake_pool() {} // TODO +async fn test_add_validator_to_pool_to_unupdated_stake_pool() {} // TODO #[tokio::test] -async fn test_add_validator_stake_account_with_uninitialized_validator_stake_list_account() {} // TODO +async fn test_add_validator_to_pool_with_uninitialized_validator_list_account() {} // TODO diff --git a/stake-pool/program/tests/vsa_remove.rs b/stake-pool/program/tests/vsa_remove.rs index 4be8f507..8cc29eda 100644 --- a/stake-pool/program/tests/vsa_remove.rs +++ b/stake-pool/program/tests/vsa_remove.rs @@ -62,7 +62,7 @@ async fn setup() -> ( .unwrap(); let error = stake_pool_accounts - .add_validator_stake_account( + .add_validator_to_pool( &mut banks_client, &payer, &recent_blockhash, @@ -84,7 +84,7 @@ async fn setup() -> ( } #[tokio::test] -async fn test_remove_validator_stake_account() { +async fn test_remove_validator_from_pool() { let ( mut banks_client, payer, @@ -109,7 +109,7 @@ async fn test_remove_validator_stake_account() { let new_authority = Pubkey::new_unique(); let error = stake_pool_accounts - .remove_validator_stake_account( + .remove_validator_from_pool( &mut banks_client, &payer, &recent_blockhash, @@ -125,18 +125,17 @@ async fn test_remove_validator_stake_account() { assert_eq!(tokens_left, 0); // Check if account was removed from the list of stake accounts - let validator_stake_list = get_account( + let validator_list = get_account( &mut banks_client, - &stake_pool_accounts.validator_stake_list.pubkey(), + &stake_pool_accounts.validator_list.pubkey(), ) .await; - let validator_stake_list = - try_from_slice_unchecked::(validator_stake_list.data.as_slice()) - .unwrap(); + let validator_list = + try_from_slice_unchecked::(validator_list.data.as_slice()).unwrap(); assert_eq!( - validator_stake_list, - state::ValidatorStakeList { - account_type: state::AccountType::ValidatorStakeList, + validator_list, + state::ValidatorList { + account_type: state::AccountType::ValidatorList, max_validators: stake_pool_accounts.max_validators, validators: vec![] } @@ -155,7 +154,7 @@ async fn test_remove_validator_stake_account() { } #[tokio::test] -async fn test_remove_validator_stake_account_with_wrong_stake_program_id() { +async fn test_remove_validator_from_pool_with_wrong_stake_program_id() { let ( mut banks_client, payer, @@ -170,13 +169,13 @@ async fn test_remove_validator_stake_account_with_wrong_stake_program_id() { let new_authority = Pubkey::new_unique(); let mut transaction = Transaction::new_with_payer( - &[instruction::remove_validator_stake_account( + &[instruction::remove_validator_from_pool( &id(), &stake_pool_accounts.stake_pool.pubkey(), &stake_pool_accounts.owner.pubkey(), &stake_pool_accounts.withdraw_authority, &new_authority, - &stake_pool_accounts.validator_stake_list.pubkey(), + &stake_pool_accounts.validator_list.pubkey(), &user_stake.stake_account, &user_pool_account.pubkey(), &stake_pool_accounts.pool_mint.pubkey(), @@ -205,7 +204,7 @@ async fn test_remove_validator_stake_account_with_wrong_stake_program_id() { } #[tokio::test] -async fn test_remove_validator_stake_account_with_wrong_token_program_id() { +async fn test_remove_validator_from_pool_with_wrong_token_program_id() { let ( mut banks_client, payer, @@ -220,13 +219,13 @@ async fn test_remove_validator_stake_account_with_wrong_token_program_id() { let new_authority = Pubkey::new_unique(); let mut transaction = Transaction::new_with_payer( - &[instruction::remove_validator_stake_account( + &[instruction::remove_validator_from_pool( &id(), &stake_pool_accounts.stake_pool.pubkey(), &stake_pool_accounts.owner.pubkey(), &stake_pool_accounts.withdraw_authority, &new_authority, - &stake_pool_accounts.validator_stake_list.pubkey(), + &stake_pool_accounts.validator_list.pubkey(), &user_stake.stake_account, &user_pool_account.pubkey(), &stake_pool_accounts.pool_mint.pubkey(), @@ -252,7 +251,7 @@ async fn test_remove_validator_stake_account_with_wrong_token_program_id() { } #[tokio::test] -async fn test_remove_validator_stake_account_with_wrong_pool_mint_account() { +async fn test_remove_validator_from_pool_with_wrong_pool_mint_account() { let ( mut banks_client, payer, @@ -267,13 +266,13 @@ async fn test_remove_validator_stake_account_with_wrong_pool_mint_account() { let new_authority = Pubkey::new_unique(); let mut transaction = Transaction::new_with_payer( - &[instruction::remove_validator_stake_account( + &[instruction::remove_validator_from_pool( &id(), &stake_pool_accounts.stake_pool.pubkey(), &stake_pool_accounts.owner.pubkey(), &stake_pool_accounts.withdraw_authority, &new_authority, - &stake_pool_accounts.validator_stake_list.pubkey(), + &stake_pool_accounts.validator_list.pubkey(), &user_stake.stake_account, &user_pool_account.pubkey(), &wrong_pool_mint.pubkey(), @@ -303,7 +302,7 @@ async fn test_remove_validator_stake_account_with_wrong_pool_mint_account() { } #[tokio::test] -async fn test_remove_validator_stake_account_with_wrong_validator_stake_list_account() { +async fn test_remove_validator_from_pool_with_wrong_validator_list_account() { let ( mut banks_client, payer, @@ -314,17 +313,17 @@ async fn test_remove_validator_stake_account_with_wrong_validator_stake_list_acc _, ) = setup().await; - let wrong_validator_stake_list = Keypair::new(); + let wrong_validator_list = Keypair::new(); let new_authority = Pubkey::new_unique(); let mut transaction = Transaction::new_with_payer( - &[instruction::remove_validator_stake_account( + &[instruction::remove_validator_from_pool( &id(), &stake_pool_accounts.stake_pool.pubkey(), &stake_pool_accounts.owner.pubkey(), &stake_pool_accounts.withdraw_authority, &new_authority, - &wrong_validator_stake_list.pubkey(), + &wrong_validator_list.pubkey(), &user_stake.stake_account, &user_pool_account.pubkey(), &stake_pool_accounts.pool_mint.pubkey(), @@ -379,7 +378,7 @@ async fn test_remove_already_removed_validator_stake_account() { let new_authority = Pubkey::new_unique(); let error = stake_pool_accounts - .remove_validator_stake_account( + .remove_validator_from_pool( &mut banks_client, &payer, &recent_blockhash, @@ -393,7 +392,7 @@ async fn test_remove_already_removed_validator_stake_account() { let latest_blockhash = banks_client.get_recent_blockhash().await.unwrap(); let transaction_error = stake_pool_accounts - .remove_validator_stake_account( + .remove_validator_from_pool( &mut banks_client, &payer, &latest_blockhash, @@ -419,7 +418,7 @@ async fn test_remove_already_removed_validator_stake_account() { } #[tokio::test] -async fn test_not_owner_try_to_remove_validator_stake_account() { +async fn test_not_owner_try_to_remove_validator_from_pool() { let ( mut banks_client, payer, @@ -434,13 +433,13 @@ async fn test_not_owner_try_to_remove_validator_stake_account() { let new_authority = Pubkey::new_unique(); let mut transaction = Transaction::new_with_payer( - &[instruction::remove_validator_stake_account( + &[instruction::remove_validator_from_pool( &id(), &stake_pool_accounts.stake_pool.pubkey(), &malicious.pubkey(), &stake_pool_accounts.withdraw_authority, &new_authority, - &stake_pool_accounts.validator_stake_list.pubkey(), + &stake_pool_accounts.validator_list.pubkey(), &user_stake.stake_account, &user_pool_account.pubkey(), &stake_pool_accounts.pool_mint.pubkey(), @@ -470,7 +469,7 @@ async fn test_not_owner_try_to_remove_validator_stake_account() { } #[tokio::test] -async fn test_not_owner_try_to_remove_validator_stake_account_without_signature() { +async fn test_not_owner_try_to_remove_validator_from_pool_without_signature() { let ( mut banks_client, payer, @@ -488,7 +487,7 @@ async fn test_not_owner_try_to_remove_validator_stake_account_without_signature( AccountMeta::new_readonly(stake_pool_accounts.owner.pubkey(), false), AccountMeta::new_readonly(stake_pool_accounts.withdraw_authority, false), AccountMeta::new_readonly(new_authority, false), - AccountMeta::new(stake_pool_accounts.validator_stake_list.pubkey(), false), + AccountMeta::new(stake_pool_accounts.validator_list.pubkey(), false), AccountMeta::new(user_stake.stake_account, false), AccountMeta::new(user_pool_account.pubkey(), false), AccountMeta::new(stake_pool_accounts.pool_mint.pubkey(), false), @@ -499,7 +498,7 @@ async fn test_not_owner_try_to_remove_validator_stake_account_without_signature( let instruction = Instruction { program_id: id(), accounts, - data: instruction::StakePoolInstruction::RemoveValidatorStakeAccount + data: instruction::StakePoolInstruction::RemoveValidatorFromPool .try_to_vec() .unwrap(), }; @@ -525,7 +524,7 @@ async fn test_not_owner_try_to_remove_validator_stake_account_without_signature( } #[tokio::test] -async fn test_remove_validator_stake_account_when_stake_acc_not_in_stake_state() { +async fn test_remove_validator_from_pool_when_stake_acc_not_in_stake_state() { let (mut banks_client, payer, recent_blockhash) = program_test().start().await; let stake_pool_accounts = StakePoolAccounts::new(); stake_pool_accounts @@ -567,7 +566,7 @@ async fn test_remove_validator_stake_account_when_stake_acc_not_in_stake_state() let new_authority = Pubkey::new_unique(); let transaction_error = stake_pool_accounts - .remove_validator_stake_account( + .remove_validator_from_pool( &mut banks_client, &payer, &recent_blockhash, @@ -591,7 +590,7 @@ async fn test_remove_validator_stake_account_when_stake_acc_not_in_stake_state() } #[tokio::test] -async fn test_remove_validator_stake_account_from_unupdated_stake_pool() {} // TODO +async fn test_remove_validator_from_pool_from_unupdated_stake_pool() {} // TODO #[tokio::test] -async fn test_remove_validator_stake_account_with_uninitialized_validator_stake_list_account() {} // TODO +async fn test_remove_validator_from_pool_with_uninitialized_validator_list_account() {} // TODO diff --git a/stake-pool/program/tests/withdraw.rs b/stake-pool/program/tests/withdraw.rs index 5fc52390..c5e73777 100644 --- a/stake-pool/program/tests/withdraw.rs +++ b/stake-pool/program/tests/withdraw.rs @@ -34,7 +34,7 @@ async fn setup() -> ( .await .unwrap(); - let validator_stake_account: ValidatorStakeAccount = simple_add_validator_stake_account( + let validator_stake_account: ValidatorStakeAccount = simple_add_validator_to_pool( &mut banks_client, &payer, &recent_blockhash, @@ -105,15 +105,14 @@ async fn test_stake_pool_withdraw() { state::StakePool::try_from_slice(&stake_pool_before.data.as_slice()).unwrap(); // Save validator stake account record before withdrawal - let validator_stake_list = get_account( + let validator_list = get_account( &mut banks_client, - &stake_pool_accounts.validator_stake_list.pubkey(), + &stake_pool_accounts.validator_list.pubkey(), ) .await; - let validator_stake_list = - try_from_slice_unchecked::(validator_stake_list.data.as_slice()) - .unwrap(); - let validator_stake_item_before = validator_stake_list + let validator_list = + try_from_slice_unchecked::(validator_list.data.as_slice()).unwrap(); + let validator_stake_item_before = validator_list .find(&validator_stake_account.vote.pubkey()) .unwrap(); @@ -149,15 +148,14 @@ async fn test_stake_pool_withdraw() { ); // Check validator stake list storage - let validator_stake_list = get_account( + let validator_list = get_account( &mut banks_client, - &stake_pool_accounts.validator_stake_list.pubkey(), + &stake_pool_accounts.validator_list.pubkey(), ) .await; - let validator_stake_list = - try_from_slice_unchecked::(validator_stake_list.data.as_slice()) - .unwrap(); - let validator_stake_item = validator_stake_list + let validator_list = + try_from_slice_unchecked::(validator_list.data.as_slice()).unwrap(); + let validator_stake_item = validator_list .find(&validator_stake_account.vote.pubkey()) .unwrap(); assert_eq!( @@ -212,7 +210,7 @@ async fn test_stake_pool_withdraw_with_wrong_stake_program() { &[instruction::withdraw( &id(), &stake_pool_accounts.stake_pool.pubkey(), - &stake_pool_accounts.validator_stake_list.pubkey(), + &stake_pool_accounts.validator_list.pubkey(), &stake_pool_accounts.withdraw_authority, &validator_stake_account.stake_account, &user_stake_recipient.pubkey(), @@ -308,7 +306,7 @@ async fn test_stake_pool_withdraw_with_wrong_token_program_id() { &[instruction::withdraw( &id(), &stake_pool_accounts.stake_pool.pubkey(), - &stake_pool_accounts.validator_stake_list.pubkey(), + &stake_pool_accounts.validator_list.pubkey(), &stake_pool_accounts.withdraw_authority, &validator_stake_account.stake_account, &user_stake_recipient.pubkey(), @@ -338,7 +336,7 @@ async fn test_stake_pool_withdraw_with_wrong_token_program_id() { } #[tokio::test] -async fn test_stake_pool_withdraw_with_wrong_validator_stake_list() { +async fn test_stake_pool_withdraw_with_wrong_validator_list() { let ( mut banks_client, payer, @@ -353,7 +351,7 @@ async fn test_stake_pool_withdraw_with_wrong_validator_stake_list() { let user_stake_recipient = Keypair::new(); let new_authority = Pubkey::new_unique(); - stake_pool_accounts.validator_stake_list = Keypair::new(); + stake_pool_accounts.validator_list = Keypair::new(); let transaction_error = stake_pool_accounts .withdraw_stake( @@ -678,7 +676,7 @@ async fn test_stake_pool_withdraw_token_delegate_was_not_setup() { .await .unwrap(); - let validator_stake_account: ValidatorStakeAccount = simple_add_validator_stake_account( + let validator_stake_account: ValidatorStakeAccount = simple_add_validator_to_pool( &mut banks_client, &payer, &recent_blockhash, @@ -746,7 +744,7 @@ async fn test_stake_pool_withdraw_with_low_delegation() { .await .unwrap(); - let validator_stake_account: ValidatorStakeAccount = simple_add_validator_stake_account( + let validator_stake_account: ValidatorStakeAccount = simple_add_validator_to_pool( &mut banks_client, &payer, &recent_blockhash,