solana-labs / solana-program-library

A collection of Solana programs maintained by Solana Labs
https://solanalabs.com
Apache License 2.0
3.25k stars 1.95k forks source link

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

Open joncinque opened 4 months ago

joncinque commented 4 months ago

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.

zahratt82 commented 4 months ago

great

zahratt82 commented 4 months ago

great

lucky-gru commented 1 week ago

@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?

joncinque commented 1 week ago

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