Skip to content

Conversation

GAtom22
Copy link
Contributor

@GAtom22 GAtom22 commented Oct 3, 2025

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

@GAtom22 GAtom22 marked this pull request as ready for review October 3, 2025 21:24
Copy link
Contributor

@Copilot Copilot AI left a 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.

Copy link
Collaborator

@KonradStaniec KonradStaniec left a 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 ?

@GAtom22
Copy link
Contributor Author

GAtom22 commented Oct 6, 2025

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

@GAtom22
Copy link
Contributor Author

GAtom22 commented Oct 8, 2025

Note that the upgrade with these changes should be done at epoch boundary to store the validator set data on upgrading

@GAtom22 GAtom22 requested a review from Copilot October 8, 2025 23:21
Copy link
Contributor

@Copilot Copilot AI left a 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 using valInfo 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.

Copy link
Contributor

@RafilxTenfen RafilxTenfen left a 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 🎉

Copy link
Collaborator

@KonradStaniec KonradStaniec left a 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.

@GAtom22 GAtom22 merged commit c8277ad into main Oct 9, 2025
32 checks passed
@GAtom22 GAtom22 deleted the GAtom22/costk-val-set branch October 9, 2025 16:06
mergify bot pushed a commit that referenced this pull request Oct 9, 2025
# 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)
GAtom22 added a commit that referenced this pull request Oct 9, 2025
… (#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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants