-
Notifications
You must be signed in to change notification settings - Fork 33
wip: pay rewards #607
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?
wip: pay rewards #607
Conversation
53aebe8 to
c2bf3d0
Compare
c2bf3d0 to
817e89b
Compare
| let mut accounts = Arc::unwrap_or_clone(self.vote_accounts()); | ||
| let (_stake, account) = accounts.remove(&voter).unwrap(); | ||
| let data = account.account().data_clone(); | ||
| let mut vote_state: VoteStateV3 = bincode::deserialize(&data).unwrap(); |
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.
We want to be targetting VoteStateV4 here
| let shared_account = | ||
| AccountSharedData::new_data(account.lamports(), &vote_state, account.owner()).unwrap(); | ||
| // XXX: is the stake getting set properly? | ||
| self.store_account(&voter, &shared_account); |
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.
Generally prefer store_accounts when storing multiple accounts as AccountsDB is able to use its thread pool to do some of the stuff in parallel.
| // XXX: pay the leader rewards | ||
| let _leader_reward_lamports = reward_lamports - validator_reward_lamports; | ||
|
|
||
| bank.pay_vote_reward(validator, validator_reward_lamports); |
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 isn't quite correct as credits != lamports.
Here's how inflationary rewards are calculated. Let V be the validator set:
Let
points(v) = credits(v) * stake(v) for any validator v
If the total inflation this epoch is T
rewards(v) = T * points(v) / Sum_{u \in V}(points(u))
You can see the full details by poking around in the caller of
| pub(crate) fn calculate_stake_points_and_credits( |
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.
We no longer want the sum of points in the denominator as in Alpenglow rewards are not based on relative performance.
When alpenglow is active we'll want to replace that with 432000 (slots per epoch) * total stake and then I believe you can just add 1 credit here.
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.
Sorry I realized that the leader also needs to be paid out for the same sol value. This is difficult because the leader's point calculation will multiply by the leader's stake rather than the voter's stake.
I'll need to think more about how to solve the leader's side of rewards.
| } | ||
|
|
||
| pub(crate) fn pay_vote_reward(&self, voter: Pubkey, reward: u64) { | ||
| let mut accounts = Arc::unwrap_or_clone(self.vote_accounts()); |
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.
Might be able to avoid some of these clones with something like this
let Some((_, vote_account)) = self.vote_accounts().get(&voter) else {
return;
};
let mut vote_state: VoteStateV4 = vote_account.account().deserialize_data();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.
We could even avoid the deserialize and calculate the offset into epoch credits to update if necessary.
Problem
Summary of Changes
Fixes #