stake-pool: Use `Pubkey::as_ref()` instead of `to_bytes()` (#4014)

This commit is contained in:
Jon Cinque 2023-02-01 15:39:44 +01:00 committed by GitHub
parent 3c02459f4d
commit ff58a068e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 38 deletions

View File

@ -372,8 +372,7 @@ impl Processor {
authority_type: &[u8], authority_type: &[u8],
bump_seed: u8, bump_seed: u8,
) -> Result<(), ProgramError> { ) -> Result<(), ProgramError> {
let authority_signature_seeds = let authority_signature_seeds = [stake_pool.as_ref(), authority_type, &[bump_seed]];
[&stake_pool.to_bytes()[..32], authority_type, &[bump_seed]];
let signers = &[&authority_signature_seeds[..]]; let signers = &[&authority_signature_seeds[..]];
let ix = stake::instruction::delegate_stake( let ix = stake::instruction::delegate_stake(
@ -405,8 +404,7 @@ impl Processor {
authority_type: &[u8], authority_type: &[u8],
bump_seed: u8, bump_seed: u8,
) -> Result<(), ProgramError> { ) -> Result<(), ProgramError> {
let authority_signature_seeds = let authority_signature_seeds = [stake_pool.as_ref(), authority_type, &[bump_seed]];
[&stake_pool.to_bytes()[..32], authority_type, &[bump_seed]];
let signers = &[&authority_signature_seeds[..]]; let signers = &[&authority_signature_seeds[..]];
let ix = stake::instruction::deactivate_stake(stake_info.key, authority_info.key); let ix = stake::instruction::deactivate_stake(stake_info.key, authority_info.key);
@ -424,8 +422,7 @@ impl Processor {
amount: u64, amount: u64,
split_stake: AccountInfo<'a>, split_stake: AccountInfo<'a>,
) -> Result<(), ProgramError> { ) -> Result<(), ProgramError> {
let me_bytes = stake_pool.to_bytes(); let authority_signature_seeds = [stake_pool.as_ref(), authority_type, &[bump_seed]];
let authority_signature_seeds = [&me_bytes[..32], authority_type, &[bump_seed]];
let signers = &[&authority_signature_seeds[..]]; let signers = &[&authority_signature_seeds[..]];
let split_instruction = let split_instruction =
@ -453,8 +450,7 @@ impl Processor {
stake_history: AccountInfo<'a>, stake_history: AccountInfo<'a>,
stake_program_info: AccountInfo<'a>, stake_program_info: AccountInfo<'a>,
) -> Result<(), ProgramError> { ) -> Result<(), ProgramError> {
let me_bytes = stake_pool.to_bytes(); let authority_signature_seeds = [stake_pool.as_ref(), authority_type, &[bump_seed]];
let authority_signature_seeds = [&me_bytes[..32], authority_type, &[bump_seed]];
let signers = &[&authority_signature_seeds[..]]; let signers = &[&authority_signature_seeds[..]];
let merge_instruction = let merge_instruction =
@ -526,8 +522,7 @@ impl Processor {
clock: AccountInfo<'a>, clock: AccountInfo<'a>,
stake_program_info: AccountInfo<'a>, stake_program_info: AccountInfo<'a>,
) -> Result<(), ProgramError> { ) -> Result<(), ProgramError> {
let me_bytes = stake_pool.to_bytes(); let authority_signature_seeds = [stake_pool.as_ref(), authority_type, &[bump_seed]];
let authority_signature_seeds = [&me_bytes[..32], authority_type, &[bump_seed]];
let signers = &[&authority_signature_seeds[..]]; let signers = &[&authority_signature_seeds[..]];
let authorize_instruction = stake::instruction::authorize( let authorize_instruction = stake::instruction::authorize(
@ -577,8 +572,7 @@ impl Processor {
stake_program_info: AccountInfo<'a>, stake_program_info: AccountInfo<'a>,
lamports: u64, lamports: u64,
) -> Result<(), ProgramError> { ) -> Result<(), ProgramError> {
let me_bytes = stake_pool.to_bytes(); let authority_signature_seeds = [stake_pool.as_ref(), authority_type, &[bump_seed]];
let authority_signature_seeds = [&me_bytes[..32], authority_type, &[bump_seed]];
let signers = &[&authority_signature_seeds[..]]; let signers = &[&authority_signature_seeds[..]];
let custodian_pubkey = None; let custodian_pubkey = None;
@ -616,8 +610,7 @@ impl Processor {
vote_account: AccountInfo<'a>, vote_account: AccountInfo<'a>,
stake_config: AccountInfo<'a>, stake_config: AccountInfo<'a>,
) -> Result<(), ProgramError> { ) -> Result<(), ProgramError> {
let me_bytes = stake_pool.to_bytes(); let authority_signature_seeds = [stake_pool.as_ref(), authority_type, &[bump_seed]];
let authority_signature_seeds = [&me_bytes[..32], authority_type, &[bump_seed]];
let signers = &[&authority_signature_seeds[..]]; let signers = &[&authority_signature_seeds[..]];
let redelegate_instruction = &stake::instruction::redelegate( let redelegate_instruction = &stake::instruction::redelegate(
@ -673,8 +666,7 @@ impl Processor {
bump_seed: u8, bump_seed: u8,
amount: u64, amount: u64,
) -> Result<(), ProgramError> { ) -> Result<(), ProgramError> {
let me_bytes = stake_pool.to_bytes(); let authority_signature_seeds = [stake_pool.as_ref(), authority_type, &[bump_seed]];
let authority_signature_seeds = [&me_bytes[..32], authority_type, &[bump_seed]];
let signers = &[&authority_signature_seeds[..]]; let signers = &[&authority_signature_seeds[..]];
let ix = spl_token_2022::instruction::mint_to( let ix = spl_token_2022::instruction::mint_to(
@ -1389,7 +1381,7 @@ impl Processor {
)?; )?;
let ephemeral_stake_account_signer_seeds: &[&[_]] = &[ let ephemeral_stake_account_signer_seeds: &[&[_]] = &[
EPHEMERAL_STAKE_SEED_PREFIX, EPHEMERAL_STAKE_SEED_PREFIX,
&stake_pool_info.key.to_bytes(), stake_pool_info.key.as_ref(),
&ephemeral_stake_seed.to_le_bytes(), &ephemeral_stake_seed.to_le_bytes(),
&[ephemeral_stake_bump_seed], &[ephemeral_stake_bump_seed],
]; ];
@ -1452,8 +1444,8 @@ impl Processor {
} else { } else {
let transient_stake_account_signer_seeds: &[&[_]] = &[ let transient_stake_account_signer_seeds: &[&[_]] = &[
TRANSIENT_STAKE_SEED_PREFIX, TRANSIENT_STAKE_SEED_PREFIX,
&vote_account_address.to_bytes(), vote_account_address.as_ref(),
&stake_pool_info.key.to_bytes(), stake_pool_info.key.as_ref(),
&transient_stake_seed.to_le_bytes(), &transient_stake_seed.to_le_bytes(),
&[transient_stake_bump_seed], &[transient_stake_bump_seed],
]; ];
@ -1664,7 +1656,7 @@ impl Processor {
)?; )?;
let ephemeral_stake_account_signer_seeds: &[&[_]] = &[ let ephemeral_stake_account_signer_seeds: &[&[_]] = &[
EPHEMERAL_STAKE_SEED_PREFIX, EPHEMERAL_STAKE_SEED_PREFIX,
&stake_pool_info.key.to_bytes(), stake_pool_info.key.as_ref(),
&ephemeral_stake_seed.to_le_bytes(), &ephemeral_stake_seed.to_le_bytes(),
&[ephemeral_stake_bump_seed], &[ephemeral_stake_bump_seed],
]; ];
@ -1730,8 +1722,8 @@ impl Processor {
// no transient stake, split // no transient stake, split
let transient_stake_account_signer_seeds: &[&[_]] = &[ let transient_stake_account_signer_seeds: &[&[_]] = &[
TRANSIENT_STAKE_SEED_PREFIX, TRANSIENT_STAKE_SEED_PREFIX,
&vote_account_address.to_bytes(), vote_account_address.as_ref(),
&stake_pool_info.key.to_bytes(), stake_pool_info.key.as_ref(),
&transient_stake_seed.to_le_bytes(), &transient_stake_seed.to_le_bytes(),
&[transient_stake_bump_seed], &[transient_stake_bump_seed],
]; ];
@ -1940,8 +1932,8 @@ impl Processor {
)?; )?;
let source_transient_stake_account_signer_seeds: &[&[_]] = &[ let source_transient_stake_account_signer_seeds: &[&[_]] = &[
TRANSIENT_STAKE_SEED_PREFIX, TRANSIENT_STAKE_SEED_PREFIX,
&vote_account_address.to_bytes(), vote_account_address.as_ref(),
&stake_pool_info.key.to_bytes(), stake_pool_info.key.as_ref(),
&source_transient_stake_seed.to_le_bytes(), &source_transient_stake_seed.to_le_bytes(),
&[source_transient_stake_bump_seed], &[source_transient_stake_bump_seed],
]; ];
@ -1973,7 +1965,7 @@ impl Processor {
)?; )?;
let ephemeral_stake_account_signer_seeds: &[&[_]] = &[ let ephemeral_stake_account_signer_seeds: &[&[_]] = &[
EPHEMERAL_STAKE_SEED_PREFIX, EPHEMERAL_STAKE_SEED_PREFIX,
&stake_pool_info.key.to_bytes(), stake_pool_info.key.as_ref(),
&ephemeral_stake_seed.to_le_bytes(), &ephemeral_stake_seed.to_le_bytes(),
&[ephemeral_stake_bump_seed], &[ephemeral_stake_bump_seed],
]; ];
@ -2076,8 +2068,8 @@ impl Processor {
)?; )?;
let destination_transient_stake_account_signer_seeds: &[&[_]] = &[ let destination_transient_stake_account_signer_seeds: &[&[_]] = &[
TRANSIENT_STAKE_SEED_PREFIX, TRANSIENT_STAKE_SEED_PREFIX,
&vote_account_address.to_bytes(), vote_account_address.as_ref(),
&stake_pool_info.key.to_bytes(), stake_pool_info.key.as_ref(),
&destination_transient_stake_seed.to_le_bytes(), &destination_transient_stake_seed.to_le_bytes(),
&[destination_transient_stake_bump_seed], &[destination_transient_stake_bump_seed],
]; ];
@ -3560,7 +3552,7 @@ impl Processor {
crate::find_withdraw_authority_program_address(program_id, stake_pool_info.key); crate::find_withdraw_authority_program_address(program_id, stake_pool_info.key);
let token_mint_authority_signer_seeds: &[&[_]] = &[ let token_mint_authority_signer_seeds: &[&[_]] = &[
&stake_pool_info.key.to_bytes()[..32], stake_pool_info.key.as_ref(),
AUTHORITY_WITHDRAW, AUTHORITY_WITHDRAW,
&[stake_withdraw_bump_seed], &[stake_withdraw_bump_seed],
]; ];
@ -3640,7 +3632,7 @@ impl Processor {
crate::find_withdraw_authority_program_address(program_id, stake_pool_info.key); crate::find_withdraw_authority_program_address(program_id, stake_pool_info.key);
let token_mint_authority_signer_seeds: &[&[_]] = &[ let token_mint_authority_signer_seeds: &[&[_]] = &[
&stake_pool_info.key.to_bytes()[..32], stake_pool_info.key.as_ref(),
AUTHORITY_WITHDRAW, AUTHORITY_WITHDRAW,
&[stake_withdraw_bump_seed], &[stake_withdraw_bump_seed],
]; ];

View File

@ -62,7 +62,7 @@ pub struct StakePool {
/// signed by this authority. If no deposit authority is specified, /// signed by this authority. If no deposit authority is specified,
/// then the stake pool will default to the result of: /// then the stake pool will default to the result of:
/// `Pubkey::find_program_address( /// `Pubkey::find_program_address(
/// &[&stake_pool_address.to_bytes()[..32], b"deposit"], /// &[&stake_pool_address.as_ref(), b"deposit"],
/// program_id, /// program_id,
/// )` /// )`
pub stake_deposit_authority: Pubkey, pub stake_deposit_authority: Pubkey,
@ -273,11 +273,7 @@ impl StakePool {
bump_seed: u8, bump_seed: u8,
) -> Result<(), ProgramError> { ) -> Result<(), ProgramError> {
let expected_address = Pubkey::create_program_address( let expected_address = Pubkey::create_program_address(
&[ &[stake_pool_address.as_ref(), authority_seed, &[bump_seed]],
&stake_pool_address.to_bytes()[..32],
authority_seed,
&[bump_seed],
],
program_id, program_id,
)?; )?;

View File

@ -2429,8 +2429,8 @@ pub fn add_stake_pool_account(
) { ) {
let mut stake_pool_bytes = stake_pool.try_to_vec().unwrap(); let mut stake_pool_bytes = stake_pool.try_to_vec().unwrap();
// more room for optionals // more room for optionals
stake_pool_bytes.extend_from_slice(&Pubkey::default().to_bytes()); stake_pool_bytes.extend_from_slice(Pubkey::default().as_ref());
stake_pool_bytes.extend_from_slice(&Pubkey::default().to_bytes()); stake_pool_bytes.extend_from_slice(Pubkey::default().as_ref());
let stake_pool_account = SolanaAccount::create( let stake_pool_account = SolanaAccount::create(
ACCOUNT_RENT_EXEMPTION, ACCOUNT_RENT_EXEMPTION,
stake_pool_bytes, stake_pool_bytes,

View File

@ -25,7 +25,7 @@ use {
// the test require so many helper accounts. // the test require so many helper accounts.
// 20k is also a very safe number for the current upper bound of the network. // 20k is also a very safe number for the current upper bound of the network.
const MAX_POOL_SIZE_WITH_REQUESTED_COMPUTE_UNITS: u32 = 20_000; const MAX_POOL_SIZE_WITH_REQUESTED_COMPUTE_UNITS: u32 = 20_000;
const MAX_POOL_SIZE: u32 = 3_000; const MAX_POOL_SIZE: u32 = 3_200;
const STAKE_AMOUNT: u64 = 200_000_000_000; const STAKE_AMOUNT: u64 = 200_000_000_000;
async fn setup( async fn setup(