-
Notifications
You must be signed in to change notification settings - Fork 94
imp(costaking): track baby staked to active validators #1776
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
Conversation
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.
Pull Request Overview
This PR modifies the co-staking tracking system to only track baby tokens staked to active validators, implementing proper validator set management and epoch-based transitions.
Key changes:
- Only process delegation hooks for active validators (using
IterateLastValidatorPowers
) - Add epoch-end hook to handle validator transitions between active/inactive states
- Update initialization logic to consider validator active status
Reviewed Changes
Copilot reviewed 12 out of 13 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
x/costaking/types/staking_cache.go | Add active validator set caching functionality |
x/costaking/types/mocked_keepers.go | Add mock methods for validator delegations and power iteration |
x/costaking/types/expected_keepers.go | Add required staking keeper interface methods |
x/costaking/keeper/hooks_staking_test.go | Add comprehensive tests for active/inactive validator scenarios |
x/costaking/keeper/hooks_staking.go | Implement active validator checks in delegation hooks |
x/costaking/keeper/hooks_epoching_test.go | Add tests for epoch-based validator transitions |
x/costaking/keeper/hooks_epoching.go | Implement epoch hooks for validator state transitions |
test/e2ev2/tmanager/genesis.go | Remove trailing whitespace |
app/upgrades/v4/upgrades_costaking_test.go | Update tests to properly handle active validator scenarios |
app/upgrades/v4/upgrades.go | Update initialization to only process active validators |
app/keepers/keepers.go | Register co-staking epoch hooks |
CHANGELOG.md | Add entry for the change |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
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.
In general looks good 👍 I have some doubts about the caching thing, which seems to be making some implicit assumptions when cache is filled.
Also, do you think it is feasible to create some e2e test in which we have 2 validators and we jail one of them to see that active baby drops to 0 for certain delegators ?
Sure, will work on this |
Note that the upgrade with these changes should be done at epoch boundary to store the validator set data on upgrading |
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.
Pull Request Overview
Copilot reviewed 40 out of 41 changed files in this pull request and generated 4 comments.
Comments suppressed due to low confidence (1)
x/costaking/keeper/hooks_staking.go:1
- This function doesn't use the provided
valInfo
parameter for token calculation, making the parameter misleading. Consider either usingvalInfo
data or removing it from the signature.
package keeper
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
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.
LGTM, good job @GAtom22 🎉
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.
Looks good, great job finding all edge cases and adding all tests 👍
Just one question, related to iterating over maps.
# Description Currently `AfterDelegationModified` hook will update co-staking tracker no matter val status This PR introduces the changes to hooks when delegation modified: - ONLY update baby amt in co-staking tracker if validator was in active set - using `staking.IterateLastValidatorPowers` Later on, `AfterEpochEnds` hook: - get newly active and inactive validators from: - cached `staking.IterateLastValidatorPowers` - is the prev-epoch validator set - `staking.IterateLastValidatorPowers` - returns the new epoch validators (updated before calling the hook) - if validator becomes inactive: - In case was add before - OK, will reduce the corresponding total amount - In case was reduced before - OK, will reduce the remaining (validator delegations already updated) - if validator becomes active: - update all delegators co-staking trackers --------- Co-authored-by: RafilxTenfen <rafaeltenfen.rt@gmail.com> (cherry picked from commit c8277ad)
… (#1798) # Description Currently `AfterDelegationModified` hook will update co-staking tracker no matter val status This PR introduces the changes to hooks when delegation modified: - ONLY update baby amt in co-staking tracker if validator was in active set - using `staking.IterateLastValidatorPowers` Later on, `AfterEpochEnds` hook: - get newly active and inactive validators from: - cached `staking.IterateLastValidatorPowers` - is the prev-epoch validator set - `staking.IterateLastValidatorPowers` - returns the new epoch validators (updated before calling the hook) - if validator becomes inactive: - In case was add before - OK, will reduce the corresponding total amount - In case was reduced before - OK, will reduce the remaining (validator delegations already updated) - if validator becomes active: - update all delegators co-staking trackers <hr>This is an automatic backport of pull request #1776 done by [Mergify](https://mergify.com). Co-authored-by: Tom <54514587+GAtom22@users.noreply.github.com> Co-authored-by: RafilxTenfen <rafaeltenfen.rt@gmail.com>
Description
Currently
AfterDelegationModified
hook will update co-staking tracker no matter val statusThis PR introduces the changes to hooks when delegation modified:
staking.IterateLastValidatorPowers
Later on,
AfterEpochEnds
hook:staking.IterateLastValidatorPowers
- is the prev-epoch validator setstaking.IterateLastValidatorPowers
- returns the new epoch validators (updated before calling the hook)