Skip to content

Commit 2bfac63

Browse files
committed
Deprecation strategy update
1 parent 9c0ba5c commit 2bfac63

File tree

9 files changed

+77
-62
lines changed

9 files changed

+77
-62
lines changed

interface/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ pub mod stake_history;
1212
pub mod state;
1313
#[cfg(feature = "sysvar")]
1414
pub mod sysvar;
15-
#[cfg(test)]
16-
mod test_utils;
1715
pub mod tools;
16+
#[cfg(test)]
17+
mod ulp;
1818
pub mod warmup_cooldown_allowance;
1919

2020
pub mod program {

interface/src/state.rs

Lines changed: 55 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,9 @@ impl Delegation {
496496
self.activation_epoch == u64::MAX
497497
}
498498

499+
/// Previous implementation that uses floats under the hood to calculate warmup/cooldown
500+
/// rate-limiting. New `stake_v2()` uses integers (upstream eBPF-compatible).
501+
#[deprecated(since = "2.0.1", note = "Use stake_v2() instead")]
499502
pub fn stake<T: StakeHistoryGetEntry>(
500503
&self,
501504
epoch: Epoch,
@@ -507,33 +510,20 @@ impl Delegation {
507510
}
508511

509512
/// Previous implementation that uses floats under the hood to calculate warmup/cooldown
510-
/// rate-limiting. For the purpose of consumers like Agave that need to feature gate the update.
511-
#[deprecated(since = "2.0.1", note = "Use stake() instead")]
512-
pub fn stake_v1_legacy<T: StakeHistoryGetEntry>(
513-
&self,
514-
epoch: Epoch,
515-
history: &T,
516-
new_rate_activation_epoch: Option<Epoch>,
517-
) -> u64 {
518-
self.stake_activating_and_deactivating_v1_legacy(epoch, history, new_rate_activation_epoch)
519-
.effective
520-
}
521-
522-
/// Previous implementation that uses floats under the hood to calculate warmup/cooldown
523-
/// rate-limiting. For the purpose of consumers like Agave that need to feature gate the update.
513+
/// rate-limiting. New `stake_activating_and_deactivating_v2()` uses integers (upstream eBPF-compatible).
524514
#[deprecated(
525515
since = "2.0.1",
526-
note = "Use stake_activating_and_deactivating() instead"
516+
note = "Use stake_activating_and_deactivating_v2() instead"
527517
)]
528-
pub fn stake_activating_and_deactivating_v1_legacy<T: StakeHistoryGetEntry>(
518+
pub fn stake_activating_and_deactivating<T: StakeHistoryGetEntry>(
529519
&self,
530520
target_epoch: Epoch,
531521
history: &T,
532522
new_rate_activation_epoch: Option<Epoch>,
533523
) -> StakeActivationStatus {
534524
// first, calculate an effective and activating stake
535525
let (effective_stake, activating_stake) =
536-
self.stake_and_activating_v1_legacy(target_epoch, history, new_rate_activation_epoch);
526+
self.stake_and_activating(target_epoch, history, new_rate_activation_epoch);
537527

538528
// then de-activate some portion if necessary
539529
if target_epoch < self.deactivation_epoch {
@@ -612,8 +602,8 @@ impl Delegation {
612602
}
613603

614604
// returned tuple is (effective, activating) stake
615-
#[deprecated(since = "2.0.1", note = "Use stake_and_activating() instead")]
616-
fn stake_and_activating_v1_legacy<T: StakeHistoryGetEntry>(
605+
#[deprecated(since = "2.0.1", note = "Use stake_and_activating_v2() instead")]
606+
fn stake_and_activating<T: StakeHistoryGetEntry>(
617607
&self,
618608
target_epoch: Epoch,
619609
history: &T,
@@ -699,15 +689,25 @@ impl Delegation {
699689
}
700690
}
701691

702-
pub fn stake_activating_and_deactivating<T: StakeHistoryGetEntry>(
692+
pub fn stake_v2<T: StakeHistoryGetEntry>(
693+
&self,
694+
epoch: Epoch,
695+
history: &T,
696+
new_rate_activation_epoch: Option<Epoch>,
697+
) -> u64 {
698+
self.stake_activating_and_deactivating_v2(epoch, history, new_rate_activation_epoch)
699+
.effective
700+
}
701+
702+
pub fn stake_activating_and_deactivating_v2<T: StakeHistoryGetEntry>(
703703
&self,
704704
target_epoch: Epoch,
705705
history: &T,
706706
new_rate_activation_epoch: Option<Epoch>,
707707
) -> StakeActivationStatus {
708708
// first, calculate an effective and activating stake
709709
let (effective_stake, activating_stake) =
710-
self.stake_and_activating(target_epoch, history, new_rate_activation_epoch);
710+
self.stake_and_activating_v2(target_epoch, history, new_rate_activation_epoch);
711711

712712
// then de-activate some portion if necessary
713713
if target_epoch < self.deactivation_epoch {
@@ -791,7 +791,7 @@ impl Delegation {
791791
}
792792

793793
// returned tuple is (effective, activating) stake
794-
fn stake_and_activating<T: StakeHistoryGetEntry>(
794+
fn stake_and_activating_v2<T: StakeHistoryGetEntry>(
795795
&self,
796796
target_epoch: Epoch,
797797
history: &T,
@@ -901,6 +901,7 @@ pub struct Stake {
901901
}
902902

903903
impl Stake {
904+
#[deprecated(since = "2.0.1", note = "Use stake_v2() instead")]
904905
pub fn stake<T: StakeHistoryGetEntry>(
905906
&self,
906907
epoch: Epoch,
@@ -911,15 +912,14 @@ impl Stake {
911912
.stake(epoch, history, new_rate_activation_epoch)
912913
}
913914

914-
#[deprecated(since = "2.0.1", note = "Use stake() instead")]
915-
pub fn stake_v1_legacy<T: StakeHistoryGetEntry>(
915+
pub fn stake_v2<T: StakeHistoryGetEntry>(
916916
&self,
917917
epoch: Epoch,
918918
history: &T,
919919
new_rate_activation_epoch: Option<Epoch>,
920920
) -> u64 {
921921
self.delegation
922-
.stake_v1_legacy(epoch, history, new_rate_activation_epoch)
922+
.stake_v2(epoch, history, new_rate_activation_epoch)
923923
}
924924

925925
pub fn split(
@@ -983,7 +983,11 @@ mod tests {
983983
I: Iterator<Item = &'a Delegation>,
984984
{
985985
stakes.fold(StakeHistoryEntry::default(), |sum, stake| {
986-
sum + stake.stake_activating_and_deactivating(epoch, history, new_rate_activation_epoch)
986+
sum + stake.stake_activating_and_deactivating_v2(
987+
epoch,
988+
history,
989+
new_rate_activation_epoch,
990+
)
987991
})
988992
}
989993

@@ -1191,23 +1195,31 @@ mod tests {
11911195
let mut stake_history = StakeHistory::default();
11921196
// assert that this stake follows step function if there's no history
11931197
assert_eq!(
1194-
stake.stake_activating_and_deactivating(stake.activation_epoch, &stake_history, None),
1198+
stake.stake_activating_and_deactivating_v2(
1199+
stake.activation_epoch,
1200+
&stake_history,
1201+
None
1202+
),
11951203
StakeActivationStatus::with_effective_and_activating(0, stake.stake),
11961204
);
11971205
for epoch in stake.activation_epoch + 1..stake.deactivation_epoch {
11981206
assert_eq!(
1199-
stake.stake_activating_and_deactivating(epoch, &stake_history, None),
1207+
stake.stake_activating_and_deactivating_v2(epoch, &stake_history, None),
12001208
StakeActivationStatus::with_effective(stake.stake),
12011209
);
12021210
}
12031211
// assert that this stake is full deactivating
12041212
assert_eq!(
1205-
stake.stake_activating_and_deactivating(stake.deactivation_epoch, &stake_history, None),
1213+
stake.stake_activating_and_deactivating_v2(
1214+
stake.deactivation_epoch,
1215+
&stake_history,
1216+
None
1217+
),
12061218
StakeActivationStatus::with_deactivating(stake.stake),
12071219
);
12081220
// assert that this stake is fully deactivated if there's no history
12091221
assert_eq!(
1210-
stake.stake_activating_and_deactivating(
1222+
stake.stake_activating_and_deactivating_v2(
12111223
stake.deactivation_epoch + 1,
12121224
&stake_history,
12131225
None
@@ -1224,7 +1236,7 @@ mod tests {
12241236
);
12251237
// assert that this stake is broken, because above setup is broken
12261238
assert_eq!(
1227-
stake.stake_activating_and_deactivating(1, &stake_history, None),
1239+
stake.stake_activating_and_deactivating_v2(1, &stake_history, None),
12281240
StakeActivationStatus::with_effective_and_activating(0, stake.stake),
12291241
);
12301242

@@ -1239,7 +1251,7 @@ mod tests {
12391251
);
12401252
// assert that this stake is broken, because above setup is broken
12411253
assert_eq!(
1242-
stake.stake_activating_and_deactivating(2, &stake_history, None),
1254+
stake.stake_activating_and_deactivating_v2(2, &stake_history, None),
12431255
StakeActivationStatus::with_effective_and_activating(
12441256
increment,
12451257
stake.stake - increment
@@ -1258,7 +1270,7 @@ mod tests {
12581270
);
12591271
// assert that this stake is broken, because above setup is broken
12601272
assert_eq!(
1261-
stake.stake_activating_and_deactivating(
1273+
stake.stake_activating_and_deactivating_v2(
12621274
stake.deactivation_epoch + 1,
12631275
&stake_history,
12641276
None,
@@ -1277,7 +1289,7 @@ mod tests {
12771289
);
12781290
// assert that this stake is broken, because above setup is broken
12791291
assert_eq!(
1280-
stake.stake_activating_and_deactivating(
1292+
stake.stake_activating_and_deactivating_v2(
12811293
stake.deactivation_epoch + 2,
12821294
&stake_history,
12831295
None,
@@ -1347,7 +1359,7 @@ mod tests {
13471359
assert_eq!(
13481360
expected_stakes,
13491361
(0..expected_stakes.len())
1350-
.map(|epoch| stake.stake_activating_and_deactivating(
1362+
.map(|epoch| stake.stake_activating_and_deactivating_v2(
13511363
epoch as u64,
13521364
&stake_history,
13531365
None,
@@ -1478,7 +1490,7 @@ mod tests {
14781490
let calculate_each_staking_status = |stake: &Delegation, epoch_count: usize| -> Vec<_> {
14791491
(0..epoch_count)
14801492
.map(|epoch| {
1481-
stake.stake_activating_and_deactivating(epoch as u64, &stake_history, None)
1493+
stake.stake_activating_and_deactivating_v2(epoch as u64, &stake_history, None)
14821494
})
14831495
.collect::<Vec<_>>()
14841496
};
@@ -1599,7 +1611,7 @@ mod tests {
15991611
(0, history.deactivating)
16001612
};
16011613
assert_eq!(
1602-
stake.stake_activating_and_deactivating(epoch, &stake_history, None),
1614+
stake.stake_activating_and_deactivating_v2(epoch, &stake_history, None),
16031615
StakeActivationStatus {
16041616
effective: expected_stake,
16051617
activating: expected_activating,
@@ -1631,7 +1643,7 @@ mod tests {
16311643
for epoch in 0..epochs {
16321644
let stake = delegations
16331645
.iter()
1634-
.map(|delegation| delegation.stake(epoch, &stake_history, None))
1646+
.map(|delegation| delegation.stake_v2(epoch, &stake_history, None))
16351647
.sum::<u64>();
16361648
max_stake = max_stake.max(stake);
16371649
min_stake = min_stake.min(stake);
@@ -1700,7 +1712,7 @@ mod tests {
17001712

17011713
let mut prev_total_effective_stake = delegations
17021714
.iter()
1703-
.map(|delegation| delegation.stake(0, &stake_history, new_rate_activation_epoch))
1715+
.map(|delegation| delegation.stake_v2(0, &stake_history, new_rate_activation_epoch))
17041716
.sum::<u64>();
17051717

17061718
// uncomment and add ! for fun with graphing
@@ -1709,7 +1721,7 @@ mod tests {
17091721
let total_effective_stake = delegations
17101722
.iter()
17111723
.map(|delegation| {
1712-
delegation.stake(epoch, &stake_history, new_rate_activation_epoch)
1724+
delegation.stake_v2(epoch, &stake_history, new_rate_activation_epoch)
17131725
})
17141726
.sum::<u64>();
17151727

@@ -1948,7 +1960,7 @@ mod tests {
19481960
super::*,
19491961
crate::{
19501962
stake_history::{StakeHistory, StakeHistoryEntry},
1951-
test_utils::max_ulp_tolerance,
1963+
ulp::max_ulp_tolerance,
19521964
},
19531965
proptest::prelude::*,
19541966
solana_pubkey::Pubkey,
@@ -2012,12 +2024,12 @@ mod tests {
20122024
new_rate_activation_epoch_option in prop::option::of(0u64..=50),
20132025
stake_history in arbitrary_stake_history(50),
20142026
) {
2015-
let new_stake = delegation.stake(
2027+
let new_stake = delegation.stake_v2(
20162028
target_epoch,
20172029
&stake_history,
20182030
new_rate_activation_epoch_option,
20192031
);
2020-
let legacy_stake = delegation.stake_v1_legacy(
2032+
let legacy_stake = delegation.stake(
20212033
target_epoch,
20222034
&stake_history,
20232035
new_rate_activation_epoch_option,

interface/src/test_utils.rs renamed to interface/src/ulp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Shared utilities for tests only
1+
//! Math utilities for calculating float/int differences
22
33
/// Calculates the "Unit in the Last Place" (`ULP`) for a `u64` value, which is
44
/// the gap between adjacent `f64` values at that magnitude. We need this because

interface/src/warmup_cooldown_allowance.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ fn rate_limited_stake_change(
100100
mod test {
101101
#[allow(deprecated)]
102102
use crate::state::{DEFAULT_WARMUP_COOLDOWN_RATE, NEW_WARMUP_COOLDOWN_RATE};
103-
use {super::*, crate::test_utils::max_ulp_tolerance, proptest::prelude::*};
103+
use {super::*, crate::ulp::max_ulp_tolerance, proptest::prelude::*};
104104

105105
// === Rate selector ===
106106

program/src/helpers/delegate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub(crate) fn redelegate_stake(
3838
stake_history: &StakeHistorySysvar,
3939
) -> Result<(), ProgramError> {
4040
// If stake is currently active:
41-
if stake.stake(
41+
if stake.stake_v2(
4242
epoch,
4343
stake_history,
4444
PERPETUAL_NEW_WARMUP_COOLDOWN_RATE_EPOCH,

program/src/helpers/merge.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl MergeKind {
4343
StakeStateV2::Stake(meta, stake, stake_flags) => {
4444
// stake must not be in a transient state. Transient here meaning
4545
// activating or deactivating with non-zero effective stake.
46-
let status = stake.delegation.stake_activating_and_deactivating(
46+
let status = stake.delegation.stake_activating_and_deactivating_v2(
4747
clock.epoch,
4848
stake_history,
4949
PERPETUAL_NEW_WARMUP_COOLDOWN_RATE_EPOCH,

program/src/processor.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -469,11 +469,13 @@ impl Processor {
469469

470470
let minimum_delegation = crate::get_minimum_delegation();
471471

472-
let status = source_stake.delegation.stake_activating_and_deactivating(
473-
clock.epoch,
474-
stake_history,
475-
PERPETUAL_NEW_WARMUP_COOLDOWN_RATE_EPOCH,
476-
);
472+
let status = source_stake
473+
.delegation
474+
.stake_activating_and_deactivating_v2(
475+
clock.epoch,
476+
stake_history,
477+
PERPETUAL_NEW_WARMUP_COOLDOWN_RATE_EPOCH,
478+
);
477479

478480
let is_active = status.effective > 0;
479481

@@ -631,7 +633,7 @@ impl Processor {
631633
.map_err(to_program_error)?;
632634
// if we have a deactivation epoch and we're in cooldown
633635
let staked = if clock.epoch >= stake.delegation.deactivation_epoch {
634-
stake.delegation.stake(
636+
stake.delegation.stake_v2(
635637
clock.epoch,
636638
stake_history,
637639
PERPETUAL_NEW_WARMUP_COOLDOWN_RATE_EPOCH,

program/tests/program_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ pub async fn get_effective_stake(banks_client: &mut BanksClient, pubkey: &Pubkey
198198
StakeStateV2::Stake(_, stake, _) => {
199199
stake
200200
.delegation
201-
.stake_activating_and_deactivating(clock.epoch, &stake_history, Some(0))
201+
.stake_activating_and_deactivating_v2(clock.epoch, &stake_history, Some(0))
202202
.effective
203203
}
204204
_ => 0,

0 commit comments

Comments
 (0)