From 5b46508afacc8a0c46804970d07ff2bbb76e0b43 Mon Sep 17 00:00:00 2001 From: ryanbajollari <54822716+rbajollari@users.noreply.github.com> Date: Fri, 26 Jul 2024 05:22:49 -0400 Subject: [PATCH 1/3] chore: v0.3.2 upgrade handler (#481) * chore: v0.3.2 upgrade handler * convert proposals * lint * migrate proposal test (cherry picked from commit faac05508f4f9aa340310f7f5aab38597f7d0ae6) # Conflicts: # app/upgrades.go --- app/upgrades.go | 28 ++++++++- x/oracle/keeper/migrate_proposal.go | 72 ++++++++++++++++++++++++ x/oracle/keeper/migrate_proposal_test.go | 52 +++++++++++++++++ 3 files changed, 150 insertions(+), 2 deletions(-) create mode 100644 x/oracle/keeper/migrate_proposal.go create mode 100644 x/oracle/keeper/migrate_proposal_test.go diff --git a/app/upgrades.go b/app/upgrades.go index 74fb4e00..6d1b8900 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -10,7 +10,6 @@ import ( consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types" crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" - govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" @@ -40,6 +39,11 @@ func (app App) RegisterUpgradeHandlers() { app.registerUpgrade0_3_1Rc1(upgradeInfo) app.registerUpgrade0_3_1Rc2(upgradeInfo) app.registerUpgrade0_3_1(upgradeInfo) +<<<<<<< HEAD +======= + app.registerUpgrade0_3_2(upgradeInfo) + app.registerUpgrade0_4_0(upgradeInfo) +>>>>>>> faac055 (chore: v0.3.2 upgrade handler (#481)) } // performs upgrade from v0.1.3 to v0.1.4 @@ -189,12 +193,32 @@ func (app *App) registerUpgrade0_3_1(_ upgradetypes.Plan) { const planName = "v0.3.1" app.UpgradeKeeper.SetUpgradeHandler(planName, +<<<<<<< HEAD func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { // migrate old proposals govMigrator := govkeeper.NewMigrator(&app.GovKeeper, app.GetSubspace(govtypes.ModuleName)) err := govMigrator.Migrate2to3(ctx) +======= + func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + sdkCtx := sdk.UnwrapSDKContext(ctx) + sdkCtx.Logger().Info("Upgrade handler execution", "name", planName) + return app.mm.RunMigrations(ctx, app.configurator, fromVM) + }, + ) +} + +func (app *App) registerUpgrade0_3_2(_ upgradetypes.Plan) { + const planName = "v0.3.2" + + app.UpgradeKeeper.SetUpgradeHandler(planName, + func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + sdkCtx := sdk.UnwrapSDKContext(ctx) + + // migrate old proposals + err := oraclekeeper.MigrateProposals(sdkCtx, app.keys[govtypes.StoreKey], app.appCodec) +>>>>>>> faac055 (chore: v0.3.2 upgrade handler (#481)) if err != nil { - panic("failed to migrate governance module") + sdkCtx.Logger().Error("failed to migrate governance proposals", "err", err) } ctx.Logger().Info("Upgrade handler execution", "name", planName) diff --git a/x/oracle/keeper/migrate_proposal.go b/x/oracle/keeper/migrate_proposal.go new file mode 100644 index 00000000..bb9b8ae3 --- /dev/null +++ b/x/oracle/keeper/migrate_proposal.go @@ -0,0 +1,72 @@ +package keeper + +import ( + "cosmossdk.io/store/prefix" + storetypes "cosmossdk.io/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + v1migrations "github.com/cosmos/cosmos-sdk/x/gov/migrations/v1" + + "github.com/cosmos/cosmos-sdk/codec" + govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + oracletypes "github.com/ojo-network/ojo/x/oracle/types" +) + +// MigrateProposals migrates all legacy MsgUpgateGovParam proposals into non legacy param update versions. +func MigrateProposals(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.BinaryCodec) error { + store := ctx.KVStore(storeKey) + propStore := prefix.NewStore(store, v1migrations.ProposalsKeyPrefix) + + iter := propStore.Iterator(nil, nil) + defer iter.Close() + + for ; iter.Valid(); iter.Next() { + var prop govv1.Proposal + err := cdc.Unmarshal(iter.Value(), &prop) + // if error unmarshaling prop, convert to non legacy prop + if err != nil { + newProp, err := convertProposal(prop, cdc) + if err != nil { + return err + } + bz, err := cdc.Marshal(&newProp) + if err != nil { + return err + } + // Set new value on store. + propStore.Set(iter.Key(), bz) + } + } + + return nil +} + +func convertProposal(prop govv1.Proposal, cdc codec.BinaryCodec) (govv1.Proposal, error) { + msgs := prop.Messages + + for _, msg := range msgs { + var oldUpdateParamMsg oracletypes.MsgLegacyGovUpdateParams + err := cdc.Unmarshal(msg.GetValue(), &oldUpdateParamMsg) + if err != nil { + return govv1.Proposal{}, err + } + + newUpdateParamMsg := oracletypes.MsgGovUpdateParams{ + Authority: oldUpdateParamMsg.Authority, + Title: oldUpdateParamMsg.Title, + Description: oldUpdateParamMsg.Description, + Plan: oracletypes.ParamUpdatePlan{ + Keys: oldUpdateParamMsg.Keys, + Height: 0, // placeholder value for height + Changes: oldUpdateParamMsg.Changes, + }, + } + + msg.Value, err = newUpdateParamMsg.Marshal() + if err != nil { + return govv1.Proposal{}, err + } + } + + prop.Messages = msgs + return prop, nil +} diff --git a/x/oracle/keeper/migrate_proposal_test.go b/x/oracle/keeper/migrate_proposal_test.go new file mode 100644 index 00000000..18d060e1 --- /dev/null +++ b/x/oracle/keeper/migrate_proposal_test.go @@ -0,0 +1,52 @@ +package keeper_test + +import ( + types1 "github.com/cosmos/cosmos-sdk/codec/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + + "github.com/ojo-network/ojo/x/oracle/keeper" + "github.com/ojo-network/ojo/x/oracle/types" +) + +func (s *IntegrationTestSuite) TestMigrateProposal() { + ctx := s.ctx + cdc := s.app.AppCodec() + storeKey := s.app.GetKey(govtypes.StoreKey) + + // create legacy prop and set it in store + legacyMsg := types.MsgLegacyGovUpdateParams{ + Authority: "ojo10d07y265gmmuvt4z0w9aw880jnsr700jcz4krc", + Title: "title", + Description: "desc", + Keys: []string{ + "VotePeriod", + }, + Changes: types.Params{ + VotePeriod: 5, + }, + } + bz, err := cdc.Marshal(&legacyMsg) + s.Require().NoError(err) + prop := govv1.Proposal{ + Id: 1, + Messages: []*types1.Any{ + { + TypeUrl: "/ojo.oracle.v1.MsgGovUpdateParams", + Value: bz, + XXX_unrecognized: []byte{}, + }, + }, + Status: govv1.ProposalStatus_PROPOSAL_STATUS_PASSED, + } + s.app.GovKeeper.SetProposal(ctx, prop) + + // try to retreive proposal and fail + _, err = s.app.GovKeeper.Proposals.Get(ctx, prop.Id) + s.Require().Error(err) + + // succesfully retreive proposal after migration + err = keeper.MigrateProposals(ctx, storeKey, cdc) + _, err = s.app.GovKeeper.Proposals.Get(ctx, prop.Id) + s.Require().NoError(err) +} From c6b9bccd6ea0bf4a34c075c43b6e2277f2816704 Mon Sep 17 00:00:00 2001 From: rbajollari Date: Fri, 26 Jul 2024 11:28:48 +0200 Subject: [PATCH 2/3] fix conflicts --- app/upgrades.go | 22 ++++------------------ x/oracle/keeper/migrate_proposal.go | 4 ++-- x/oracle/keeper/migrate_proposal_test.go | 10 ++++++---- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/app/upgrades.go b/app/upgrades.go index 6d1b8900..7c52549c 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -39,11 +39,7 @@ func (app App) RegisterUpgradeHandlers() { app.registerUpgrade0_3_1Rc1(upgradeInfo) app.registerUpgrade0_3_1Rc2(upgradeInfo) app.registerUpgrade0_3_1(upgradeInfo) -<<<<<<< HEAD -======= app.registerUpgrade0_3_2(upgradeInfo) - app.registerUpgrade0_4_0(upgradeInfo) ->>>>>>> faac055 (chore: v0.3.2 upgrade handler (#481)) } // performs upgrade from v0.1.3 to v0.1.4 @@ -193,15 +189,8 @@ func (app *App) registerUpgrade0_3_1(_ upgradetypes.Plan) { const planName = "v0.3.1" app.UpgradeKeeper.SetUpgradeHandler(planName, -<<<<<<< HEAD func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - // migrate old proposals - govMigrator := govkeeper.NewMigrator(&app.GovKeeper, app.GetSubspace(govtypes.ModuleName)) - err := govMigrator.Migrate2to3(ctx) -======= - func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - sdkCtx := sdk.UnwrapSDKContext(ctx) - sdkCtx.Logger().Info("Upgrade handler execution", "name", planName) + ctx.Logger().Info("Upgrade handler execution", "name", planName) return app.mm.RunMigrations(ctx, app.configurator, fromVM) }, ) @@ -211,14 +200,11 @@ func (app *App) registerUpgrade0_3_2(_ upgradetypes.Plan) { const planName = "v0.3.2" app.UpgradeKeeper.SetUpgradeHandler(planName, - func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - sdkCtx := sdk.UnwrapSDKContext(ctx) - + func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { // migrate old proposals - err := oraclekeeper.MigrateProposals(sdkCtx, app.keys[govtypes.StoreKey], app.appCodec) ->>>>>>> faac055 (chore: v0.3.2 upgrade handler (#481)) + err := oraclekeeper.MigrateProposals(ctx, app.keys[govtypes.StoreKey], app.appCodec) if err != nil { - sdkCtx.Logger().Error("failed to migrate governance proposals", "err", err) + ctx.Logger().Error("failed to migrate governance proposals", "err", err) } ctx.Logger().Info("Upgrade handler execution", "name", planName) diff --git a/x/oracle/keeper/migrate_proposal.go b/x/oracle/keeper/migrate_proposal.go index bb9b8ae3..9c135f79 100644 --- a/x/oracle/keeper/migrate_proposal.go +++ b/x/oracle/keeper/migrate_proposal.go @@ -1,8 +1,8 @@ package keeper import ( - "cosmossdk.io/store/prefix" - storetypes "cosmossdk.io/store/types" + "github.com/cosmos/cosmos-sdk/store/prefix" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" v1migrations "github.com/cosmos/cosmos-sdk/x/gov/migrations/v1" diff --git a/x/oracle/keeper/migrate_proposal_test.go b/x/oracle/keeper/migrate_proposal_test.go index 18d060e1..1434a34d 100644 --- a/x/oracle/keeper/migrate_proposal_test.go +++ b/x/oracle/keeper/migrate_proposal_test.go @@ -42,11 +42,13 @@ func (s *IntegrationTestSuite) TestMigrateProposal() { s.app.GovKeeper.SetProposal(ctx, prop) // try to retreive proposal and fail - _, err = s.app.GovKeeper.Proposals.Get(ctx, prop.Id) - s.Require().Error(err) + s.Require().Panics(func() { + s.app.GovKeeper.GetProposal(ctx, prop.Id) + }) // succesfully retreive proposal after migration err = keeper.MigrateProposals(ctx, storeKey, cdc) - _, err = s.app.GovKeeper.Proposals.Get(ctx, prop.Id) - s.Require().NoError(err) + s.Require().NotPanics(func() { + s.app.GovKeeper.GetProposal(ctx, prop.Id) + }) } From a2bc412e76677f750b36161598b0ccf28124a96b Mon Sep 17 00:00:00 2001 From: rbajollari Date: Mon, 29 Jul 2024 09:56:57 -0400 Subject: [PATCH 3/3] new pf version in e2w --- tests/e2e/orchestrator/orchestrator.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/e2e/orchestrator/orchestrator.go b/tests/e2e/orchestrator/orchestrator.go index d6abe5b4..0a95d31f 100644 --- a/tests/e2e/orchestrator/orchestrator.go +++ b/tests/e2e/orchestrator/orchestrator.go @@ -44,8 +44,7 @@ const ( ojoGrpcPort = "9090" ojoMaxStartupTime = 40 // seconds - // TODO: update original pf instance with sdk 0.47 - priceFeederContainerRepo = "ghcr.io/ojo-network/price-feeder-ojo-47" + priceFeederContainerRepo = "ghcr.io/ojo-network/price-feeder-ojo-v0.1.11" priceFeederServerPort = "7171/tcp" priceFeederMaxStartupTime = 20 // seconds @@ -427,7 +426,7 @@ func (o *Orchestrator) runPriceFeeder(t *testing.T) { fmt.Sprintf("RPC_GRPC_ENDPOINT=%s", grpcEndpoint), fmt.Sprintf("RPC_TMRPC_ENDPOINT=%s", tmrpcEndpoint), }, - Cmd: []string{"--skip-provider-check", "--log-level=debug"}, + Cmd: []string{"--skip-provider-check", "--config-currency-providers", "--log-level=debug"}, }, noRestart, )