-
Notifications
You must be signed in to change notification settings - Fork 976
runtime: Implement rent-adjusted stake delegations for amended SIMD-0392 (formerly SIMD-0488) #11332
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
base: master
Are you sure you want to change the base?
runtime: Implement rent-adjusted stake delegations for amended SIMD-0392 (formerly SIMD-0488) #11332
Changes from all commits
2175b89
cd71a27
4858056
59aff48
c4ca302
d4a007c
66826a6
a84e8bb
d8a8278
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -139,6 +139,57 @@ impl StakeReward { | |
| } | ||
| } | ||
|
|
||
| pub fn new_with_pre_stake_account( | ||
| 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; | ||
|
|
@@ -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); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
@@ -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"); | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in retrospect, we should have added a helper on
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The thought did cross my mind 🙃 |
||
| }, | ||
| ) | ||
| .collect() | ||
|
|
@@ -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); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'cause it calls
Pubkey::unique()There was a problem hiding this comment.
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-utilson line 97