From 8105892d0c8121629dcea2338379e5ce2e722115 Mon Sep 17 00:00:00 2001 From: GNaD Date: Sun, 24 Sep 2023 22:14:17 +0700 Subject: [PATCH] add genesis consumer --- app/app.go | 6 ++++-- app/upgrades/types.go | 4 +++- app/upgrades/v4/upgrade.go | 4 ++++ app/upgrades/v5/upgrade.go | 4 ++++ app/upgrades/v6/upgrade.go | 27 +++++++++++++++++++++++++++ 5 files changed, 42 insertions(+), 3 deletions(-) diff --git a/app/app.go b/app/app.go index b883759fa..2ce834a5a 100644 --- a/app/app.go +++ b/app/app.go @@ -507,7 +507,7 @@ func NewCentauriApp( app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter()) app.mm.RegisterServices(app.configurator) - app.setupUpgradeHandlers() + app.setupUpgradeHandlers(appOpts) // create the simulation manager and define the order of the modules for deterministic simulations // app.sm = module.NewSimulationManager( @@ -738,7 +738,7 @@ func (app *CentauriApp) customPreUpgradeHandler(_ upgradetypes.Plan) { // } } -func (app *CentauriApp) setupUpgradeHandlers() { +func (app *CentauriApp) setupUpgradeHandlers(appOpts servertypes.AppOptions) { for _, upgrade := range Upgrades { app.UpgradeKeeper.SetUpgradeHandler( upgrade.UpgradeName, @@ -746,6 +746,8 @@ func (app *CentauriApp) setupUpgradeHandlers() { app.mm, app.configurator, app.BaseApp, + appOpts, + app.appCodec, &app.AppKeepers, ), ) diff --git a/app/upgrades/types.go b/app/upgrades/types.go index 4e3dcc1ef..9ed54785b 100644 --- a/app/upgrades/types.go +++ b/app/upgrades/types.go @@ -2,6 +2,8 @@ package upgrades import ( types "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/cosmos/cosmos-sdk/codec" + servertypes "github.com/cosmos/cosmos-sdk/server/types" store "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" @@ -26,7 +28,7 @@ type Upgrade struct { UpgradeName string // CreateUpgradeHandler defines the function that creates an upgrade handler - CreateUpgradeHandler func(*module.Manager, module.Configurator, BaseAppParamManager, *keepers.AppKeepers) upgradetypes.UpgradeHandler + CreateUpgradeHandler func(*module.Manager, module.Configurator, BaseAppParamManager, servertypes.AppOptions, codec.Codec, *keepers.AppKeepers) upgradetypes.UpgradeHandler // Store upgrades, should be used for any new modules introduced, new modules deleted, or store names renamed. StoreUpgrades store.StoreUpgrades diff --git a/app/upgrades/v4/upgrade.go b/app/upgrades/v4/upgrade.go index c46f17999..179620e8e 100644 --- a/app/upgrades/v4/upgrade.go +++ b/app/upgrades/v4/upgrade.go @@ -2,6 +2,8 @@ package v4 import ( wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + "github.com/cosmos/cosmos-sdk/codec" + servertypes "github.com/cosmos/cosmos-sdk/server/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" @@ -15,6 +17,8 @@ func CreateUpgradeHandler( mm *module.Manager, configurator module.Configurator, _ upgrades.BaseAppParamManager, + appOpts servertypes.AppOptions, + cdc codec.Codec, keepers *keepers.AppKeepers, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { diff --git a/app/upgrades/v5/upgrade.go b/app/upgrades/v5/upgrade.go index 3102b16f3..00bcc681d 100644 --- a/app/upgrades/v5/upgrade.go +++ b/app/upgrades/v5/upgrade.go @@ -2,6 +2,8 @@ package v5 import ( "cosmossdk.io/math" + "github.com/cosmos/cosmos-sdk/codec" + servertypes "github.com/cosmos/cosmos-sdk/server/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" @@ -22,6 +24,8 @@ func CreateUpgradeHandler( mm *module.Manager, configurator module.Configurator, _ upgrades.BaseAppParamManager, + appOpts servertypes.AppOptions, + cdc codec.Codec, keepers *keepers.AppKeepers, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { diff --git a/app/upgrades/v6/upgrade.go b/app/upgrades/v6/upgrade.go index 6d0e0b444..9a60a2cc4 100644 --- a/app/upgrades/v6/upgrade.go +++ b/app/upgrades/v6/upgrade.go @@ -1,20 +1,47 @@ package v6 import ( + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/codec" + servertypes "github.com/cosmos/cosmos-sdk/server/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + consumertypes "github.com/cosmos/interchain-security/v3/x/ccv/consumer/types" "github.com/notional-labs/centauri/v6/app/keepers" "github.com/notional-labs/centauri/v6/app/upgrades" + + "github.com/spf13/cast" ) func CreateUpgradeHandler( mm *module.Manager, configurator module.Configurator, _ upgrades.BaseAppParamManager, + appOpts servertypes.AppOptions, + cdc codec.Codec, keepers *keepers.AppKeepers, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + ctx.Logger().Info("Starting upgrade v6...") + + consumerKeeper := keepers.ConsumerKeeper + + nodeHome := cast.ToString(appOpts.Get(flags.FlagHome)) + consumerUpgradeGenFile := nodeHome + "/config/ccv.json" + appState, _, err := genutiltypes.GenesisStateFromGenFile(consumerUpgradeGenFile) + if err != nil { + panic("Unable to read consumer genesis") + } + + var consumerGenesis = consumertypes.GenesisState{} + cdc.MustUnmarshalJSON(appState[consumertypes.ModuleName], &consumerGenesis) + + consumerGenesis.PreCCV = true + consumerGenesis.Params.SoftOptOutThreshold = "0.05" + consumerKeeper.InitGenesis(ctx, &consumerGenesis) + return mm.RunMigrations(ctx, configurator, vm) } }