diff --git a/app/setup_handlers.go b/app/setup_handlers.go index 8619fa046f..bdb18a0aa8 100644 --- a/app/setup_handlers.go +++ b/app/setup_handlers.go @@ -5,6 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/upgrade/types" + observerTypes "github.com/zeta-chain/zetacore/x/observer/types" ) const releaseVersion = "v12.1.0" @@ -16,6 +17,8 @@ func SetupHandlers(app *App) { for m, mb := range app.mm.Modules { vm[m] = mb.ConsensusVersion() } + vm = VersionMigrator{vm}.TriggerMigration(observerTypes.ModuleName) + return app.mm.RunMigrations(ctx, app.configurator, vm) }) @@ -34,3 +37,12 @@ func SetupHandlers(app *App) { app.SetStoreLoader(types.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades)) } } + +type VersionMigrator struct { + v module.VersionMap +} + +func (v VersionMigrator) TriggerMigration(moduleName string) module.VersionMap { + v.v[moduleName] = v.v[moduleName] - 1 + return v.v +} diff --git a/changelog.md b/changelog.md index 01cee846e4..1adfa29044 100644 --- a/changelog.md +++ b/changelog.md @@ -5,16 +5,15 @@ ## Version: v12.1.0 ### Tests - * [1577](https://github.com/zeta-chain/node/pull/1577) - add chain header tests in E2E tests and fix admin tests ### Features ### Fixes - * [1535](https://github.com/zeta-chain/node/issues/1535) - Avoid voting on wrong ballots due to false blockNumber in EVM tx receipt * [1588](https://github.com/zeta-chain/node/pull/1588) - fix chain params comparison logic * [1650](https://github.com/zeta-chain/node/pull/1605) - exempt (discounted) *system txs* from min gas price check and gas fee deduction +* [1632](https://github.com/zeta-chain/node/pull/1632) - set keygen to `KeygenStatus_KeyGenSuccess` if its in `KeygenStatus_PendingKeygen`. * [1576](https://github.com/zeta-chain/node/pull/1576) - Fix zetaclient crash due to out of bound integer conversion and log prints. * [1575](https://github.com/zeta-chain/node/issues/1575) - Skip unsupported chain parameters by IsSupported flag diff --git a/x/observer/keeper/migrator.go b/x/observer/keeper/migrator.go index 47b8ecfcc7..0cee0ed183 100644 --- a/x/observer/keeper/migrator.go +++ b/x/observer/keeper/migrator.go @@ -6,6 +6,7 @@ import ( v3 "github.com/zeta-chain/zetacore/x/observer/migrations/v3" v4 "github.com/zeta-chain/zetacore/x/observer/migrations/v4" v5 "github.com/zeta-chain/zetacore/x/observer/migrations/v5" + v6 "github.com/zeta-chain/zetacore/x/observer/migrations/v6" ) // Migrator is a struct for handling in-place store migrations. @@ -37,3 +38,7 @@ func (m Migrator) Migrate3to4(ctx sdk.Context) error { func (m Migrator) Migrate4to5(ctx sdk.Context) error { return v5.MigrateStore(ctx, m.observerKeeper) } + +func (m Migrator) Migrate5to6(ctx sdk.Context) error { + return v6.MigrateStore(ctx, m.observerKeeper) +} diff --git a/x/observer/migrations/v6/migrate.go b/x/observer/migrations/v6/migrate.go new file mode 100644 index 0000000000..a678c8a54d --- /dev/null +++ b/x/observer/migrations/v6/migrate.go @@ -0,0 +1,39 @@ +package v6 + +import ( + "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/zeta-chain/zetacore/x/observer/types" +) + +// observerKeeper prevents circular dependency +type observerKeeper interface { + SetKeygen(ctx sdk.Context, keygen types.Keygen) + GetKeygen(ctx sdk.Context) (val types.Keygen, found bool) + GetTSS(ctx sdk.Context) (val types.TSS, found bool) + StoreKey() storetypes.StoreKey + Codec() codec.BinaryCodec +} + +func MigrateStore(ctx sdk.Context, observerKeeper observerKeeper) error { + return SetKeyGenStatus(ctx, observerKeeper) +} + +func SetKeyGenStatus(ctx sdk.Context, keeper observerKeeper) error { + keygen, found := keeper.GetKeygen(ctx) + if !found { + return types.ErrKeygenNotFound + } + if keygen.Status == types.KeygenStatus_PendingKeygen { + tss, foundTss := keeper.GetTSS(ctx) + if !foundTss { + return types.ErrTssNotFound + } + keygen.Status = types.KeygenStatus_KeyGenSuccess + keygen.BlockNumber = tss.KeyGenZetaHeight + keygen.GranteePubkeys = tss.TssParticipantList + keeper.SetKeygen(ctx, keygen) + } + return nil +} diff --git a/x/observer/migrations/v6/migrate_test.go b/x/observer/migrations/v6/migrate_test.go new file mode 100644 index 0000000000..574ece4be4 --- /dev/null +++ b/x/observer/migrations/v6/migrate_test.go @@ -0,0 +1,87 @@ +package v6_test + +import ( + "math" + "testing" + + "github.com/stretchr/testify/assert" + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + v6 "github.com/zeta-chain/zetacore/x/observer/migrations/v6" + "github.com/zeta-chain/zetacore/x/observer/types" +) + +func TestMigrateObserverParams(t *testing.T) { + t.Run("Migrate when keygen is Pending", func(t *testing.T) { + k, ctx := keepertest.ObserverKeeper(t) + k.SetKeygen(ctx, types.Keygen{ + Status: types.KeygenStatus_PendingKeygen, + BlockNumber: math.MaxInt64, + }) + participantList := []string{ + "zetapub1addwnpepqglunjrgl3qg08duxq9pf28jmvrer3crwnnfzp6m0u0yh9jk9mnn5p76utc", + "zetapub1addwnpepqwwpjwwnes7cywfkr0afme7ymk8rf5jzhn8pfr6qqvfm9v342486qsrh4f5", + "zetapub1addwnpepq07xj82w5e6vr85qj3r7htmzh2mp3vkvfraapcv6ynhdwankseayk5yh80t", + "zetapub1addwnpepq0lxqx92m3fhae3usn8jffqvtx6cuzl06xh9r345c2qcqq8zyfs4cdpqcum", + "zetapub1addwnpepqvzlntzltvpm22ved5gjtn9nzqfz5fun38el4r64njc979rwanxlgq4u3p8", + "zetapub1addwnpepqg40psrhwwgy257p4xv50xp0asmtwjup66z8vk829289zxge5lyl7sycga8", + "zetapub1addwnpepqgpr5ffquqchra93r8l6d35q62cv4nsc9d4k2q7kten4sljxg5rluwx29gh", + "zetapub1addwnpepqdjf3vt8etgdddkghrvxfmmmeatky6m7hx7wjuv86udfghqpty8h5h4r78w", + "zetapub1addwnpepqtfcfmsdkzdgv03t8392gsh7kzrstp9g864w2ltz9k0xzz33q60dq6mnkex", + } + operatorList := []string{ + "zeta19jr7nl82lrktge35f52x9g5y5prmvchmk40zhg", + "zeta1cxj07f3ju484ry2cnnhxl5tryyex7gev0yzxtj", + "zeta1hjct6q7npsspsg3dgvzk3sdf89spmlpf7rqmnw", + "zeta1k6vh9y7ctn06pu5jngznv5dyy0rltl2qp0j30g", + "zeta1l07weaxkmn6z69qm55t53v4rfr43eys4cjz54h", + "zeta1p0uwsq4naus5r4l7l744upy0k8ezzj84mn40nf", + "zeta1rhj4pkp7eygw8lu9wacpepeh0fnzdxrqr27g6m", + "zeta1t0uj2z93jd2g3w94zl3jhfrn2ek6dnuk3v93j9", + "zeta1t5pgk2fucx3drkynzew9zln5z9r7s3wqqyy0pe", + } + keygenHeight := int64(1440460) + finalizedZetaHeight := int64(1440680) + k.SetTSS(ctx, types.TSS{ + KeyGenZetaHeight: keygenHeight, + TssParticipantList: participantList, + TssPubkey: "zetapub1addwnpepqtadxdyt037h86z60nl98t6zk56mw5zpnm79tsmvspln3hgt5phdc79kvfc", + OperatorAddressList: operatorList, + FinalizedZetaHeight: finalizedZetaHeight, + }) + err := v6.MigrateStore(ctx, k) + assert.NoError(t, err) + keygen, found := k.GetKeygen(ctx) + assert.True(t, found) + assert.Equal(t, types.KeygenStatus_KeyGenSuccess, keygen.Status) + assert.Equal(t, keygenHeight, keygenHeight) + assert.Equal(t, participantList, participantList) + }) + t.Run("Migrate when keygen is not Pending", func(t *testing.T) { + k, ctx := keepertest.ObserverKeeper(t) + participantList := []string{ + "zetapub1addwnpepqglunjrgl3qg08duxq9pf28jmvrer3crwnnfzp6m0u0yh9jk9mnn5p76utc", + "zetapub1addwnpepqwwpjwwnes7cywfkr0afme7ymk8rf5jzhn8pfr6qqvfm9v342486qsrh4f5", + "zetapub1addwnpepq07xj82w5e6vr85qj3r7htmzh2mp3vkvfraapcv6ynhdwankseayk5yh80t", + "zetapub1addwnpepq0lxqx92m3fhae3usn8jffqvtx6cuzl06xh9r345c2qcqq8zyfs4cdpqcum", + "zetapub1addwnpepqvzlntzltvpm22ved5gjtn9nzqfz5fun38el4r64njc979rwanxlgq4u3p8", + "zetapub1addwnpepqg40psrhwwgy257p4xv50xp0asmtwjup66z8vk829289zxge5lyl7sycga8", + "zetapub1addwnpepqgpr5ffquqchra93r8l6d35q62cv4nsc9d4k2q7kten4sljxg5rluwx29gh", + "zetapub1addwnpepqdjf3vt8etgdddkghrvxfmmmeatky6m7hx7wjuv86udfghqpty8h5h4r78w", + "zetapub1addwnpepqtfcfmsdkzdgv03t8392gsh7kzrstp9g864w2ltz9k0xzz33q60dq6mnkex", + } + keygenHeight := int64(1440460) + k.SetKeygen(ctx, types.Keygen{ + Status: types.KeygenStatus_KeyGenSuccess, + BlockNumber: keygenHeight, + GranteePubkeys: participantList, + }) + err := v6.MigrateStore(ctx, k) + assert.NoError(t, err) + keygen, found := k.GetKeygen(ctx) + assert.True(t, found) + assert.Equal(t, types.KeygenStatus_KeyGenSuccess, keygen.Status) + assert.Equal(t, keygen.BlockNumber, keygenHeight) + assert.Equal(t, keygen.GranteePubkeys, participantList) + }) + +} diff --git a/x/observer/module.go b/x/observer/module.go index 563b5188ea..8e4e750608 100644 --- a/x/observer/module.go +++ b/x/observer/module.go @@ -156,6 +156,9 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { if err := cfg.RegisterMigration(types.ModuleName, 4, m.Migrate4to5); err != nil { panic(err) } + if err := cfg.RegisterMigration(types.ModuleName, 5, m.Migrate5to6); err != nil { + panic(err) + } } // RegisterInvariants registers the observer module's invariants. @@ -180,7 +183,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw } // ConsensusVersion implements ConsensusVersion. -func (AppModule) ConsensusVersion() uint64 { return 5 } +func (AppModule) ConsensusVersion() uint64 { return 6 } // BeginBlock executes all ABCI BeginBlock logic respective to the observer module. func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { diff --git a/x/observer/types/errors.go b/x/observer/types/errors.go index 8918b08e7f..fd61f4ea4d 100644 --- a/x/observer/types/errors.go +++ b/x/observer/types/errors.go @@ -36,4 +36,5 @@ var ( ErrParamsMinObserverDelegation = errorsmod.Register(ModuleName, 1128, "min observer delegation cannot be nil") ErrMinDelegationNotFound = errorsmod.Register(ModuleName, 1129, "min delegation not found") ErrObserverSetNotFound = errorsmod.Register(ModuleName, 1130, "observer set not found") + ErrTssNotFound = errorsmod.Register(ModuleName, 1131, "tss not found") )