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(x/signal): reset all versions via ResetTally #3277

Merged
merged 12 commits into from
Apr 16, 2024
1 change: 1 addition & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
version: v1.57.0
args: --timeout 10m
github-token: ${{ secrets.github_token }}
skip-pkg-cache: true
if: env.GIT_DIFF

# hadolint lints the Dockerfile
Expand Down
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ func (app *App) Upgrade(ctx sdk.Context, fromVersion, toVersion uint64) error {
app.SetInitialAppVersionInConsensusParams(ctx, toVersion)
}
app.SetAppVersion(ctx, toVersion)
app.SignalKeeper.ResetTally(ctx)
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion specs/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
- [blobstream](https://github.com/celestiaorg/celestia-app/blob/main/x/blobstream/README.md)
- [mint](https://github.com/celestiaorg/celestia-app/blob/main/x/mint/README.md)
- [paramfilter](https://github.com/celestiaorg/celestia-app/blob/main/x/paramfilter/README.md)
- [upgrade](https://github.com/celestiaorg/celestia-app/blob/main/x/upgrade/README.md)
- [signal](https://github.com/celestiaorg/celestia-app/blob/main/x/signal/README.md)
- [tokenfilter](https://github.com/celestiaorg/celestia-app/blob/main/x/tokenfilter/README.md)
- [Mainnet Parameters](./specs/params.md)
2 changes: 1 addition & 1 deletion specs/src/specs/state_machine_modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Celestia app is built using the cosmos-sdk, and follows standard cosmos-sdk modu
- [minfee](https://github.com/celestiaorg/celestia-app/blob/main/x/minfee/README.md)
- [mint](https://github.com/celestiaorg/celestia-app/blob/main/x/mint/README.md)
- [paramfilter](https://github.com/celestiaorg/celestia-app/blob/main/x/paramfilter/README.md)
- [upgrade](https://github.com/celestiaorg/celestia-app/blob/main/x/upgrade/README.md)
- [signal](https://github.com/celestiaorg/celestia-app/blob/main/x/signal/README.md)
- [tokenfilter](https://github.com/celestiaorg/celestia-app/blob/main/x/tokenfilter/README.md)

## Standard `cosmos-sdk` Modules
Expand Down
12 changes: 4 additions & 8 deletions x/signal/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,14 @@ func (k *Keeper) ShouldUpgrade() (bool, uint64) {
return k.quorumVersion != 0, k.quorumVersion
}

// ResetTally resets the tally after a version change. It iterates over the store,
// and deletes any versions that are less than the provided version. It also
// resets the quorumVersion to 0.
func (k *Keeper) ResetTally(ctx sdk.Context, version uint64) {
// ResetTally resets the tally after a version change. It iterates over the
// store and deletes all versions. It also resets the quorumVersion to 0.
func (k *Keeper) ResetTally(ctx sdk.Context) {
store := ctx.KVStore(k.storeKey)
iterator := store.Iterator(nil, nil)
defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
v := VersionFromBytes(iterator.Value())
if v <= version {
store.Delete(iterator.Key())
}
store.Delete(iterator.Key())
}
k.quorumVersion = 0
}
Expand Down
30 changes: 29 additions & 1 deletion x/signal/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func TestTallyingLogic(t *testing.T) {
require.Error(t, err)

// resetting the tally should clear other votes
upgradeKeeper.ResetTally(ctx, 2)
upgradeKeeper.ResetTally(ctx)
res, err = upgradeKeeper.VersionTally(goCtx, &types.QueryVersionTallyRequest{
Version: 2,
})
Expand Down Expand Up @@ -258,6 +258,34 @@ func TestThresholdVotingPower(t *testing.T) {
}
}

// TestResetTally verifies that the VotingPower for all versions is reset to
// zero after calling ResetTally.
func TestResetTally(t *testing.T) {
upgradeKeeper, ctx, _ := setup(t)

_, err := upgradeKeeper.SignalVersion(ctx, &types.MsgSignalVersion{ValidatorAddress: testutil.ValAddrs[0].String(), Version: 1})
require.NoError(t, err)
resp, err := upgradeKeeper.VersionTally(ctx, &types.QueryVersionTallyRequest{Version: 1})
require.NoError(t, err)
assert.Equal(t, uint64(40), resp.VotingPower)

_, err = upgradeKeeper.SignalVersion(ctx, &types.MsgSignalVersion{ValidatorAddress: testutil.ValAddrs[1].String(), Version: 2})
require.NoError(t, err)
resp, err = upgradeKeeper.VersionTally(ctx, &types.QueryVersionTallyRequest{Version: 2})
require.NoError(t, err)
assert.Equal(t, uint64(1), resp.VotingPower)

upgradeKeeper.ResetTally(ctx)

resp, err = upgradeKeeper.VersionTally(ctx, &types.QueryVersionTallyRequest{Version: 1})
require.NoError(t, err)
assert.Equal(t, uint64(0), resp.VotingPower)

resp, err = upgradeKeeper.VersionTally(ctx, &types.QueryVersionTallyRequest{Version: 2})
require.NoError(t, err)
assert.Equal(t, uint64(0), resp.VotingPower)
}

func setup(t *testing.T) (signal.Keeper, sdk.Context, *mockStakingKeeper) {
signalStore := sdk.NewKVStoreKey(types.StoreKey)
db := tmdb.NewMemDB()
Expand Down
Loading