From 0a5ea3766ec0ad551960d686971c87ebe8fa96dc Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Thu, 27 Jun 2024 14:10:39 -0600 Subject: [PATCH 1/3] Remove rpc_deprecated_v1_18 --- rpc/src/rpc.rs | 36 ------------------------------------ rpc/src/rpc_service.rs | 6 +----- 2 files changed, 1 insertion(+), 41 deletions(-) diff --git a/rpc/src/rpc.rs b/rpc/src/rpc.rs index 4749be383b90c6..51c651b481aa71 100644 --- a/rpc/src/rpc.rs +++ b/rpc/src/rpc.rs @@ -4240,42 +4240,6 @@ fn rpc_perf_sample_from_perf_sample(slot: u64, sample: PerfSample) -> RpcPerfSam } } -pub mod rpc_deprecated_v1_18 { - use super::*; - #[rpc] - pub trait DeprecatedV1_18 { - type Metadata; - - // DEPRECATED - #[rpc(meta, name = "getStakeActivation")] - fn get_stake_activation( - &self, - meta: Self::Metadata, - pubkey_str: String, - config: Option, - ) -> Result; - } - - pub struct DeprecatedV1_18Impl; - impl DeprecatedV1_18 for DeprecatedV1_18Impl { - type Metadata = JsonRpcRequestProcessor; - - fn get_stake_activation( - &self, - meta: Self::Metadata, - pubkey_str: String, - config: Option, - ) -> Result { - debug!( - "get_stake_activation rpc request received: {:?}", - pubkey_str - ); - let pubkey = verify_pubkey(&pubkey_str)?; - meta.get_stake_activation(&pubkey, config) - } - } -} - const MAX_BASE58_SIZE: usize = 1683; // Golden, bump if PACKET_DATA_SIZE changes const MAX_BASE64_SIZE: usize = 1644; // Golden, bump if PACKET_DATA_SIZE changes fn decode_and_deserialize( diff --git a/rpc/src/rpc_service.rs b/rpc/src/rpc_service.rs index d22d21c0803d02..fed748d709472b 100644 --- a/rpc/src/rpc_service.rs +++ b/rpc/src/rpc_service.rs @@ -5,10 +5,7 @@ use { cluster_tpu_info::ClusterTpuInfo, max_slots::MaxSlots, optimistically_confirmed_bank_tracker::OptimisticallyConfirmedBank, - rpc::{ - rpc_accounts::*, rpc_accounts_scan::*, rpc_bank::*, rpc_deprecated_v1_18::*, - rpc_full::*, rpc_minimal::*, *, - }, + rpc::{rpc_accounts::*, rpc_accounts_scan::*, rpc_bank::*, rpc_full::*, rpc_minimal::*, *}, rpc_cache::LargestAccountsCache, rpc_health::*, }, @@ -506,7 +503,6 @@ impl JsonRpcService { io.extend_with(rpc_accounts::AccountsDataImpl.to_delegate()); io.extend_with(rpc_accounts_scan::AccountsScanImpl.to_delegate()); io.extend_with(rpc_full::FullImpl.to_delegate()); - io.extend_with(rpc_deprecated_v1_18::DeprecatedV1_18Impl.to_delegate()); } let request_middleware = RpcRequestMiddleware::new( From fc8f710f8799d4c1a69a42840ac3513c849f51f2 Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Thu, 27 Jun 2024 14:17:48 -0600 Subject: [PATCH 2/3] Update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 118edd898ca416..e99f93f85cfebe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,7 +25,7 @@ Release channels have their own copy of this changelog: confirmTransaction, getSignatureStatus, getSignatureConfirmation, getTotalSupply, getConfirmedSignaturesForAddress, getConfirmedBlock, getConfirmedBlocks, getConfirmedBlocksWithLimit, getConfirmedTransaction, getConfirmedSignaturesForAddress2, getRecentBlockhash, getFees, - getFeeCalculatorForBlockhash, getFeeRateGovernor, getSnapshotSlot + getFeeCalculatorForBlockhash, getFeeRateGovernor, getSnapshotSlot getStakeActivation * `--enable-rpc-obsolete_v1_7` flag removed * Changes * `central-scheduler` as default option for `--block-production-method` (#34891) From 8c7ac00f1c6dd8d8d7dfe27f187d93961fabdd1a Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Thu, 27 Jun 2024 13:55:33 -0600 Subject: [PATCH 3/3] Fixup redelegation test --- cli/tests/stake.rs | 113 +++++++++++++++++++++++---------------------- 1 file changed, 59 insertions(+), 54 deletions(-) diff --git a/cli/tests/stake.rs b/cli/tests/stake.rs index 217e073f1c3ada..92a4b1ef109535 100644 --- a/cli/tests/stake.rs +++ b/cli/tests/stake.rs @@ -12,8 +12,7 @@ use { solana_faucet::faucet::run_local_faucet, solana_rpc_client::rpc_client::RpcClient, solana_rpc_client_api::{ - request::DELINQUENT_VALIDATOR_SLOT_DISTANCE, - response::{RpcStakeActivation, StakeActivationState}, + request::DELINQUENT_VALIDATOR_SLOT_DISTANCE, response::StakeActivationState, }, solana_rpc_client_nonce_utils::blockhash_query::{self, BlockhashQuery}, solana_sdk::{ @@ -29,8 +28,9 @@ use { stake::{ self, instruction::LockupArgs, - state::{Lockup, StakeAuthorize, StakeStateV2}, + state::{Delegation, Lockup, StakeActivationStatus, StakeAuthorize, StakeStateV2}, }, + sysvar::stake_history, }, solana_streamer::socket::SocketAddrSpace, solana_test_validator::{TestValidator, TestValidatorGenesis}, @@ -163,6 +163,30 @@ fn test_stake_redelegation() { // wait for new epoch plus one additional slot for rewards payout wait_for_next_epoch_plus_n_slots(&rpc_client, 1); + let check_activation_status = |delegation: &Delegation, + expected_state: StakeActivationState, + expected_active_stake: u64| { + let stake_history_account = rpc_client.get_account(&stake_history::id()).unwrap(); + let stake_history = solana_sdk::account::from_account(&stake_history_account).unwrap(); + let current_epoch = rpc_client.get_epoch_info().unwrap().epoch; + let StakeActivationStatus { + effective, + activating, + deactivating, + } = delegation.stake_activating_and_deactivating(current_epoch, &stake_history, None); + let stake_activation_state = if deactivating > 0 { + StakeActivationState::Deactivating + } else if activating > 0 { + StakeActivationState::Activating + } else if effective > 0 { + StakeActivationState::Active + } else { + StakeActivationState::Inactive + }; + assert_eq!(stake_activation_state, expected_state); + assert_eq!(effective, expected_active_stake); + }; + // `stake_keypair` should now be delegated to `vote_keypair` and fully activated let stake_account = rpc_client.get_account(&stake_keypair.pubkey()).unwrap(); let stake_state: StakeStateV2 = stake_account.state().unwrap(); @@ -170,21 +194,16 @@ fn test_stake_redelegation() { let rent_exempt_reserve = match stake_state { StakeStateV2::Stake(meta, stake, _) => { assert_eq!(stake.delegation.voter_pubkey, vote_keypair.pubkey()); + check_activation_status( + &stake.delegation, + StakeActivationState::Active, + 50_000_000_000 - meta.rent_exempt_reserve, + ); meta.rent_exempt_reserve } _ => panic!("Unexpected stake state!"), }; - assert_eq!( - rpc_client - .get_stake_activation(stake_keypair.pubkey(), None) - .unwrap(), - RpcStakeActivation { - state: StakeActivationState::Active, - active: 50_000_000_000 - rent_exempt_reserve, - inactive: 0 - } - ); check_balance!(50_000_000_000, &rpc_client, &stake_keypair.pubkey()); let stake2_keypair = Keypair::new(); @@ -226,28 +245,24 @@ fn test_stake_redelegation() { process_command(&config).unwrap(); // `stake_keypair` should now be deactivating - assert_eq!( - rpc_client - .get_stake_activation(stake_keypair.pubkey(), None) - .unwrap(), - RpcStakeActivation { - state: StakeActivationState::Deactivating, - active: 50_000_000_000 - rent_exempt_reserve, - inactive: 0, - } + let stake_account = rpc_client.get_account(&stake_keypair.pubkey()).unwrap(); + let stake_state: StakeStateV2 = stake_account.state().unwrap(); + let StakeStateV2::Stake(_, stake, _) = stake_state else { + panic!() + }; + check_activation_status( + &stake.delegation, + StakeActivationState::Deactivating, + 50_000_000_000 - rent_exempt_reserve, ); // `stake_keypair2` should now be activating - assert_eq!( - rpc_client - .get_stake_activation(stake2_keypair.pubkey(), None) - .unwrap(), - RpcStakeActivation { - state: StakeActivationState::Activating, - active: 0, - inactive: 50_000_000_000 - rent_exempt_reserve, - } - ); + let stake_account = rpc_client.get_account(&stake2_keypair.pubkey()).unwrap(); + let stake_state: StakeStateV2 = stake_account.state().unwrap(); + let StakeStateV2::Stake(_, stake, _) = stake_state else { + panic!() + }; + check_activation_status(&stake.delegation, StakeActivationState::Activating, 0); // check that all the stake, save `rent_exempt_reserve`, have been moved from `stake_keypair` // to `stake2_keypair` @@ -258,38 +273,28 @@ fn test_stake_redelegation() { wait_for_next_epoch_plus_n_slots(&rpc_client, 1); // `stake_keypair` should now be deactivated - assert_eq!( - rpc_client - .get_stake_activation(stake_keypair.pubkey(), None) - .unwrap(), - RpcStakeActivation { - state: StakeActivationState::Inactive, - active: 0, - inactive: 0, - } - ); + let stake_account = rpc_client.get_account(&stake_keypair.pubkey()).unwrap(); + let stake_state: StakeStateV2 = stake_account.state().unwrap(); + let StakeStateV2::Stake(_, stake, _) = stake_state else { + panic!() + }; + check_activation_status(&stake.delegation, StakeActivationState::Inactive, 0); // `stake2_keypair` should now be delegated to `vote2_keypair` and fully activated let stake2_account = rpc_client.get_account(&stake2_keypair.pubkey()).unwrap(); let stake2_state: StakeStateV2 = stake2_account.state().unwrap(); match stake2_state { - StakeStateV2::Stake(_meta, stake, _) => { + StakeStateV2::Stake(meta, stake, _) => { assert_eq!(stake.delegation.voter_pubkey, vote2_keypair.pubkey()); + check_activation_status( + &stake.delegation, + StakeActivationState::Active, + 50_000_000_000 - meta.rent_exempt_reserve, + ); } _ => panic!("Unexpected stake2 state!"), }; - - assert_eq!( - rpc_client - .get_stake_activation(stake2_keypair.pubkey(), None) - .unwrap(), - RpcStakeActivation { - state: StakeActivationState::Active, - active: 50_000_000_000 - rent_exempt_reserve, - inactive: 0 - } - ); } #[test]