From d74b8c8f0af6d7f4126faf6799690cbad58659af Mon Sep 17 00:00:00 2001 From: Jon Cinque Date: Tue, 23 Feb 2021 00:28:06 +0100 Subject: [PATCH] stake-pool-cli: Update RPC client per TODO (#1304) * 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 --- stake-pool/cli/src/main.rs | 17 +++++------------ stake-pool/program/Cargo.toml | 2 +- stake-pool/program/program-id.md | 2 +- stake-pool/program/src/error.rs | 18 +++++++++++++++--- stake-pool/program/src/instruction.rs | 17 ++++++++++------- stake-pool/program/src/lib.rs | 2 +- stake-pool/program/src/processor.rs | 1 - stake-pool/program/src/state.rs | 17 ++++++++--------- 8 files changed, 41 insertions(+), 35 deletions(-) diff --git a/stake-pool/cli/src/main.rs b/stake-pool/cli/src/main.rs index e537508ebf7894..3c4a3de720750a 100644 --- a/stake-pool/cli/src/main.rs +++ b/stake-pool/cli/src/main.rs @@ -53,7 +53,6 @@ struct Config { verbose: bool, owner: Box, fee_payer: Box, - commitment_config: CommitmentConfig, } type Error = Box; @@ -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 = vec![]; let mut signers = vec![config.fee_payer.as_ref(), config.owner.as_ref()]; @@ -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(), @@ -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)?; @@ -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(), } }; @@ -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(()) diff --git a/stake-pool/program/Cargo.toml b/stake-pool/program/Cargo.toml index 6783a5e4e1dc82..a2043751ead579 100644 --- a/stake-pool/program/Cargo.toml +++ b/stake-pool/program/Cargo.toml @@ -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] diff --git a/stake-pool/program/program-id.md b/stake-pool/program/program-id.md index eae20664478239..26d3f43474c82e 100644 --- a/stake-pool/program/program-id.md +++ b/stake-pool/program/program-id.md @@ -1 +1 @@ -STAKEPQQL1111111111111111111111111111111111 +poo1B9L9nR3CrcaziKVYVpRX6A9Y1LAXYasjjfCbApj diff --git a/stake-pool/program/src/error.rs b/stake-pool/program/src/error.rs index d2a34451227c22..7acc56a69c7357 100644 --- a/stake-pool/program/src/error.rs +++ b/stake-pool/program/src/error.rs @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/stake-pool/program/src/instruction.rs b/stake-pool/program/src/instruction.rs index 00c85ccf42411a..049c8abd920f4c 100644 --- a/stake-pool/program/src/instruction.rs +++ b/stake-pool/program/src/instruction.rs @@ -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 @@ -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 diff --git a/stake-pool/program/src/lib.rs b/stake-pool/program/src/lib.rs index 6f48ebb519705a..61a2a883b8f6c8 100644 --- a/stake-pool/program/src/lib.rs +++ b/stake-pool/program/src/lib.rs @@ -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"); diff --git a/stake-pool/program/src/processor.rs b/stake-pool/program/src/processor.rs index 448cc40ec5dc08..38c687ee46b902 100644 --- a/stake-pool/program/src/processor.rs +++ b/stake-pool/program/src/processor.rs @@ -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"), diff --git a/stake-pool/program/src/state.rs b/stake-pool/program/src/state.rs index 3c945223ced2d3..f96493bfa7b189 100644 --- a/stake-pool/program/src/state.rs +++ b/stake-pool/program/src/state.rs @@ -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)]