Skip to content

Commit

Permalink
add genesis consumer
Browse files Browse the repository at this point in the history
  • Loading branch information
GNaD13 committed Sep 24, 2023
1 parent ed05df7 commit 8105892
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
6 changes: 4 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -738,14 +738,16 @@ 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,
upgrade.CreateUpgradeHandler(
app.mm,
app.configurator,
app.BaseApp,
appOpts,
app.appCodec,
&app.AppKeepers,
),
)
Expand Down
4 changes: 3 additions & 1 deletion app/upgrades/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions app/upgrades/v4/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions app/upgrades/v5/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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) {
Expand Down
27 changes: 27 additions & 0 deletions app/upgrades/v6/upgrade.go
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 8105892

Please sign in to comment.