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

feat: add migration for authorization list #2366

Merged
merged 4 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ start-stress-test: zetanode
#TODO: replace OLD_VERSION with v16 tag once its available
zetanode-upgrade: zetanode
@echo "Building zetanode-upgrade"
$(DOCKER) build -t zetanode:old -f Dockerfile-localnet --target old-runtime --build-arg OLD_VERSION='release/v16' .
$(DOCKER) build -t zetanode:old -f Dockerfile-localnet --target old-runtime --build-arg OLD_VERSION='release/v17' .
$(DOCKER) build -t orchestrator -f contrib/localnet/orchestrator/Dockerfile.fastbuild .
.PHONY: zetanode-upgrade

Expand Down
3 changes: 3 additions & 0 deletions app/setup_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
"github.com/zeta-chain/zetacore/pkg/constant"
emissionstypes "github.com/zeta-chain/zetacore/x/emissions/types"
ibccrosschaintypes "github.com/zeta-chain/zetacore/x/ibccrosschain/types"

authoritytypes "github.com/zeta-chain/zetacore/x/authority/types"
)

func SetupHandlers(app *App) {
Expand Down Expand Up @@ -66,6 +68,7 @@
govtypes.ModuleName,
crisistypes.ModuleName,
emissionstypes.ModuleName,
authoritytypes.ModuleName,

Check warning on line 71 in app/setup_handlers.go

View check run for this annotation

Codecov / codecov/patch

app/setup_handlers.go#L71

Added line #L71 was not covered by tests
}
allUpgrades := upgradeTracker{
upgrades: []upgradeTrackerItem{
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* [2319](https://github.com/zeta-chain/node/pull/2319) - use `CheckAuthorization` function in all messages
* [2325](https://github.com/zeta-chain/node/pull/2325) - revert telemetry server changes
* [2339](https://github.com/zeta-chain/node/pull/2339) - add binaries related question to syncing issue form
* [2366](https://github.com/zeta-chain/node/pull/2366) - add migration script for adding authorizations table

### Refactor

Expand Down
24 changes: 24 additions & 0 deletions x/authority/keeper/migrator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"

v2 "github.com/zeta-chain/zetacore/x/authority/migrations/v2"
)

// Migrator is a struct for handling in-place store migrations.
type Migrator struct {
authorityKeeper Keeper
}

// NewMigrator returns a new Migrator for the authority module.
func NewMigrator(keeper Keeper) Migrator {
return Migrator{
authorityKeeper: keeper,
}
}

// Migrate1to2 migrates the authority store from consensus version 1 to 2
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
return v2.MigrateStore(ctx, m.authorityKeeper)
}
21 changes: 21 additions & 0 deletions x/authority/migrations/v2/migrate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package v2

import (
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/zeta-chain/zetacore/x/authority/types"
)

type authorityKeeper interface {
SetAuthorizationList(ctx sdk.Context, list types.AuthorizationList)
}

// MigrateStore migrates the authority module state from the consensus version 1 to 2
func MigrateStore(
ctx sdk.Context,
keeper authorityKeeper,
) error {
ctx.Logger().Info("Migrating authority store from version 1 to 2")
keeper.SetAuthorizationList(ctx, types.DefaultAuthorizationsList())
return nil
}
28 changes: 28 additions & 0 deletions x/authority/migrations/v2/migrate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package v2_test

import (
"testing"

"github.com/stretchr/testify/require"

keepertest "github.com/zeta-chain/zetacore/testutil/keeper"
v2 "github.com/zeta-chain/zetacore/x/authority/migrations/v2"
"github.com/zeta-chain/zetacore/x/authority/types"
)

func TestMigrateStore(t *testing.T) {
t.Run("Set authorization list", func(t *testing.T) {
k, ctx := keepertest.AuthorityKeeper(t)

list, found := k.GetAuthorizationList(ctx)
require.False(t, found)
require.Equal(t, types.AuthorizationList{}, list)

err := v2.MigrateStore(ctx, *k)
require.NoError(t, err)

list, found = k.GetAuthorizationList(ctx)
require.True(t, found)
require.Equal(t, types.DefaultAuthorizationsList(), list)
})
}
6 changes: 5 additions & 1 deletion x/authority/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ func (am AppModule) Name() string {
func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
types.RegisterQueryServer(cfg.QueryServer(), am.keeper)
m := keeper.NewMigrator(am.keeper)
if err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2); err != nil {
panic(err)
}
}

// RegisterInvariants registers the authority module's invariants.
Expand All @@ -146,7 +150,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
}

// ConsensusVersion implements AppModule/ConsensusVersion.
func (AppModule) ConsensusVersion() uint64 { return 1 }
func (AppModule) ConsensusVersion() uint64 { return 2 }

// BeginBlock executes all ABCI BeginBlock logic respective to the authority module.
func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {}
Expand Down
5 changes: 5 additions & 0 deletions x/authority/types/authorization_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ func TestAuthorizationList_Validate(t *testing.T) {
authorizations types.AuthorizationList
expectedError error
}{
{
name: "validate default authorizations list",
authorizations: types.DefaultAuthorizationsList(),
expectedError: nil,
},
{
name: "validate successfully",
authorizations: types.AuthorizationList{Authorizations: []types.Authorization{
Expand Down
Loading