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
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ solana-quic-client = { path = "quic-client", version = "=4.1.0-alpha.0", feature
solana-rayon-threadlimit = { path = "rayon-threadlimit", version = "=4.1.0-alpha.0", features = ["agave-unstable-api"] }
solana-remote-wallet = { path = "remote-wallet", version = "=4.1.0-alpha.0", default-features = false, features = ["agave-unstable-api"] }
solana-rent = "4.1.0"
solana-reward-info = "5.0.0"
solana-reward-info = "6.0.0"
solana-rpc = { path = "rpc", version = "=4.1.0-alpha.0", features = ["agave-unstable-api"] }
solana-rpc-client = { path = "rpc-client", version = "=4.1.0-alpha.0", default-features = false }
solana-rpc-client-api = { path = "rpc-client-api", version = "=4.1.0-alpha.0" }
Expand Down
58 changes: 57 additions & 1 deletion accounts-db/src/stake_rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,57 @@ impl StakeReward {
}
}

pub fn new_with_pre_stake_account(
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn new_with_pre_stake_account(
#[cfg(feature = "dev-context-only-utils")]
pub fn new_with_pre_stake_account(

'cause it calls Pubkey::unique()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already gated with dev-context-only-utils on line 97

reward_lamports: i64,
stake_lamports: u64,
rent: &Rent,
) -> (AccountSharedData, Self) {
let vote_pubkey = Pubkey::new_unique();
let vote_account = vote_state::create_v4_account_with_authorized(
&Pubkey::new_unique(),
&vote_pubkey,
[0u8; BLS_PUBLIC_KEY_COMPRESSED_SIZE],
&vote_pubkey,
1000,
&vote_pubkey,
0,
&vote_pubkey,
stake_lamports,
);

let rent_exempt_reserve = rent.minimum_balance(StakeStateV2::size_of());
let stake_pubkey = Pubkey::new_unique();
let pre_stake_account = create_stake_account(
&stake_pubkey,
&vote_pubkey,
&vote_account,
rent,
rent_exempt_reserve + stake_lamports,
);
let post_stake_account = create_stake_account(
&stake_pubkey,
&vote_pubkey,
&vote_account,
rent,
rent_exempt_reserve + stake_lamports + reward_lamports as u64,
);

(
pre_stake_account,
Self {
stake_pubkey,
stake_reward_info: StakeRewardInfo {
reward_type: solana_reward_info::RewardType::Staking,
lamports: reward_lamports,
post_balance: 0, /* unused atm */
commission_bps: Some(0), /* unused but tests require some value */
},

stake_account: post_stake_account,
},
)
}

pub fn credit(&mut self, amount: u64) {
self.stake_reward_info.lamports = amount as i64;
self.stake_reward_info.post_balance += amount;
Expand All @@ -160,6 +211,7 @@ fn create_stake_account(
let vote_state =
vote_state::VoteStateV4::deserialize(vote_account.data(), voter_pubkey).unwrap();
let credits_observed = vote_state.credits();
let last_epoch = vote_state.epoch_credits.last().map(|c| c.0).unwrap_or(0);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the _or(0) the right thing to do here? seems like current_epoch - 1 is more correct, but this doesn't not work? just unclear whether it will encourage us to write more misleading tests

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure why not, it can't hurt to pass in the epoch too. I was going with the simplest way to just create a deactivated stake account


let rent_exempt_reserve = rent.minimum_balance(stake_account.data().len());
let stake_amount = lamports
Expand All @@ -172,11 +224,15 @@ fn create_stake_account(
..Meta::default()
};

let stake = Stake {
let mut stake = Stake {
delegation: Delegation::new(voter_pubkey, stake_amount, Epoch::MAX),
credits_observed,
};

if stake_amount == 0 {
stake.delegation.deactivation_epoch = last_epoch;
}

stake_account
.set_state(&StakeStateV2::Stake(meta, stake, StakeFlags::empty()))
.expect("set_state");
Expand Down
4 changes: 2 additions & 2 deletions dev-bins/Cargo.lock

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

8 changes: 8 additions & 0 deletions feature-set/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,10 @@ pub mod block_revenue_sharing {
solana_pubkey::declare_id!("B1ockRevenueSharing111111111111111111111111");
}

pub mod rent_adjusted_delegations {
solana_pubkey::declare_id!("7MYx95UBiJufqnumyN7HfskJ9vKdcGMmhreVguqrE97K");
}

pub mod vote_account_initialize_v2 {
solana_pubkey::declare_id!("VoteAccount1nitia1izeV211111111111111111111");
}
Expand Down Expand Up @@ -2527,6 +2531,10 @@ pub static FEATURE_NAMES: LazyLock<AHashMap<Pubkey, &'static str>> = LazyLock::n
upgrade_bpf_stake_program_to_v5::id(),
"SIMD-0490: Upgrade BPF Stake Program to v5.0.0",
),
(
rent_adjusted_delegations::id(),
"SIMD-0488: Rent-adjusted delegations",
),
/*************** ADD NEW FEATURES HERE ***************/
/***** ADD NEW FEATURE BOOL TO `FeatureSnapshot` *****/
]
Expand Down
4 changes: 2 additions & 2 deletions programs/sbf/Cargo.lock

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

9 changes: 7 additions & 2 deletions rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,9 @@ impl JsonRpcRequestProcessor {
&addresses,
&|reward_type| -> bool {
reward_type == RewardType::Voting
|| (!epoch_has_partitioned_rewards && reward_type == RewardType::Staking)
|| (!epoch_has_partitioned_rewards
&& (reward_type == RewardType::Staking
|| reward_type == RewardType::DeactivatedStake))
Comment on lines +783 to +784
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in retrospect, we should have added a helper on RewardType

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thought did cross my mind 🙃

},
)
.collect()
Expand Down Expand Up @@ -859,7 +861,10 @@ impl JsonRpcRequestProcessor {
block.rewards,
slot,
addresses,
&|reward_type| -> bool { reward_type == RewardType::Staking },
&|reward_type| -> bool {
reward_type == RewardType::Staking
|| reward_type == RewardType::DeactivatedStake
},
);
reward_map.extend(index_reward_map);
}
Expand Down
15 changes: 14 additions & 1 deletion runtime/src/bank/partitioned_epoch_rewards/calculation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ impl Bank {
new_rate_activation_epoch: Option<Epoch>,
delay_commission_updates: bool,
commission_rate_in_basis_points: bool,
adjust_delegations_for_rent: bool,
) -> Option<DelegationRewards> {
// curry closure to add the contextual stake_pubkey
let reward_calc_tracer = reward_calc_tracer.as_ref().map(|outer| {
Expand All @@ -466,6 +467,12 @@ impl Bank {
let vote_state = vote_account.vote_state_view();
let stake_state = stake_account.stake_state();

let current_lamports = stake_account.lamports();
let minimum_lamports = self
.rent_collector
.rent
.minimum_balance(stake_account.data_len());

// Fetch the voter commission from past epochs to attempt to
// delay the effect of commission updates by at least one
// full epoch.
Expand Down Expand Up @@ -499,7 +506,9 @@ impl Bank {
reward_calc_tracer,
new_rate_activation_epoch,
commission_rate_in_basis_points,
stake_account.lamports(),
current_lamports,
minimum_lamports,
adjust_delegations_for_rent,
) {
Ok((stake_reward, commission_lamports, stake)) => {
let stake_reward = PartitionedStakeReward {
Expand Down Expand Up @@ -547,6 +556,9 @@ impl Bank {
let commission_rate_in_basis_points = self
.feature_set
.is_active(&feature_set::commission_rate_in_basis_points::id());
let adjust_delegations_for_rent = self
.feature_set
.is_active(&feature_set::rent_adjusted_delegations::id());

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 @@ -578,6 +590,7 @@ impl Bank {
new_warmup_cooldown_rate_epoch,
delay_commission_updates,
commission_rate_in_basis_points,
adjust_delegations_for_rent,
)
});
let (stake_reward, maybe_reward_record) = match maybe_reward_record {
Expand Down
Loading
Loading