Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove almost all solana-sdk usage from solana-stake-program #4447

Merged
merged 1 commit into from
Jan 14, 2025
Merged
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
12 changes: 12 additions & 0 deletions Cargo.lock

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

9 changes: 9 additions & 0 deletions programs/sbf/Cargo.lock

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

12 changes: 12 additions & 0 deletions programs/stake/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,22 @@ edition = { workspace = true }
bincode = { workspace = true }
log = { workspace = true }
solana-account = { workspace = true }
solana-bincode = { workspace = true }
solana-clock = { workspace = true }
solana-config-program = { workspace = true }
solana-feature-set = { workspace = true }
solana-instruction = { workspace = true }
solana-log-collector = { workspace = true }
solana-native-token = { workspace = true }
solana-packet = { workspace = true }
solana-program = { workspace = true }
solana-program-runtime = { workspace = true }
solana-pubkey = { workspace = true }
solana-rent = { workspace = true }
solana-sdk = { workspace = true }
tao-stones marked this conversation as resolved.
Show resolved Hide resolved
solana-sdk-ids = { workspace = true }
solana-sysvar = { workspace = true }
solana-transaction-context = { workspace = true }
solana-type-overrides = { workspace = true }
solana-vote-program = { workspace = true, default-features = false }

Expand All @@ -28,7 +37,10 @@ assert_matches = { workspace = true }
criterion = { workspace = true }
proptest = { workspace = true }
solana-compute-budget = { workspace = true }
solana-epoch-rewards = { workspace = true }
solana-epoch-schedule = { workspace = true }
solana-logger = { workspace = true }
solana-sysvar-id = { workspace = true }
test-case = { workspace = true }

[features]
Expand Down
37 changes: 16 additions & 21 deletions programs/stake/benches/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,26 @@ use {
bincode::serialize,
criterion::{black_box, criterion_group, criterion_main, Criterion},
solana_account::{create_account_shared_data_for_test, AccountSharedData, WritableAccount},
solana_clock::{Clock, Epoch},
solana_feature_set::FeatureSet,
solana_instruction::AccountMeta,
solana_program_runtime::invoke_context::mock_process_instruction,
solana_pubkey::Pubkey,
solana_sdk::{
clock::{Clock, Epoch},
stake::{
instruction::{
self, AuthorizeCheckedWithSeedArgs, AuthorizeWithSeedArgs, LockupArgs,
LockupCheckedArgs, StakeInstruction,
},
stake_flags::StakeFlags,
state::{Authorized, Lockup, StakeAuthorize, StakeStateV2},
},
stake_history::StakeHistory,
sysvar::{
clock,
rent::{self, Rent},
stake_history,
solana_program::stake::{
instruction::{
self, AuthorizeCheckedWithSeedArgs, AuthorizeWithSeedArgs, LockupArgs,
LockupCheckedArgs, StakeInstruction,
},
stake_flags::StakeFlags,
state::{Authorized, Lockup, StakeAuthorize, StakeStateV2},
},
solana_program_runtime::invoke_context::mock_process_instruction,
solana_pubkey::Pubkey,
solana_rent::Rent,
solana_sdk_ids::sysvar::{clock, rent, stake_history},
solana_stake_program::{
stake_instruction,
stake_state::{Delegation, Meta, Stake},
},
solana_sysvar::stake_history::StakeHistory,
solana_vote_program::vote_state::{self, VoteState, VoteStateVersions},
std::sync::Arc,
};
Expand Down Expand Up @@ -207,7 +202,7 @@ impl TestSetup {
fn bench_initialize(c: &mut Criterion) {
let mut test_setup = TestSetup::new();
test_setup.add_account(
solana_sdk::sysvar::rent::id(),
solana_sdk_ids::sysvar::rent::id(),
create_account_shared_data_for_test(&Rent::default()),
);

Expand All @@ -224,7 +219,7 @@ fn bench_initialize(c: &mut Criterion) {
fn bench_initialize_checked(c: &mut Criterion) {
let mut test_setup = TestSetup::new();
test_setup.add_account(
solana_sdk::sysvar::rent::id(),
solana_sdk_ids::sysvar::rent::id(),
create_account_shared_data_for_test(&Rent::default()),
);
// add staker account
Expand Down Expand Up @@ -626,7 +621,7 @@ fn bench_deactivate_delinquent(c: &mut Criterion) {

// reference vote account has been consistently voting
let mut vote_state = VoteState::default();
for epoch in 0..=solana_sdk::stake::MINIMUM_DELINQUENT_EPOCHS_FOR_DEACTIVATION {
for epoch in 0..=solana_program::stake::MINIMUM_DELINQUENT_EPOCHS_FOR_DEACTIVATION {
vote_state.increment_credits(epoch as Epoch, 1);
}
let reference_vote_address = Pubkey::new_unique();
Expand Down Expand Up @@ -662,7 +657,7 @@ fn bench_deactivate_delinquent(c: &mut Criterion) {
test_setup.add_account(
clock::id(),
create_account_shared_data_for_test(&Clock {
epoch: solana_sdk::stake::MINIMUM_DELINQUENT_EPOCHS_FOR_DEACTIVATION as u64,
epoch: solana_program::stake::MINIMUM_DELINQUENT_EPOCHS_FOR_DEACTIVATION as u64,
..Clock::default()
}),
);
Expand Down
9 changes: 4 additions & 5 deletions programs/stake/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
//! config for staking
//! carries variables that the stake program cares about
#[allow(deprecated)]
use solana_sdk::stake::config;
#[deprecated(
since = "1.8.0",
note = "Please use `solana_sdk::stake::config` or `solana_program::stake::config` instead"
)]
pub use solana_sdk::stake::config::*;
pub use solana_program::stake::config::*;
use {
bincode::deserialize,
solana_account::{AccountSharedData, ReadableAccount, WritableAccount},
solana_config_program::{create_config_account, get_config_data},
solana_sdk::{genesis_config::GenesisConfig, transaction_context::BorrowedAccount},
solana_sdk::genesis_config::GenesisConfig,
solana_transaction_context::BorrowedAccount,
};

#[allow(deprecated)]
Expand All @@ -33,7 +32,7 @@ pub fn add_genesis_account(genesis_config: &mut GenesisConfig) -> u64 {

account.set_lamports(lamports.max(1));

genesis_config.add_account(config::id(), account);
genesis_config.add_account(solana_sdk_ids::config::id(), account);

lamports
}
5 changes: 3 additions & 2 deletions programs/stake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
since = "1.8.0",
note = "Please use `solana_sdk::stake::program::id` or `solana_program::stake::program::id` instead"
)]
pub use solana_sdk::stake::program::{check_id, id};
pub use solana_sdk_ids::stake::{check_id, id};
use {
solana_feature_set::{self as feature_set, FeatureSet},
solana_sdk::{genesis_config::GenesisConfig, native_token::LAMPORTS_PER_SOL},
solana_native_token::LAMPORTS_PER_SOL,
solana_sdk::genesis_config::GenesisConfig,
};

pub mod config;
Expand Down
12 changes: 5 additions & 7 deletions programs/stake/src/points.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
//! Used by `solana-runtime`.

use {
solana_clock::Epoch,
solana_instruction::error::InstructionError,
solana_program::stake::state::{Delegation, Stake, StakeStateV2},
solana_pubkey::Pubkey,
solana_sdk::{
clock::Epoch,
stake::state::{Delegation, Stake, StakeStateV2},
stake_history::StakeHistory,
},
solana_sysvar::stake_history::StakeHistory,
solana_vote_program::vote_state::VoteState,
std::cmp::Ordering,
};
Expand Down Expand Up @@ -212,7 +210,7 @@ pub(crate) fn calculate_stake_points_and_credits(

#[cfg(test)]
mod tests {
use {super::*, crate::stake_state::new_stake, solana_sdk::native_token};
use {super::*, crate::stake_state::new_stake, solana_native_token::sol_to_lamports};

#[test]
fn test_stake_state_calculate_points_with_typical_values() {
Expand All @@ -221,7 +219,7 @@ mod tests {
// bootstrap means fully-vested stake at epoch 0 with
// 10_000_000 SOL is a big but not unreasaonable stake
let stake = new_stake(
native_token::sol_to_lamports(10_000_000f64),
sol_to_lamports(10_000_000f64),
&Pubkey::default(),
&vote_state,
u64::MAX,
Expand Down
19 changes: 8 additions & 11 deletions programs/stake/src/rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@ use {
calculate_stake_points_and_credits, CalculatedStakePoints, InflationPointCalculationEvent,
PointValue, SkippedReason,
},
solana_account::{AccountSharedData, WritableAccount},
solana_account::{state_traits::StateMut, AccountSharedData, WritableAccount},
solana_clock::Epoch,
solana_instruction::error::InstructionError,
solana_sdk::{
account_utils::StateMut,
clock::Epoch,
stake::{
instruction::StakeError,
state::{Stake, StakeStateV2},
},
stake_history::StakeHistory,
solana_program::stake::{
instruction::StakeError,
state::{Stake, StakeStateV2},
},
solana_sysvar::stake_history::StakeHistory,
solana_vote_program::vote_state::VoteState,
};

Expand Down Expand Up @@ -231,8 +228,8 @@ mod tests {
use {
super::*,
crate::{points::null_tracer, stake_state::new_stake},
solana_native_token::sol_to_lamports,
solana_pubkey::Pubkey,
solana_sdk::native_token,
test_case::test_case,
};

Expand Down Expand Up @@ -640,7 +637,7 @@ mod tests {
// bootstrap means fully-vested stake at epoch 0 with
// 10_000_000 SOL is a big but not unreasaonable stake
let stake = new_stake(
native_token::sol_to_lamports(10_000_000f64),
sol_to_lamports(10_000_000f64),
&Pubkey::default(),
&vote_state,
u64::MAX,
Expand Down
Loading
Loading