Skip to content

Commit

Permalink
stake-pool-cli: Update RPC client per TODO (solana-labs#1304)
Browse files Browse the repository at this point in the history
* Update deployed stake pool program id

* Add validator account takes 1 SOL instead of 1 lamport

* Fix "update" command for empty validator list

* Update dependencies

* Revert consequential changes

* Run cargo fmt

* Revert sdk

* Revert Cargo.lock
  • Loading branch information
joncinque authored Feb 22, 2021
1 parent d75fc58 commit d74b8c8
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 35 deletions.
17 changes: 5 additions & 12 deletions stake-pool/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ struct Config {
verbose: bool,
owner: Box<dyn Signer>,
fee_payer: Box<dyn Signer>,
commitment_config: CommitmentConfig,
}

type Error = Box<dyn std::error::Error>;
Expand Down Expand Up @@ -530,6 +529,7 @@ fn command_deposit(
// Calculate validator stake account address linked to the pool
let (validator_stake_account, _) =
PoolProcessor::find_stake_address_for_validator(&spl_stake_pool::id(), &validator, pool);
println!("Depositing into stake account {}", validator_stake_account);

let mut instructions: Vec<Instruction> = vec![];
let mut signers = vec![config.fee_payer.as_ref(), config.owner.as_ref()];
Expand Down Expand Up @@ -615,7 +615,7 @@ fn command_deposit(
fn command_list(config: &Config, pool: &Pubkey) -> CommandResult {
// Get stake pool state
let pool_data = config.rpc_client.get_account_data(&pool)?;
let pool_data: StakePool = StakePool::deserialize(pool_data.as_slice()).unwrap();
let pool_data = StakePool::deserialize(pool_data.as_slice()).unwrap();

let pool_withdraw_authority: Pubkey = PoolProcessor::authority_id(
&spl_stake_pool::id(),
Expand Down Expand Up @@ -645,7 +645,7 @@ fn command_list(config: &Config, pool: &Pubkey) -> CommandResult {
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 = StakePool::deserialize(pool_data.as_slice()).unwrap();
let pool_data = StakePool::deserialize(pool_data.as_slice()).unwrap();
let validator_stake_list_data = config
.rpc_client
.get_account_data(&pool_data.validator_stake_list)?;
Expand Down Expand Up @@ -1356,11 +1356,10 @@ fn main() {
let verbose = matches.is_present("verbose");

Config {
rpc_client: RpcClient::new(json_rpc_url),
rpc_client: RpcClient::new_with_commitment(json_rpc_url, CommitmentConfig::confirmed()),
verbose,
owner,
fee_payer,
commitment_config: CommitmentConfig::confirmed(),
}
};

Expand Down Expand Up @@ -1440,15 +1439,9 @@ fn main() {
}
.and_then(|transaction| {
if let Some(transaction) = transaction {
// TODO: Upgrade to solana-client 1.3 and
// `send_and_confirm_transaction_with_spinner_and_commitment()` with single
// confirmation by default for better UX
let signature = config
.rpc_client
.send_and_confirm_transaction_with_spinner_and_commitment(
&transaction,
config.commitment_config,
)?;
.send_and_confirm_transaction_with_spinner(&transaction)?;
println!("Signature: {}", signature);
}
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion stake-pool/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ bincode = "1.3.1"
[dev-dependencies]
solana-program-test = "1.5.6"
solana-sdk = "1.5.6"
solana-vote-program = "1.5.3"
solana-vote-program = "1.5.6"
tokio = { version = "0.3", features = ["macros"]}

[lib]
Expand Down
2 changes: 1 addition & 1 deletion stake-pool/program/program-id.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
STAKEPQQL1111111111111111111111111111111111
poo1B9L9nR3CrcaziKVYVpRX6A9Y1LAXYasjjfCbApj
18 changes: 15 additions & 3 deletions stake-pool/program/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use thiserror::Error;
/// Errors that may be returned by the StakePool program.
#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
pub enum StakePoolError {
// 0.
/// The account cannot be initialized because it is already being used.
#[error("AlreadyInUse")]
AlreadyInUse,
Expand All @@ -22,12 +23,11 @@ pub enum StakePoolError {
/// Stake pool fee > 1.
#[error("FeeTooHigh")]
FeeTooHigh,

// 5.
/// Token account is associated with the wrong mint.
#[error("WrongAccountMint")]
WrongAccountMint,
/// Account balance should be zero.
#[error("NonZeroBalance")]
NonZeroBalance,
/// Wrong pool owner account.
#[error("WrongOwner")]
WrongOwner,
Expand All @@ -37,9 +37,13 @@ pub enum StakePoolError {
/// Invalid validator stake list account.
#[error("InvalidValidatorStakeList")]
InvalidValidatorStakeList,

// 10.
/// Invalid owner fee account.
#[error("InvalidFeeAccount")]
InvalidFeeAccount,

// 10.
/// Specified pool mint account is wrong.
#[error("WrongPoolMint")]
WrongPoolMint,
Expand All @@ -52,9 +56,13 @@ pub enum StakePoolError {
/// Stake account voting for this validator already exists in the pool.
#[error("ValidatorAlreadyAdded")]
ValidatorAlreadyAdded,

// 15.
/// Stake account for this validator not found in the pool.
#[error("ValidatorNotFound")]
ValidatorNotFound,

// 15.
/// Stake account address not properly derived from the validator address.
#[error("InvalidStakeAccountAddress")]
InvalidStakeAccountAddress,
Expand All @@ -67,9 +75,13 @@ pub enum StakePoolError {
/// Validator stake account is not found in the list storage.
#[error("UnknownValidatorStakeAccount")]
UnknownValidatorStakeAccount,

// 20.
/// Wrong minting authority set for mint pool account
#[error("WrongMintingAuthority")]
WrongMintingAuthority,

// 20.
/// Account is not rent-exempt
#[error("AccountNotRentExempt")]
AccountNotRentExempt,
Expand Down
17 changes: 10 additions & 7 deletions stake-pool/program/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
#![allow(clippy::too_many_arguments)]

use solana_program::instruction::AccountMeta;
use solana_program::instruction::Instruction;
use solana_program::program_error::ProgramError;
use solana_program::pubkey::Pubkey;
use solana_program::sysvar;
use std::mem::size_of;
use {
solana_program::{
instruction::{AccountMeta, Instruction},
program_error::ProgramError,
pubkey::Pubkey,
sysvar,
},
std::mem::size_of,
};

/// Fee rate as a ratio
/// Fee is minted on deposit
Expand Down Expand Up @@ -89,7 +92,7 @@ pub enum StakePoolInstruction {
RemoveValidatorStakeAccount,

/// 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
Expand Down
2 changes: 1 addition & 1 deletion stake-pool/program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ pub mod entrypoint;
// Export current sdk types for downstream users building with a different sdk version
pub use solana_program;

solana_program::declare_id!("5QuBzCtUC6pHgFEQJ5d2qX7ktyyHba9HVXLQVUEiAf7d");
solana_program::declare_id!("poo1B9L9nR3CrcaziKVYVpRX6A9Y1LAXYasjjfCbApj");
1 change: 0 additions & 1 deletion stake-pool/program/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,6 @@ impl PrintProgramError for StakePoolError {
StakePoolError::CalculationFailure => msg!("Error: The calculation failed"),
StakePoolError::FeeTooHigh => msg!("Error: Stake pool fee > 1"),
StakePoolError::WrongAccountMint => msg!("Error: Token account is associated with the wrong mint"),
StakePoolError::NonZeroBalance => msg!("Error: Account balance should be zero"),
StakePoolError::WrongOwner => msg!("Error: Wrong pool owner account"),
StakePoolError::SignatureMissing => msg!("Error: Required signature is missing"),
StakePoolError::InvalidValidatorStakeList => msg!("Error: Invalid validator stake list account"),
Expand Down
17 changes: 8 additions & 9 deletions stake-pool/program/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
//! State transition types
use crate::error::StakePoolError;
use crate::instruction::Fee;
use crate::processor::Processor;
use core::convert::TryInto;
use solana_program::{
account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError,
pubkey::Pubkey,
use {
crate::{error::StakePoolError, instruction::Fee, processor::Processor},
solana_program::{
account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError,
pubkey::Pubkey,
},
std::convert::{TryFrom, TryInto},
std::mem::size_of,
};
use std::convert::TryFrom;
use std::mem::size_of;

/// Initialized program details.
#[repr(C)]
Expand Down

0 comments on commit d74b8c8

Please sign in to comment.