Repository navigation
SIMD-0599: Remove inactive stakes from stake delegations - #15078
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #15078 +/- ##
========================================
Coverage 82.3% 82.3%
========================================
Files 929 929
Lines 369989 370330 +341
========================================
+ Hits 304743 305048 +305
- Misses 65246 65282 +36 🚀 New features to boost your workflow:
|
262b2a0 to
3ee6925
Compare
|
had to do a nontrivial rebase because fixed point stake math removal landed and this touches all the same stuff, should be good now |
3ee6925 to
44a6aba
Compare
joncinque
left a comment
There was a problem hiding this comment.
This looks really great to me! Dropping from the cache on startup is definitely the right approach.
Just a few small questions on my side
| let delegation = stake_account.delegation(); | ||
| is_delegation_inert( | ||
| delegation, | ||
| self.epoch, | ||
| &self.stake_history, | ||
| new_rate_activation_epoch, | ||
| ) && is_delegation_inert( | ||
| delegation, | ||
| self.epoch.saturating_sub(1), | ||
| &self.stake_history, | ||
| new_rate_activation_epoch, | ||
| ) |
There was a problem hiding this comment.
Sorry if I'm missing something here, but why isn't this check the same as in check_and_store? If we're out of the rewards period, it should always be safe to drop the inactives, right?
There was a problem hiding this comment.
because bank epoch_reward_status is Inactive here. we could read the sysvar directly, or i think we could move this after recalculate_partitioned_rewards_if_active() but it would break if anyone reordered it
There was a problem hiding this comment.
Again, sorry if I'm missing something, but recalculate_partitioned_rewards_if_active fetches the sysvar account to see if it's active, which implies that active field of the sysvar needs to be correct by the time we get into initialize_after_snapshot_restore. That means we can trust it here, and ordering within initialize_after_snapshot_restore shouldn't matter.
There was a problem hiding this comment.
sorry, i meant ordering would matter if we used the bank field, like check_and_store() does. 323ada9 this is using the raw sysvar
There was a problem hiding this comment.
oh gotcha, the newest commit looks great to me!
d3ea736 to
323ada9
Compare
joncinque
left a comment
There was a problem hiding this comment.
Looks great to me! Do you want to get any other reviewers before merging this since we had issues last time?
bw-solana
left a comment
There was a problem hiding this comment.
LGTM. left a couple performance related comments, but they don't need to block
| && activation_status.effective == 0 | ||
| && activation_status.activating == 0 | ||
| { | ||
| inert_stake_delegations.push(**stake_pubkey); |
There was a problem hiding this comment.
if we have a ton of inert stake delegations, seems silly to push way more than 10k here.
could probably do a CAS to detect when we've hit the limit, but that might be worse than the allocations... maybe some lazy CAS updated and checked every 100 entries or something.
but also, that starts sounding a little over-engineered.. if we measure this taking a long time in the field, we can revisit
There was a problem hiding this comment.
yea i didnt want to overdo this since we expect to never have over 10k after the backlog is cleared. even if more than 10k get deactivated in an epoch, they will naturally be cleared when people withdraw in the next epoch, because of my change to do "drop if inactive if not in rewards period, or if inactive now and last epoch" whereas the the previous pr was only the latter rule. so this only needs to cover:
- deactivations where the persion decided to leave all sol in the account
- deactivate delinquent
- deactivations from rent increase
| /// Removes inactive delegations, used when restoring from snapshot. As in | ||
| /// `upsert_stake_delegation`, during the rewards period we keep stakes that | ||
| /// were active last epoch in case they are owed rewards. | ||
| fn remove_inert_stake_delegations( |
There was a problem hiding this comment.
it would be cool to combine this removal with the stakes iteration we already do as part of the refresh_delegated_stakes / calculate_delegated_stakes path
There was a problem hiding this comment.
this is only part of snapshot loading so i didnt want to get fancy, the iteration is like 80ms
ae97949 to
e9458bb
Compare
|
@joncinque re-reqed with no changes, i have to rebase this for merge conflicts like daily @bw-solana should i take your comments to mean you are a full second reviewer? or should i get someone else? we really want another reviewer on this because it was a weeks-long design-by-committee by me jon and ibhatt, so the first version came out less than perfect because it was hard to review by any of us with fresh eyes |
--------- Co-authored-by: Ishan Bhatt <ibhatt@jumptrading.com> Co-authored-by: Jon C <me@jonc.dev>
e9458bb to
9a3e53c
Compare
yes, can count me as the 2nd reviewer. LGTM 👍 |
Problem
we previously tried to impl this (#14394) like so:
points 1 and 3 imposed unacceptable cost, and the pr was reverted (#15029). 1 required hashing all 1.65m stake pubkeys to check against the inactive hashset and pushes epoch time almost to 300ms. 3 would have had to remove 250k entries from imbl on first epoch, which takes 800ms
Summary of Changes
instead we take a new approach:
bench:
we incur another 8ms from the 250k inactives until we clear them. the extra 16ms is the 10k prune. we could turn it down to 5k but i wanted to leave a healthy margin so a backlog doesnt reaccumulate. this only needs to clear inactives that arent touched again: if someone withdraws, even partially, in the next epoch, the stake will be dropped in CAS because of the new epoch rewards logic in my point 4
Testing
we keep ibhatt's
test_inert_delegation_is_not_partitioned_for_rewards(). i improve mytest_inert_delegation_is_removed_from_cache()to cover in-rewards and out-of-rewards, as well as the drop vs decline to insert cases. and addtest_inert_delegation_is_pruned_on_load()to test the snapshot prune path