solana-program-library icon indicating copy to clipboard operation
solana-program-library copied to clipboard

stake-pool: Add instruction creators that re-use existing seeds

Open joncinque opened this issue 1 year ago • 4 comments

Problem

The IncreaseAdditionalValidatorStake and DecreaseAdditionalValidatorStake instruction creators helpers that take the vote account require that you pass in the transient_stake_seed:

https://github.com/solana-labs/solana-program-library/blob/c9eb289de8bc52930c109e0fba128d08e4948352/stake-pool/program/src/instruction.rs#L1325-L1334

And

https://github.com/solana-labs/solana-program-library/blob/c9eb289de8bc52930c109e0fba128d08e4948352/stake-pool/program/src/instruction.rs#L1240-L1249

Since these instructions are usually meant to reuse an existing transient stake account, these instruction creators can be confusing.

Solution

Create a new variant of these creators, decrease_additional_validator_stake_with_list and increase_additional_validator_stake_with_list, which takes in the pool's ValidatorList, ie:

pub fn increase_additional_validator_stake_with_list(
    program_id: &Pubkey,
    stake_pool: &StakePool,
    validator_list: &ValidatorList,
    stake_pool_address: &Pubkey,
    vote_account_address: &Pubkey,
    lamports: u64,
    ephemeral_stake_seed: u64,
) -> Instruction {

From the validator list, it can figure out the seeds and be much easier to use.

joncinque avatar Feb 20 '24 23:02 joncinque

great

zahratt82 avatar Feb 22 '24 08:02 zahratt82

great

zahratt82 avatar Feb 23 '24 12:02 zahratt82

@joncinque increase_additional_validator_stake_with_vote uses &stake_pool.validator_list without having the validator list as an argument. IncreaseValidatorStake instruction requires a transient_stake_seed. so need to add another instruction that doesn't require a transient_stake_seed. I don't think it's your intent. Or that instruction can consume lists of transient_stake_seeds? Then, How can I get a transient_stake_seed from validators lists?

lucky-gru avatar Jun 28 '24 08:06 lucky-gru

I'm not sure I totally understand the comment, but the concept is that ValidatorList contains the validator stake seed and the transient stake seed for the given vote account address:

https://github.com/solana-labs/solana-program-library/blob/4d0c646d94f68b62ea9527e3e479397de0ae2c4c/stake-pool/program/src/state.rs#L708-L716

So increase_additional_validator_stake_with_list can just read those values for the given validator and pass them into increase_additional_validator_stake_with_vote

joncinque avatar Jun 28 '24 18:06 joncinque

So do we want to iterate through the validator lists and execute the DecreaseAdditionalValidatorStake / IncreaseAdditionalValidatorStake? Do we return an array of instructions?

Hrushi20 avatar Aug 04 '24 15:08 Hrushi20

@Hrushi20 it's only one instruction in this case, but you'll need to search through the ValidatorList to find the validator and use the transient stake seed stored there

joncinque avatar Aug 05 '24 14:08 joncinque