Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit fa35066

Browse files
stake: deprecate on chain warmup/cooldown rate and config (#32723)
* stake: deprecate on chain warmup/cooldown rate and config * Pr feedback: Deprecate since 1.16.7 Co-authored-by: Jon Cinque <[email protected]> --------- Co-authored-by: Jon Cinque <[email protected]>
1 parent 5c86f89 commit fa35066

File tree

26 files changed

+826
-358
lines changed

26 files changed

+826
-358
lines changed

account-decoder/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ extern crate serde_derive;
77
pub mod parse_account_data;
88
pub mod parse_address_lookup_table;
99
pub mod parse_bpf_loader;
10+
#[allow(deprecated)]
1011
pub mod parse_config;
1112
pub mod parse_nonce;
1213
pub mod parse_stake;

account-decoder/src/parse_config.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ use {
88
solana_config_program::{get_config_data, ConfigKeys},
99
solana_sdk::{
1010
pubkey::Pubkey,
11-
stake::config::{self as stake_config, Config as StakeConfig},
11+
stake::config::{
12+
Config as StakeConfig, {self as stake_config},
13+
},
1214
},
1315
};
1416

@@ -66,6 +68,10 @@ pub struct UiConfigKey {
6668
pub signer: bool,
6769
}
6870

71+
#[deprecated(
72+
since = "1.16.7",
73+
note = "Please use `solana_sdk::stake::state::warmup_cooldown_rate()` instead"
74+
)]
6975
#[derive(Debug, Serialize, Deserialize, PartialEq)]
7076
#[serde(rename_all = "camelCase")]
7177
pub struct UiStakeConfig {

account-decoder/src/parse_stake.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,16 @@ pub struct UiDelegation {
119119
pub stake: StringAmount,
120120
pub activation_epoch: StringAmount,
121121
pub deactivation_epoch: StringAmount,
122+
#[deprecated(
123+
since = "1.16.7",
124+
note = "Please use `solana_sdk::stake::stake::warmup_cooldown_rate()` instead"
125+
)]
122126
pub warmup_cooldown_rate: f64,
123127
}
124128

125129
impl From<Delegation> for UiDelegation {
126130
fn from(delegation: Delegation) -> Self {
131+
#[allow(deprecated)]
127132
Self {
128133
voter: delegation.voter_pubkey.to_string(),
129134
stake: delegation.stake.to_string(),
@@ -139,6 +144,7 @@ mod test {
139144
use {super::*, bincode::serialize, solana_sdk::stake::stake_flags::StakeFlags};
140145

141146
#[test]
147+
#[allow(deprecated)]
142148
fn test_parse_stake() {
143149
let stake_state = StakeState::Uninitialized;
144150
let stake_data = serialize(&stake_state).unwrap();

cli/src/cluster_query.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use {
22
crate::{
33
cli::{CliCommand, CliCommandInfo, CliConfig, CliError, ProcessResult},
44
compute_unit_price::WithComputeUnitPrice,
5+
feature::get_feature_activation_epoch,
56
spend_utils::{resolve_spend_tx_and_check_account_balance, SpendAmount},
67
},
78
clap::{value_t, value_t_or_exit, App, AppSettings, Arg, ArgMatches, SubCommand},
@@ -43,6 +44,7 @@ use {
4344
clock::{self, Clock, Slot},
4445
commitment_config::CommitmentConfig,
4546
epoch_schedule::Epoch,
47+
feature_set,
4648
hash::Hash,
4749
message::Message,
4850
native_token::lamports_to_sol,
@@ -1800,6 +1802,8 @@ pub fn process_show_stakes(
18001802
let stake_history = from_account(&stake_history_account).ok_or_else(|| {
18011803
CliError::RpcRequestError("Failed to deserialize stake history".to_string())
18021804
})?;
1805+
let new_rate_activation_epoch =
1806+
get_feature_activation_epoch(rpc_client, &feature_set::reduce_stake_warmup_cooldown::id())?;
18031807

18041808
let mut stake_accounts: Vec<CliKeyedStakeState> = vec![];
18051809
for (stake_pubkey, stake_account) in all_stake_accounts {
@@ -1815,6 +1819,7 @@ pub fn process_show_stakes(
18151819
use_lamports_unit,
18161820
&stake_history,
18171821
&clock,
1822+
new_rate_activation_epoch,
18181823
),
18191824
});
18201825
}
@@ -1833,6 +1838,7 @@ pub fn process_show_stakes(
18331838
use_lamports_unit,
18341839
&stake_history,
18351840
&clock,
1841+
new_rate_activation_epoch,
18361842
),
18371843
});
18381844
}

cli/src/feature.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use {
2222
genesis_config::ClusterType,
2323
message::Message,
2424
pubkey::Pubkey,
25+
stake_history::Epoch,
2526
transaction::Transaction,
2627
},
2728
std::{cmp::Ordering, collections::HashMap, fmt, str::FromStr, sync::Arc},
@@ -817,6 +818,22 @@ pub fn get_feature_is_active(
817818
.map(|status| matches!(status, Some(CliFeatureStatus::Active(_))))
818819
}
819820

821+
pub fn get_feature_activation_epoch(
822+
rpc_client: &RpcClient,
823+
feature_id: &Pubkey,
824+
) -> Result<Option<Epoch>, ClientError> {
825+
rpc_client
826+
.get_feature_activation_slot(feature_id)
827+
.and_then(|activation_slot: Option<Slot>| {
828+
rpc_client
829+
.get_epoch_schedule()
830+
.map(|epoch_schedule| (activation_slot, epoch_schedule))
831+
})
832+
.map(|(activation_slot, epoch_schedule)| {
833+
activation_slot.map(|slot| epoch_schedule.get_epoch(slot))
834+
})
835+
}
836+
820837
fn process_status(
821838
rpc_client: &RpcClient,
822839
config: &CliConfig,

cli/src/stake.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use {
66
ProcessResult,
77
},
88
compute_unit_price::WithComputeUnitPrice,
9+
feature::get_feature_activation_epoch,
910
memo::WithMemo,
1011
nonce::check_nonce_account,
1112
spend_utils::{resolve_spend_tx_and_check_account_balances, SpendAmount},
@@ -40,6 +41,7 @@ use {
4041
clock::{Clock, UnixTimestamp, SECONDS_PER_DAY},
4142
commitment_config::CommitmentConfig,
4243
epoch_schedule::EpochSchedule,
44+
feature_set,
4345
message::Message,
4446
pubkey::Pubkey,
4547
stake::{
@@ -48,7 +50,7 @@ use {
4850
state::{Authorized, Lockup, Meta, StakeActivationStatus, StakeAuthorize, StakeState},
4951
tools::{acceptable_reference_epoch_credits, eligible_for_deactivate_delinquent},
5052
},
51-
stake_history::StakeHistory,
53+
stake_history::{Epoch, StakeHistory},
5254
system_instruction::SystemError,
5355
sysvar::{clock, stake_history},
5456
transaction::Transaction,
@@ -2186,6 +2188,7 @@ pub fn build_stake_state(
21862188
use_lamports_unit: bool,
21872189
stake_history: &StakeHistory,
21882190
clock: &Clock,
2191+
new_rate_activation_epoch: Option<Epoch>,
21892192
) -> CliStakeState {
21902193
match stake_state {
21912194
StakeState::Stake(
@@ -2202,9 +2205,11 @@ pub fn build_stake_state(
22022205
effective,
22032206
activating,
22042207
deactivating,
2205-
} = stake
2206-
.delegation
2207-
.stake_activating_and_deactivating(current_epoch, Some(stake_history));
2208+
} = stake.delegation.stake_activating_and_deactivating(
2209+
current_epoch,
2210+
Some(stake_history),
2211+
new_rate_activation_epoch,
2212+
);
22082213
let lockup = if lockup.is_in_force(clock, None) {
22092214
Some(lockup.into())
22102215
} else {
@@ -2424,13 +2429,18 @@ pub fn process_show_stake_account(
24242429
let clock: Clock = from_account(&clock_account).ok_or_else(|| {
24252430
CliError::RpcRequestError("Failed to deserialize clock sysvar".to_string())
24262431
})?;
2432+
let new_rate_activation_epoch = get_feature_activation_epoch(
2433+
rpc_client,
2434+
&feature_set::reduce_stake_warmup_cooldown::id(),
2435+
)?;
24272436

24282437
let mut state = build_stake_state(
24292438
stake_account.lamports,
24302439
&stake_state,
24312440
use_lamports_unit,
24322441
&stake_history,
24332442
&clock,
2443+
new_rate_activation_epoch,
24342444
);
24352445

24362446
if state.stake_type == CliStakeType::Stake && state.activation_epoch.is_some() {

local-cluster/src/local_cluster.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ use {
3838
pubkey::Pubkey,
3939
signature::{Keypair, Signer},
4040
stake::{
41-
config as stake_config, instruction as stake_instruction,
41+
instruction as stake_instruction,
4242
state::{Authorized, Lockup},
4343
},
4444
system_transaction,
4545
transaction::Transaction,
4646
},
47-
solana_stake_program::{config::create_account as create_stake_config_account, stake_state},
47+
solana_stake_program::stake_state,
4848
solana_streamer::socket::SocketAddrSpace,
4949
solana_tpu_client::tpu_client::{
5050
DEFAULT_TPU_CONNECTION_POOL_SIZE, DEFAULT_TPU_ENABLE_UDP, DEFAULT_TPU_USE_QUIC,
@@ -267,18 +267,6 @@ impl LocalCluster {
267267
.native_instruction_processors
268268
.extend_from_slice(&config.native_instruction_processors);
269269

270-
// Replace staking config
271-
genesis_config.add_account(
272-
stake_config::id(),
273-
create_stake_config_account(
274-
1,
275-
&stake_config::Config {
276-
warmup_cooldown_rate: std::f64::MAX,
277-
slash_penalty: std::u8::MAX,
278-
},
279-
),
280-
);
281-
282270
let (leader_ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_config);
283271
let leader_contact_info = leader_node.info.clone();
284272
let mut leader_config = safe_clone_config(&config.validator_configs[0]);

local-cluster/tests/local_cluster.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,10 +1535,13 @@ fn test_fake_shreds_broadcast_leader() {
15351535
fn test_wait_for_max_stake() {
15361536
solana_logger::setup_with_default(RUST_LOG_FILTER);
15371537
let validator_config = ValidatorConfig::default_for_test();
1538+
let slots_per_epoch = MINIMUM_SLOTS_PER_EPOCH;
15381539
let mut config = ClusterConfig {
15391540
cluster_lamports: DEFAULT_CLUSTER_LAMPORTS,
15401541
node_stakes: vec![DEFAULT_NODE_STAKE; 4],
15411542
validator_configs: make_identical_validator_configs(&validator_config, 4),
1543+
slots_per_epoch,
1544+
stakers_slot_offset: slots_per_epoch,
15421545
..ClusterConfig::default()
15431546
};
15441547
let cluster = LocalCluster::new(&mut config, SocketAddrSpace::Unspecified);

program-test/tests/warp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ async fn stake_rewards_from_warp() {
278278
assert_eq!(
279279
stake
280280
.delegation
281-
.stake_activating_and_deactivating(clock.epoch, Some(&stake_history)),
281+
.stake_activating_and_deactivating(clock.epoch, Some(&stake_history), None),
282282
StakeActivationStatus::with_effective(stake.delegation.stake),
283283
);
284284
}
@@ -394,7 +394,7 @@ async fn stake_rewards_filter_bench_core(num_stake_accounts: u64) {
394394
assert_eq!(
395395
stake
396396
.delegation
397-
.stake_activating_and_deactivating(clock.epoch, Some(&stake_history)),
397+
.stake_activating_and_deactivating(clock.epoch, Some(&stake_history), None),
398398
StakeActivationStatus::with_effective(stake.delegation.stake),
399399
);
400400
}

programs/config/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ pub mod config_processor;
44
pub mod date_instruction;
55

66
pub use solana_sdk::config::program::id;
7+
#[allow(deprecated)]
8+
use solana_sdk::stake::config::Config as StakeConfig;
79
use {
810
bincode::{deserialize, serialize, serialized_size},
911
serde_derive::{Deserialize, Serialize},
1012
solana_sdk::{
1113
account::{Account, AccountSharedData},
1214
pubkey::Pubkey,
1315
short_vec,
14-
stake::config::Config as StakeConfig,
1516
},
1617
};
1718

@@ -21,6 +22,7 @@ pub trait ConfigState: serde::Serialize + Default {
2122
}
2223

2324
// TODO move ConfigState into `solana_program` to implement trait locally
25+
#[allow(deprecated)]
2426
impl ConfigState for StakeConfig {
2527
fn max_space() -> u64 {
2628
serialized_size(&StakeConfig::default()).unwrap()

programs/stake/src/config.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,31 @@
55
note = "Please use `solana_sdk::stake::config` or `solana_program::stake::config` instead"
66
)]
77
pub use solana_sdk::stake::config::*;
8+
#[allow(deprecated)]
9+
use solana_sdk::stake::config::{self, Config};
810
use {
911
bincode::deserialize,
1012
solana_config_program::{create_config_account, get_config_data},
1113
solana_sdk::{
1214
account::{AccountSharedData, ReadableAccount, WritableAccount},
1315
genesis_config::GenesisConfig,
14-
stake::config::{self, Config},
1516
transaction_context::BorrowedAccount,
1617
},
1718
};
1819

20+
#[allow(deprecated)]
1921
pub fn from(account: &BorrowedAccount) -> Option<Config> {
2022
get_config_data(account.get_data())
2123
.ok()
2224
.and_then(|data| deserialize(data).ok())
2325
}
2426

27+
#[allow(deprecated)]
2528
pub fn create_account(lamports: u64, config: &Config) -> AccountSharedData {
2629
create_config_account(vec![], config, lamports)
2730
}
2831

32+
#[allow(deprecated)]
2933
pub fn add_genesis_account(genesis_config: &mut GenesisConfig) -> u64 {
3034
let mut account = create_config_account(vec![], &Config::default(), 0);
3135
let lamports = genesis_config.rent.minimum_balance(account.data().len());

0 commit comments

Comments
 (0)