Skip to content
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

refactor(distribution)!: use collections for ValidatorHistoricalRewards state #16607

Merged
merged 25 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove DeleteValidatorHistoricalRewards
  • Loading branch information
unknown unknown committed Jun 19, 2023
commit 51cba3e5de6205b63137bbea14315d654cd7246f
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ require (
// replace (
// <temporary replace>
// )
replace (
cosmossdk.io/collections v0.2.0 => ./collections
)

// Below are the long-lived replace of the Cosmos SDK
replace (
Expand Down
525 changes: 523 additions & 2 deletions go.sum

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ require (
// SimApp on main always tests the latest extracted SDK modules importing the sdk
replace (
cosmossdk.io/client/v2 => ../client/v2
cosmossdk.io/tools/confix => ../tools/confix
testinginprod marked this conversation as resolved.
Show resolved Hide resolved
cosmossdk.io/tools/rosetta => ../tools/rosetta
cosmossdk.io/collections => ../collections
cosmossdk.io/x/circuit => ../x/circuit
cosmossdk.io/x/evidence => ../x/evidence
cosmossdk.io/x/feegrant => ../x/feegrant
Expand Down
513 changes: 513 additions & 0 deletions tests/go.sum

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions x/distribution/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ func (h Hooks) AfterValidatorRemoved(ctx context.Context, _ sdk.ConsAddress, val
h.k.DeleteValidatorSlashEvents(ctx, valAddr)

// clear historical rewards
h.k.DeleteValidatorHistoricalRewards(ctx, valAddr)

err = h.k.ValidatorHistoricalRewards.Clear(ctx, collections.NewPrefixedPairRange[sdk.ValAddress, uint64](valAddr))
if err != nil {
return err
}
// clear current rewards
err = h.k.ValidatorCurrentRewards.Remove(ctx, valAddr)
if err != nil {
Expand Down
10 changes: 0 additions & 10 deletions x/distribution/keeper/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,6 @@ func (k Keeper) SetValidatorHistoricalRewards(ctx context.Context, val sdk.ValAd
return k.ValidatorHistoricalRewards.Set(ctx, collections.Join(val, period), rewards)
}

// delete historical rewards for a validator
func (k Keeper) DeleteValidatorHistoricalRewards(ctx context.Context, val sdk.ValAddress) {
store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
iter := storetypes.KVStorePrefixIterator(store, types.GetValidatorHistoricalRewardsPrefix(val))
defer iter.Close()
for ; iter.Valid(); iter.Next() {
store.Delete(iter.Key())
}
}

// delete all historical rewards
func (k Keeper) DeleteAllValidatorHistoricalRewards(ctx context.Context) {
store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
Expand Down
2 changes: 0 additions & 2 deletions x/evidence/go.sum
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looked weird, so I go mod tidy in this PR: #16616.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Goland EAP does weird things with go.sum I always revert them, this time I forgot. Sorry 🙏

Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,6 @@ github.com/cosmos/cosmos-db v1.0.0 h1:EVcQZ+qYag7W6uorBKFPvX6gRjw6Uq2hIh4hCWjuQ0
github.com/cosmos/cosmos-db v1.0.0/go.mod h1:iBvi1TtqaedwLdcrZVYRSSCb6eSy61NLj4UNmdIgs0U=
github.com/cosmos/cosmos-proto v1.0.0-beta.3 h1:VitvZ1lPORTVxkmF2fAp3IiA61xVwArQYKXTdEcpW6o=
github.com/cosmos/cosmos-proto v1.0.0-beta.3/go.mod h1:t8IASdLaAq+bbHbjq4p960BvcTqtwuAxid3b/2rOD6I=
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230614103911-b3da8bb4e801 h1:Qg0EgcEYtN0RWmxaFWTTCeMDfnbHB6UEzHucafy14i8=
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230614103911-b3da8bb4e801/go.mod h1:VwFzgpv4z/Mrx+0sQpWwURCHx4h/iAalMdKIe3VEyBw=
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230616095813-1111e0b51118 h1:XIBDrJ25Sv4nnO6LspwXQkiMYnlo7j52XCl2KzBMjoQ=
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230616095813-1111e0b51118/go.mod h1:dtE3e607fUxLeDcDwSzKycM0lat8U5BbK/wsAmFk7HI=
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
Expand Down