Don't reset credits_observed due to stale voters#13836
Don't reset credits_observed due to stale voters#13836ryoqun merged 3 commits intosolana-labs:masterfrom
Conversation
| // if there is no newer credits since observed, return no point | ||
| if new_vote_state.credits() <= self.credits_observed { | ||
| return (0, 0); | ||
| if fix_stake_deactivate { |
There was a problem hiding this comment.
For testnet, we can freeride on this fix_stake_deactivate flag (backed by already activated stake_program_v2) only after inflation is started.
For mainnet-beta, we are still safe to edit this.
There was a problem hiding this comment.
Strictly speaking, we don't need this fix_stake_deactivate flag at all. That's because we can prove we never use the second item in this returned tuple statically if fix_stake_deactivate = false; this becomes relevant only with fix_stake_deactivate = false. Any I'm adding this for consistency and just be in the safe side.
Codecov Report
@@ Coverage Diff @@
## master #13836 +/- ##
=======================================
Coverage 82.0% 82.0%
=======================================
Files 381 381
Lines 93220 93232 +12
=======================================
+ Hits 76530 76541 +11
- Misses 16690 16691 +1 |
| ) -> (u128, u64) { | ||
| // if there is no newer credits since observed, return no point | ||
| if new_vote_state.credits() <= self.credits_observed { | ||
| return (0, 0); |
There was a problem hiding this comment.
There was a problem hiding this comment.
lessons learnt: never violate invariants (= credits_observed can't be 0) (introduced at #10914, https://github.com/solana-labs/solana/pull/10914/files#r531390890) nevertheless at-the-time code was irrelevant of the violation.
it surely will bite future maintainers like this. (hah, past me bit current me...)
There was a problem hiding this comment.
Oh dang... so obvious in retrospect! How'd I miss that 🤦♂️
|
Combined with #13837, I confirmed this pr fixes this stale stake state (pun intended). |
|
sad, ci passed without chaining the test while I definitely changed implementation code....
vanity metrics here. ;) |
aa6891b to
5d16eaf
Compare
|
well, I'm regarding that it's very rare for these critical bugs to slip through my eyes. So I went to solo postmortem on this incident. In short, I think this was just a fluke. To my best, I had several protection to notice this but all of it failed at once to my surprise. I guess the likelihood is like once in a year... I don't have clear counter-measures against this kind of unnoticed bugs. Alternatively, I think I should be more careful. (too obvious).... Anyway, concluding this as rather a fluke, I believe there should be no more other similar critical bugs due to my lack of general competence. As a detail, I failed to notice this bug at these individual opportunities:
|
t-nelson
left a comment
There was a problem hiding this comment.
LGTM! Just a comment typo nit.
Nice job catching this one!
| ) | ||
| ); | ||
|
|
||
| // credis_observed isn't reset for stale vote accounts while no rewards |
There was a problem hiding this comment.
| // credis_observed isn't reset for stale vote accounts while no rewards | |
| // credits_observed isn't reset for stale vote accounts while no rewards |
There was a problem hiding this comment.
Here's a suggestion for this comment (which I found confusing):
credits_observed remains at previous level when vote_state credits are not advancing and inflation is disabled
There was a problem hiding this comment.
admittedly, I had some difficulty to describe this.. Thank for helping writing. :)
CriesofCarrots
left a comment
There was a problem hiding this comment.
Lgtm too! One suggestion that I think makes that comment a little more clear.
| ) | ||
| ); | ||
|
|
||
| // credis_observed isn't reset for stale vote accounts while no rewards |
There was a problem hiding this comment.
Here's a suggestion for this comment (which I found confusing):
credits_observed remains at previous level when vote_state credits are not advancing and inflation is disabled
|
This needs a v1.4 label right? And just to confirm, we're safe to land this ungated? |
Yeah, I added one. Assuming
Yeah, that should be so. I'll check this now. => EDIT: Yeah, I don't need this; I double-checked this again with testnet/mainnet ledgers to justify the lack of gating. |
Pull request has been modified.
* Don't reset credits_observed due to stale voters * Add tests * Fix comment (cherry picked from commit e81c2c8)
Problem
#13680 resets stake account's
credits_observedto0(returned fromcalculate_points_and_credits()) for stale vote accounts. That makes the stake account is incorrectly eligible for inflation rewords:solana/programs/stake/src/stake_state.rs
Lines 625 to 635 in 0b00a1b
For fun fact, at the next epoch,
credits_observedwill reset back to vote'scredits. Then, yet another next epoch, it'll be again be0. and so on.So, when the inflation is activated at the odd-number after the
stake_program_v2activation, our inflation would be skewed. On the other hand, it won't be skewed at the even-number after the activation.Summary of Changes
credits_observedvalue fromcalculate_points_and_credits()todo
Fixes #