From d6869773bb9d8ba4b268f8dee41459c34decdbf4 Mon Sep 17 00:00:00 2001 From: Brooks Prumo Date: Mon, 25 Apr 2022 18:35:05 -0400 Subject: [PATCH] Make rpc test_account_subscribe aware of stake minimum delegation (#24659) --- programs/stake/src/lib.rs | 2 +- rpc/src/rpc_pubsub.rs | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/programs/stake/src/lib.rs b/programs/stake/src/lib.rs index 1041288fdb..a5731078aa 100644 --- a/programs/stake/src/lib.rs +++ b/programs/stake/src/lib.rs @@ -19,7 +19,7 @@ pub fn add_genesis_accounts(genesis_config: &mut GenesisConfig) -> u64 { /// NOTE: This is also used to calculate the minimum balance of a stake account, which is the /// rent exempt reserve _plus_ the minimum stake delegation. #[inline(always)] -pub(crate) fn get_minimum_delegation(_feature_set: &FeatureSet) -> u64 { +pub fn get_minimum_delegation(_feature_set: &FeatureSet) -> u64 { // If/when the minimum delegation amount is changed, the `feature_set` parameter will be used // to chose the correct value. And since the MINIMUM_STAKE_DELEGATION constant cannot be // removed, use it here as to not duplicate magic constants. diff --git a/rpc/src/rpc_pubsub.rs b/rpc/src/rpc_pubsub.rs index 143c36f4d3..f12ae086f2 100644 --- a/rpc/src/rpc_pubsub.rs +++ b/rpc/src/rpc_pubsub.rs @@ -607,7 +607,7 @@ mod tests { signature::{Keypair, Signer}, stake::{ self, instruction as stake_instruction, - state::{Authorized, Lockup, StakeAuthorize}, + state::{Authorized, Lockup, StakeAuthorize, StakeState}, }, system_instruction, system_program, system_transaction, transaction::{self, Transaction}, @@ -828,7 +828,7 @@ mod tests { genesis_config, mint_keypair: alice, .. - } = create_genesis_config(10_000); + } = create_genesis_config(10_000_000_000); let new_stake_authority = solana_sdk::pubkey::new_rand(); let stake_authority = Keypair::new(); @@ -872,16 +872,24 @@ mod tests { rpc_subscriptions.notify_slot(1, 0, 0); receiver2.recv(); - let tx = system_transaction::transfer(&alice, &from.pubkey(), 51, blockhash); - process_transaction_and_notify(&bank_forks, &tx, &rpc_subscriptions, 1).unwrap(); + let balance = { + let bank = bank_forks.read().unwrap().working_bank(); + let rent = &bank.rent_collector().rent; + let rent_exempt_reserve = rent.minimum_balance(StakeState::size_of()); + let minimum_delegation = + solana_stake_program::get_minimum_delegation(&bank.feature_set); + rent_exempt_reserve + minimum_delegation + }; + let tx = system_transaction::transfer(&alice, &from.pubkey(), balance, blockhash); + process_transaction_and_notify(&bank_forks, &tx, &rpc_subscriptions, 1).unwrap(); let authorized = Authorized::auto(&stake_authority.pubkey()); let ixs = stake_instruction::create_account( &from.pubkey(), &stake_account.pubkey(), &authorized, &Lockup::default(), - 51, + balance, ); let message = Message::new(&ixs, Some(&from.pubkey())); let tx = Transaction::new(&[&from, &stake_account], message, blockhash); @@ -904,7 +912,7 @@ mod tests { "context": { "slot": 1 }, "value": { "owner": stake_program_id.to_string(), - "lamports": 51, + "lamports": balance, "data": [base64::encode(expected_data), encoding], "executable": false, "rentEpoch": 0,