Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to get stake minimum delegation from RPC #24690

Closed
Tracked by #22559
brooksprumo opened this issue Apr 26, 2022 · 5 comments · Fixed by #25200 or #26638
Closed
Tracked by #22559

Add a way to get stake minimum delegation from RPC #24690

brooksprumo opened this issue Apr 26, 2022 · 5 comments · Fixed by #25200 or #26638
Assignees

Comments

@brooksprumo
Copy link
Contributor

brooksprumo commented Apr 26, 2022

Problem

From RPC, we cannot query the minimum stake delegation.

Proposed Solution

Add a new RPC endpoint.

We cannot use simulate_transaction() here, as it fails when loading accounts.

Previous proposed solution

How about an RpcClient helper under the hood that performs simulate_transaction and returns parsed return_data of type T? I think we're going to want something similar for spl_token::instruction::GetAccountDataSize

Originally posted by @CriesofCarrots in #24690 (comment)

Initial Description

how about moving this into solana-program, so we don’t need a new dep in ledger/
When it’s moved into solana-program, we could probably remove the FeatureSet as well (since that’s only available in solana-sdk) and instead just always use 1 SOL

Originally posted by @mvines in #24660 (comment)

@brooksprumo
Copy link
Contributor Author

@mvines There is already a get_minimum_delegation() in solana-program here:

pub fn get_minimum_delegation() -> Result<u64, ProgramError> {
let instruction = super::instruction::get_minimum_delegation();
crate::program::invoke_unchecked(&instruction, &[])?;
get_minimum_delegation_return_data()
}

Is that where you were thinking? Since Rust doesn't allow function overloading, is there a way we've handled similar conflicts in the past?

Also, I put the function in solana-stake-program because it is used in the implementation when the GetMinimumDelegation instruction is called/processed:

Ok(StakeInstruction::GetMinimumDelegation) => {
let feature_set = invoke_context.feature_set.as_ref();
if !feature_set.is_active(
&feature_set::add_get_minimum_delegation_instruction_to_stake_program::id(),
) {
// Retain previous behavior of always checking that the first account
// is a stake account until the feature is activated
let _ = get_stake_account()?;
return Err(InstructionError::InvalidInstructionData);
}
let minimum_delegation = crate::get_minimum_delegation(feature_set);

Is it still best to move the fn?

@mvines
Copy link
Member

mvines commented Apr 26, 2022

Ah, I see.

My initial comment was made from the perspective of an off-chain user who's looking through RpcClient, such as the solana-cli.

They don't really have a nice way to determine the minimum delegation currently -- downside of our decision to not use a Sysvar. Their current choices seem to be:

  1. Hardcode a value
  2. Try to create the stake account with whatever stake amount the user provided, and attempt to gracefully handle the error from transaction simulation (or worse case, see the transaction fail)
  3. Simulate a transaction with StakeInstruction::GetMinimumDelegation in it to retrieve the current minimum

@brooksprumo
Copy link
Contributor Author

I was wondering if I should add a command to the CLI to get the stake minimum delegation. Would that be useful in this case?

@mvines
Copy link
Member

mvines commented Apr 26, 2022

An RpcClient method that does this would certainly be useful to the cli internally, so we can add the appropriate error handling when the user tries to create a new stake or split a stake with less than the minimum (ie, choice 3!)

@CriesofCarrots
Copy link
Contributor

How about an RpcClient helper under the hood that performs simulate_transaction and returns parsed return_data of type T? I think we're going to want something similar for spl_token::instruction::GetAccountDataSize

@brooksprumo brooksprumo changed the title Move get_minimum_delegation() into solana-program Add a way to get minimum delegation from cli/rpc May 2, 2022
@brooksprumo brooksprumo changed the title Add a way to get minimum delegation from cli/rpc Add a way to get minimum delegation from RpcClient May 13, 2022
@brooksprumo brooksprumo changed the title Add a way to get minimum delegation from RpcClient Add a way to get stake minimum delegation from RpcClient May 13, 2022
@brooksprumo brooksprumo reopened this May 20, 2022
@brooksprumo brooksprumo changed the title Add a way to get stake minimum delegation from RpcClient Add a way to get stake minimum delegation from Rpc Jul 11, 2022
@brooksprumo brooksprumo changed the title Add a way to get stake minimum delegation from Rpc Add a way to get stake minimum delegation from RPC Jul 11, 2022
@mergify mergify bot closed this as completed in #26638 Jul 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment