From eccd52e40864f394470cd8b1f85487ff8e6f38ba Mon Sep 17 00:00:00 2001 From: Tanmay Date: Fri, 7 Jun 2024 15:53:53 -0400 Subject: [PATCH 1/4] add migration for authorization list --- x/authority/keeper/migrator.go | 23 +++++++++++++++++ x/authority/migrations/v2/migrate.go | 20 +++++++++++++++ x/authority/migrations/v2/migrate_test.go | 27 ++++++++++++++++++++ x/authority/module.go | 6 ++++- x/authority/types/authorization_list_test.go | 5 ++++ 5 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 x/authority/keeper/migrator.go create mode 100644 x/authority/migrations/v2/migrate.go create mode 100644 x/authority/migrations/v2/migrate_test.go diff --git a/x/authority/keeper/migrator.go b/x/authority/keeper/migrator.go new file mode 100644 index 0000000000..74085f6c54 --- /dev/null +++ b/x/authority/keeper/migrator.go @@ -0,0 +1,23 @@ +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) +} diff --git a/x/authority/migrations/v2/migrate.go b/x/authority/migrations/v2/migrate.go new file mode 100644 index 0000000000..9f5b7aaf80 --- /dev/null +++ b/x/authority/migrations/v2/migrate.go @@ -0,0 +1,20 @@ +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 +} diff --git a/x/authority/migrations/v2/migrate_test.go b/x/authority/migrations/v2/migrate_test.go new file mode 100644 index 0000000000..ee82f004ae --- /dev/null +++ b/x/authority/migrations/v2/migrate_test.go @@ -0,0 +1,27 @@ +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) + }) +} diff --git a/x/authority/module.go b/x/authority/module.go index f92da86e37..696c9c1edb 100644 --- a/x/authority/module.go +++ b/x/authority/module.go @@ -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. @@ -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) {} diff --git a/x/authority/types/authorization_list_test.go b/x/authority/types/authorization_list_test.go index ee301c92d6..4a1cf701e8 100644 --- a/x/authority/types/authorization_list_test.go +++ b/x/authority/types/authorization_list_test.go @@ -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{ From e1b8c14631003fd77f53fc262a5bccaf289141b9 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Fri, 21 Jun 2024 12:10:44 -0400 Subject: [PATCH 2/4] add changelog --- Makefile | 2 +- changelog.md | 1 + x/authority/keeper/migrator.go | 1 + x/authority/migrations/v2/migrate.go | 1 + x/authority/migrations/v2/migrate_test.go | 1 + 5 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 75834d690d..858efad24a 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/changelog.md b/changelog.md index 9d439de407..70116d7939 100644 --- a/changelog.md +++ b/changelog.md @@ -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 diff --git a/x/authority/keeper/migrator.go b/x/authority/keeper/migrator.go index 74085f6c54..9edf014b1d 100644 --- a/x/authority/keeper/migrator.go +++ b/x/authority/keeper/migrator.go @@ -2,6 +2,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + v2 "github.com/zeta-chain/zetacore/x/authority/migrations/v2" ) diff --git a/x/authority/migrations/v2/migrate.go b/x/authority/migrations/v2/migrate.go index 9f5b7aaf80..5b9bbd3d83 100644 --- a/x/authority/migrations/v2/migrate.go +++ b/x/authority/migrations/v2/migrate.go @@ -2,6 +2,7 @@ package v2 import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/zeta-chain/zetacore/x/authority/types" ) diff --git a/x/authority/migrations/v2/migrate_test.go b/x/authority/migrations/v2/migrate_test.go index ee82f004ae..d8cbdbf6fe 100644 --- a/x/authority/migrations/v2/migrate_test.go +++ b/x/authority/migrations/v2/migrate_test.go @@ -4,6 +4,7 @@ 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" From f4330ece3c3535d8ce38bd11bfae75045cbe23f6 Mon Sep 17 00:00:00 2001 From: Alex Gartner Date: Mon, 24 Jun 2024 13:59:29 -0700 Subject: [PATCH 3/4] add forced migration to fix upgrade tests --- app/setup_handlers.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/setup_handlers.go b/app/setup_handlers.go index 7fe7bc1f8f..437b7a49c1 100644 --- a/app/setup_handlers.go +++ b/app/setup_handlers.go @@ -26,6 +26,8 @@ import ( "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) { @@ -66,6 +68,7 @@ func SetupHandlers(app *App) { govtypes.ModuleName, crisistypes.ModuleName, emissionstypes.ModuleName, + authoritytypes.ModuleName, } allUpgrades := upgradeTracker{ upgrades: []upgradeTrackerItem{ From b5e978d051aec2ed7a33a47976e3b33a4d77832c Mon Sep 17 00:00:00 2001 From: Alex Gartner Date: Mon, 24 Jun 2024 14:44:30 -0700 Subject: [PATCH 4/4] make fmt --- app/setup_handlers.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/setup_handlers.go b/app/setup_handlers.go index 437b7a49c1..df6ef31c9b 100644 --- a/app/setup_handlers.go +++ b/app/setup_handlers.go @@ -24,10 +24,9 @@ import ( "golang.org/x/exp/slices" "github.com/zeta-chain/zetacore/pkg/constant" + authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" 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) {