Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ opt-level = 3
[patch.crates-io]
# for details, see https://github.com/anza-xyz/crossbeam/commit/fd279d707025f0e60951e429bf778b4813d1b6bf
crossbeam-epoch = { git = "https://github.com/anza-xyz/crossbeam", rev = "fd279d707025f0e60951e429bf778b4813d1b6bf" }
solana-stake-interface = { git = "https://github.com/solana-program/stake", rev = "5f3fe65d94213f7514a0cc45662a5fe0cc2dbe15" }

# We include the following crates as our dependencies above from crates.io:
#
Expand Down
14 changes: 4 additions & 10 deletions account-decoder/src/parse_stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use {
bincode::deserialize,
serde::{Deserialize, Serialize},
solana_clock::{Epoch, UnixTimestamp},
solana_stake_interface::state::{Authorized, Delegation, Lockup, Meta, Stake, StakeStateV2},
solana_stake_interface::{
state::{Authorized, Delegation, Lockup, Meta, Stake, StakeStateV2},
},
};

pub fn parse_stake(data: &[u8]) -> Result<StakeAccountType, ParseAccountError> {
Expand Down Expand Up @@ -118,22 +120,15 @@ pub struct UiDelegation {
pub stake: StringAmount,
pub activation_epoch: StringAmount,
pub deactivation_epoch: StringAmount,
#[deprecated(
since = "1.16.7",
note = "Please use `solana_stake_interface::state::warmup_cooldown_rate()` instead"
)]
pub warmup_cooldown_rate: f64,
}

impl From<Delegation> for UiDelegation {
fn from(delegation: Delegation) -> Self {
#[allow(deprecated)]
Self {
voter: delegation.voter_pubkey.to_string(),
stake: delegation.stake.to_string(),
activation_epoch: delegation.activation_epoch.to_string(),
deactivation_epoch: delegation.deactivation_epoch.to_string(),
warmup_cooldown_rate: delegation.warmup_cooldown_rate,
}
}
}
Expand Down Expand Up @@ -194,7 +189,7 @@ mod test {
stake: 20,
activation_epoch: 2,
deactivation_epoch: u64::MAX,
warmup_cooldown_rate: 0.25,
_reserved: [0; 8],
},
credits_observed: 10,
};
Expand Down Expand Up @@ -222,7 +217,6 @@ mod test {
stake: 20.to_string(),
activation_epoch: 2.to_string(),
deactivation_epoch: u64::MAX.to_string(),
warmup_cooldown_rate: 0.25,
},
credits_observed: 10,
})
Expand Down
2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ solana-sdk-ids = "=3.0.0"
solana-signature = { version = "=3.1.0", default-features = false }
solana-signer = "=3.0.0"
solana-slot-history = "=3.0.0"
solana-stake-interface = "=2.0.2"
solana-stake-interface = { workspace = true }
solana-system-interface = { version = "=2.0", features = ["bincode"] }
solana-sysvar = "=3.1.1"
solana-tps-client = { workspace = true }
Expand Down
9 changes: 9 additions & 0 deletions cli/src/cluster_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1997,6 +1997,13 @@ pub async fn process_show_stakes(
&agave_feature_set::reduce_stake_warmup_cooldown::id(),
)
.await?;
let fixed_point_activation_epoch = get_feature_activation_epoch(
rpc_client,
&agave_feature_set::stake_program_fixed_point_warmup_cooldown::id(),
)
.await?;
let use_fixed_point_stake_math = fixed_point_activation_epoch
.is_some_and(|activation_epoch| clock.epoch >= activation_epoch);
stake_account_progress_bar.finish_and_clear();

let mut stake_accounts: Vec<CliKeyedStakeState> = vec![];
Expand All @@ -2018,6 +2025,7 @@ pub async fn process_show_stakes(
&stake_history,
&clock,
new_rate_activation_epoch,
use_fixed_point_stake_math,
false,
),
});
Expand All @@ -2036,6 +2044,7 @@ pub async fn process_show_stakes(
&stake_history,
&clock,
new_rate_activation_epoch,
use_fixed_point_stake_math,
false,
),
});
Expand Down
28 changes: 23 additions & 5 deletions cli/src/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2436,6 +2436,7 @@ pub fn build_stake_state(
stake_history: &StakeHistory,
clock: &Clock,
new_rate_activation_epoch: Option<Epoch>,
use_fixed_point_stake_math: bool,
use_csv: bool,
) -> CliStakeState {
match stake_state {
Expand All @@ -2453,11 +2454,20 @@ pub fn build_stake_state(
effective,
activating,
deactivating,
} = stake.delegation.stake_activating_and_deactivating(
current_epoch,
stake_history,
new_rate_activation_epoch,
);
} = if use_fixed_point_stake_math {
stake.delegation.stake_activating_and_deactivating_v2(
current_epoch,
stake_history,
new_rate_activation_epoch,
)
} else {
#[allow(deprecated)]
stake.delegation.stake_activating_and_deactivating(
current_epoch,
stake_history,
new_rate_activation_epoch,
)
};
let lockup = if lockup.is_in_force(clock, None) {
Some(lockup.into())
} else {
Expand Down Expand Up @@ -2723,6 +2733,13 @@ pub async fn get_account_stake_state(
&agave_feature_set::reduce_stake_warmup_cooldown::id(),
)
.await?;
let fixed_point_activation_epoch = get_feature_activation_epoch(
rpc_client,
&agave_feature_set::stake_program_fixed_point_warmup_cooldown::id(),
)
.await?;
let use_fixed_point_stake_math = fixed_point_activation_epoch
.is_some_and(|activation_epoch| clock.epoch >= activation_epoch);

let mut state = build_stake_state(
stake_account.lamports,
Expand All @@ -2731,6 +2748,7 @@ pub async fn get_account_stake_state(
&stake_history,
&clock,
new_rate_activation_epoch,
use_fixed_point_stake_math,
use_csv,
);

Expand Down
3 changes: 2 additions & 1 deletion dev-bins/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ solana-sdk-ids = "3.0.0"
solana-shred-version = "3.0.0"
solana-signature = { version = "3.1.0", default-features = false }
solana-signer = "3.0.0"
solana-stake-interface = "2.0.2"
solana-stake-interface = { workspace = true }
solana-storage-bigtable = { path = "../storage-bigtable", version = "=4.0.0-alpha.0", features = ["agave-unstable-api"] }
solana-streamer = { path = "../streamer", version = "=4.0.0-alpha.0", features = ["agave-unstable-api"] }
solana-svm-callback = { path = "../svm-callback", version = "=4.0.0-alpha.0", features = ["agave-unstable-api"] }
Expand Down Expand Up @@ -223,3 +223,4 @@ opt-level = 3
# There is a similar override in `programs/sbf/Cargo.toml`. Please keep both
# comments and the overrides in sync.
solana-curve25519 = { path = "../curves/curve25519" }
solana-stake-interface = { git = "https://github.com/solana-program/stake", rev = "5f3fe65d94213f7514a0cc45662a5fe0cc2dbe15" }
8 changes: 8 additions & 0 deletions feature-set/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,10 @@ pub mod reduce_stake_warmup_cooldown {
solana_pubkey::declare_id!("GwtDQBghCTBgmX2cpEGNPxTEBUTQRaDMGTr5qychdGMj");
}

pub mod stake_program_fixed_point_warmup_cooldown {
solana_pubkey::declare_id!("FvA7BcL3RG2wL5QbDoRhFKi5o9nSxoarQrsLx6EHTcmC");
}

pub mod revise_turbine_epoch_stakes {
solana_pubkey::declare_id!("BTWmtJC8U5ZLMbBUUA1k6As62sYjPEjAiNAT55xYGdJU");
}
Expand Down Expand Up @@ -1795,6 +1799,10 @@ pub static FEATURE_NAMES: LazyLock<AHashMap<Pubkey, &'static str>> = LazyLock::n
reduce_stake_warmup_cooldown::id(),
"reduce stake warmup cooldown from 25% to 9%",
),
(
stake_program_fixed_point_warmup_cooldown::id(),
"SIMD-0391: use fixed-point stake warmup/cooldown math",
),
(
revise_turbine_epoch_stakes::id(),
"revise turbine epoch stakes",
Expand Down
2 changes: 1 addition & 1 deletion genesis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ solana-rpc-client-api = { workspace = true }
solana-runtime = { workspace = true }
solana-sdk-ids = "=3.0.0"
solana-signer = "=3.0.0"
solana-stake-interface = { version = "=2.0.2", features = ["borsh"] }
solana-stake-interface = { workspace = true, features = ["borsh"] }
solana-time-utils = "3.0.0"
solana-version = { workspace = true }
solana-vote-program = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions program-test/tests/warp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ async fn stake_rewards_from_warp() {
assert_eq!(
stake
.delegation
.stake_activating_and_deactivating(clock.epoch, &stake_history, None),
.stake_activating_and_deactivating_v2(clock.epoch, &stake_history, None),
StakeActivationStatus::with_effective(stake.delegation.stake),
);
}
Expand Down Expand Up @@ -325,7 +325,7 @@ async fn stake_rewards_filter_bench_core(num_stake_accounts: u64) {
assert_eq!(
stake
.delegation
.stake_activating_and_deactivating(clock.epoch, &stake_history, None),
.stake_activating_and_deactivating_v2(clock.epoch, &stake_history, None),
StakeActivationStatus::with_effective(stake.delegation.stake),
);
}
Expand Down
5 changes: 3 additions & 2 deletions programs/sbf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ solana-sbpf = "=0.13.1"
solana-sdk-ids = "=3.0.0"
solana-secp256k1-recover = "=3.1.0"
solana-sha256-hasher = { version = "=3.1.0", features = ["sha2"] }
solana-stake-interface = { version = "=2.0.2", features = ["bincode"] }
solana-stake-interface = { workspace = true, features = ["bincode"] }
solana-svm = { path = "../../svm", version = "=4.0.0-alpha.0" }
solana-svm-callback = { path = "../../svm-callback", version = "=4.0.0-alpha.0" }
solana-svm-feature-set = { path = "../../svm-feature-set", version = "=4.0.0-alpha.0" }
Expand Down Expand Up @@ -239,7 +239,7 @@ solana-sbf-rust-realloc-invoke-dep = { workspace = true }
solana-sbpf = { workspace = true, features = ["jit"] }
solana-sdk-ids = "3.0.0"
solana-signer = "3.0.0"
solana-stake-interface = "2.0.2"
solana-stake-interface = { workspace = true }
solana-svm = { workspace = true }
solana-svm-callback = { workspace = true }
solana-svm-feature-set = { workspace = true }
Expand Down Expand Up @@ -310,3 +310,4 @@ name = "bpf_loader"
# There is a similar override in `../../Cargo.toml`. Please keep both comments
# and the overrides in sync.
solana-curve25519 = { path = "../../curves/curve25519" }
solana-stake-interface = { git = "https://github.com/solana-program/stake", rev = "5f3fe65d94213f7514a0cc45662a5fe0cc2dbe15" }
19 changes: 16 additions & 3 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1630,6 +1630,11 @@ impl Bank {
}
}

fn use_fixed_point_stake_math(&self) -> bool {
self.feature_set
.is_active(&agave_feature_set::stake_program_fixed_point_warmup_cooldown::id())
}

/// Returns updated stake history and vote accounts that includes new
/// activated stake from the last epoch.
fn compute_new_epoch_caches_and_rewards(
Expand All @@ -1649,7 +1654,8 @@ impl Bank {
self.epoch(),
thread_pool,
self.new_warmup_cooldown_rate_epoch(),
&stake_delegations
&stake_delegations,
self.use_fixed_point_stake_math(),
));

// Apply stake rewards and commission using new snapshots.
Expand Down Expand Up @@ -4069,13 +4075,15 @@ impl Bank {
assert!(!self.freeze_started());
let mut m = Measure::start("stakes_cache.check_and_store");
let new_warmup_cooldown_rate_epoch = self.new_warmup_cooldown_rate_epoch();
let use_fixed_point_stake_math = self.use_fixed_point_stake_math();

(0..accounts.len()).for_each(|i| {
accounts.account(i, |account| {
self.stakes_cache.check_and_store(
account.pubkey(),
&account,
new_warmup_cooldown_rate_epoch,
use_fixed_point_stake_math,
)
})
});
Expand Down Expand Up @@ -5020,6 +5028,7 @@ impl Bank {
) {
debug_assert_eq!(txs.len(), processing_results.len());
let new_warmup_cooldown_rate_epoch = self.new_warmup_cooldown_rate_epoch();
let use_fixed_point_stake_math = self.use_fixed_point_stake_math();
txs.iter()
.zip(processing_results)
.filter_map(|(tx, processing_result)| {
Expand All @@ -5041,8 +5050,12 @@ impl Bank {
.for_each(|(pubkey, account)| {
// note that this could get timed to: self.rc.accounts.accounts_db.stats.stakes_cache_check_and_store_us,
// but this code path is captured separately in ExecuteTimingType::UpdateStakesCacheUs
self.stakes_cache
.check_and_store(pubkey, account, new_warmup_cooldown_rate_epoch);
self.stakes_cache.check_and_store(
pubkey,
account,
new_warmup_cooldown_rate_epoch,
use_fixed_point_stake_math,
);
});
}

Expand Down
6 changes: 6 additions & 0 deletions runtime/src/bank/partitioned_epoch_rewards/calculation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ impl Bank {
reward_calc_tracer: Option<impl RewardCalcTracer>,
new_rate_activation_epoch: Option<Epoch>,
delay_commission_updates: bool,
use_fixed_point_stake_math: bool,
) -> Option<DelegationRewards> {
// curry closure to add the contextual stake_pubkey
let reward_calc_tracer = reward_calc_tracer.as_ref().map(|outer| {
Expand Down Expand Up @@ -488,6 +489,7 @@ impl Bank {
stake_history,
reward_calc_tracer,
new_rate_activation_epoch,
use_fixed_point_stake_math,
) {
Ok((stake_reward, vote_rewards, stake)) => {
let stake_reward = PartitionedStakeReward {
Expand Down Expand Up @@ -532,6 +534,7 @@ impl Bank {
let delay_commission_updates = self
.feature_set
.is_active(&agave_feature_set::delay_commission_updates::id());
let use_fixed_point_stake_math = self.use_fixed_point_stake_math();

let mut measure_redeem_rewards = Measure::start("redeem-rewards");
// For N stake delegations, where N is >1,000,000, we produce:
Expand Down Expand Up @@ -562,6 +565,7 @@ impl Bank {
reward_calc_tracer.as_ref(),
new_warmup_cooldown_rate_epoch,
delay_commission_updates,
use_fixed_point_stake_math,
)
});
let (stake_reward, maybe_reward_record) = match maybe_reward_record {
Expand Down Expand Up @@ -642,6 +646,7 @@ impl Bank {

let solana_vote_program: Pubkey = solana_vote_program::id();
let new_warmup_cooldown_rate_epoch = self.new_warmup_cooldown_rate_epoch();
let use_fixed_point_stake_math = self.use_fixed_point_stake_math();
let (points, measure_us) = measure_us!(thread_pool.install(|| {
stake_delegations
.par_iter()
Expand All @@ -662,6 +667,7 @@ impl Bank {
DelegatedVoteState::from(vote_account.vote_state_view()),
stake_history,
new_warmup_cooldown_rate_epoch,
use_fixed_point_stake_math,
)
.unwrap_or(0)
})
Expand Down
Loading
Loading