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
staking: Fix reward distribution when common pool is exhausted #5319
Conversation
de23845
to
3d2aa62
Compare
Codecov Report
@@ Coverage Diff @@
## master #5319 +/- ##
==========================================
- Coverage 66.97% 66.64% -0.33%
==========================================
Files 524 524
Lines 55370 55776 +406
==========================================
+ Hits 37082 37173 +91
- Misses 13771 14017 +246
- Partials 4517 4586 +69
|
@@ -1219,6 +1219,11 @@ func (s *MutableState) AddRewards( | |||
continue | |||
} | |||
|
|||
if q.Cmp(commonPool) == 1 { |
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.
If this condition is true (q > commonPool
), should we lower the reward and give as much as we can (q = commmonPool.Clone()
)?
// If an error occurs, the pool and affected accounts are left in an invalid state.
// This may fail due to the common pool running out of stake.
The method's comment is not correct anymore, as the pool will never run out of stake.
This method is not fair. For example:
- If I have an unlimited escrow balance, my rewards will always be too big and therefore skipped while others will receive their awards until they drain the pool.
- Assuming equal balances and too small pool to cover all rewards, the first in the list will get more rewards than the last one.
However, I'm not sure if this is a problem. If we want fairness, we should distribute the reminder of the pool proportional to stakes. But that is probably too much.
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.
Yeah, we should discuss what to do about this and implement it in a separate PR. This PR just fixes the panic that would have happened otherwise :)
3d2aa62
to
f7246af
Compare
This PR fixes the scenario when the reward schedule hasn't completed yet, but the common pool has been exhausted.