diff --git a/app/upgrades/nextupgrade/upgrades.go b/app/upgrades/nextupgrade/upgrades.go index 9fed784e7..4424b36df 100644 --- a/app/upgrades/nextupgrade/upgrades.go +++ b/app/upgrades/nextupgrade/upgrades.go @@ -3,10 +3,10 @@ package nextupgrade import ( "errors" - "github.com/cosmos/cosmos-sdk/codec" ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" ibcchanneltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" @@ -16,7 +16,83 @@ import ( contractmanagertypes "github.com/neutron-org/neutron/x/contractmanager/types" ) -func MigrateFailures(ctx sdk.Context, storeKeys upgrades.StoreKeys, cdc codec.Codec) error { +func CreateUpgradeHandler( + mm *module.Manager, + configurator module.Configurator, + keepers *upgrades.UpgradeKeepers, + storeKeys upgrades.StoreKeys, + cdc codec.Codec, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + ctx.Logger().Info("Starting module migrations...") + vm, err := mm.RunMigrations(ctx, configurator, vm) + if err != nil { + return vm, err + } + + err = migrateGlobalFees(ctx, keepers) + if err != nil { + ctx.Logger().Error("failed to migrate GlobalFees", "err", err) + return vm, err + } + + err = migrateFailures(ctx, storeKeys, cdc) + if err != nil { + ctx.Logger().Error("failed to migrate Failures", "err", err) + return vm, err + } + + ctx.Logger().Info("Upgrade complete") + return vm, err + } +} + +func migrateGlobalFees(ctx sdk.Context, keepers *upgrades.UpgradeKeepers) error { + ctx.Logger().Info("Implementing GlobalFee Params...") + + if !keepers.GlobalFeeSubspace.Has(ctx, types.ParamStoreKeyMinGasPrices) { + return errors.New("minimum_gas_prices param not found") + } + + if !keepers.GlobalFeeSubspace.Has(ctx, types.ParamStoreKeyBypassMinFeeMsgTypes) { + return errors.New("bypass_min_fee_msg_types param not found") + } + + if !keepers.GlobalFeeSubspace.Has(ctx, types.ParamStoreKeyMaxTotalBypassMinFeeMsgGasUsage) { + return errors.New("max_total_bypass_min_fee_msg_gas_usage param not found") + } + + // global fee is empty set, set global fee to equal to 0.05 USD (for 200k of gas) in appropriate coin + // As of June 22nd, 2023 this is + // 0.9untrn,0.026ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9,0.25ibc/F082B65C88E4B6D5EF1DB243CDA1D331D002759E938A0F5CD3FFDC5D53B3E349 + requiredGlobalFees := sdk.DecCoins{ + sdk.NewDecCoinFromDec("untrn", sdk.MustNewDecFromStr("0.9")), + sdk.NewDecCoinFromDec("ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9", sdk.MustNewDecFromStr("0.026")), + sdk.NewDecCoinFromDec("ibc/F082B65C88E4B6D5EF1DB243CDA1D331D002759E938A0F5CD3FFDC5D53B3E349", sdk.MustNewDecFromStr("0.25")), + } + requiredGlobalFees = requiredGlobalFees.Sort() + + keepers.GlobalFeeSubspace.Set(ctx, types.ParamStoreKeyMinGasPrices, &requiredGlobalFees) + + ctx.Logger().Info("Global fees was set successfully") + + defaultBypassFeeMessages := []string{ + sdk.MsgTypeURL(&ibcchanneltypes.MsgRecvPacket{}), + sdk.MsgTypeURL(&ibcchanneltypes.MsgAcknowledgement{}), + sdk.MsgTypeURL(&ibcclienttypes.MsgUpdateClient{}), + } + keepers.GlobalFeeSubspace.Set(ctx, types.ParamStoreKeyBypassMinFeeMsgTypes, &defaultBypassFeeMessages) + + ctx.Logger().Info("Bypass min fee msg types was set successfully") + + keepers.GlobalFeeSubspace.Set(ctx, types.ParamStoreKeyMaxTotalBypassMinFeeMsgGasUsage, types.DefaultmaxTotalBypassMinFeeMsgGasUsage) + + ctx.Logger().Info("Max total bypass min fee msg gas usage set successfully") + + return nil +} + +func migrateFailures(ctx sdk.Context, storeKeys upgrades.StoreKeys, cdc codec.Codec) error { ctx.Logger().Info("Migrating failures...") // fetch list of all old failures @@ -53,68 +129,3 @@ func MigrateFailures(ctx sdk.Context, storeKeys upgrades.StoreKeys, cdc codec.Co return nil } - -func CreateUpgradeHandler( - mm *module.Manager, - configurator module.Configurator, - keepers *upgrades.UpgradeKeepers, - storeKeys upgrades.StoreKeys, - cdc codec.Codec, -) upgradetypes.UpgradeHandler { - return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { - ctx.Logger().Info("Starting module migrations...") - vm, err := mm.RunMigrations(ctx, configurator, vm) - if err != nil { - return vm, err - } - - ctx.Logger().Info("Implementing GlobalFee Params...") - - if !keepers.GlobalFeeSubspace.Has(ctx, types.ParamStoreKeyMinGasPrices) { - return vm, errors.New("minimum_gas_prices param not found") - } - - if !keepers.GlobalFeeSubspace.Has(ctx, types.ParamStoreKeyBypassMinFeeMsgTypes) { - return vm, errors.New("bypass_min_fee_msg_types param not found") - } - - if !keepers.GlobalFeeSubspace.Has(ctx, types.ParamStoreKeyMaxTotalBypassMinFeeMsgGasUsage) { - return vm, errors.New("max_total_bypass_min_fee_msg_gas_usage param not found") - } - - // global fee is empty set, set global fee to equal to 0.05 USD (for 200k of gas) in appropriate coin - // As of June 22nd, 2023 this is - // 0.9untrn,0.026ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9,0.25ibc/F082B65C88E4B6D5EF1DB243CDA1D331D002759E938A0F5CD3FFDC5D53B3E349 - requiredGlobalFees := sdk.DecCoins{ - sdk.NewDecCoinFromDec("untrn", sdk.MustNewDecFromStr("0.9")), - sdk.NewDecCoinFromDec("ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9", sdk.MustNewDecFromStr("0.026")), - sdk.NewDecCoinFromDec("ibc/F082B65C88E4B6D5EF1DB243CDA1D331D002759E938A0F5CD3FFDC5D53B3E349", sdk.MustNewDecFromStr("0.25")), - } - requiredGlobalFees = requiredGlobalFees.Sort() - - keepers.GlobalFeeSubspace.Set(ctx, types.ParamStoreKeyMinGasPrices, &requiredGlobalFees) - - ctx.Logger().Info("Global fees was set successfully") - - defaultBypassFeeMessages := []string{ - sdk.MsgTypeURL(&ibcchanneltypes.MsgRecvPacket{}), - sdk.MsgTypeURL(&ibcchanneltypes.MsgAcknowledgement{}), - sdk.MsgTypeURL(&ibcclienttypes.MsgUpdateClient{}), - } - keepers.GlobalFeeSubspace.Set(ctx, types.ParamStoreKeyBypassMinFeeMsgTypes, &defaultBypassFeeMessages) - - ctx.Logger().Info("Bypass min fee msg types was set successfully") - - keepers.GlobalFeeSubspace.Set(ctx, types.ParamStoreKeyMaxTotalBypassMinFeeMsgGasUsage, types.DefaultmaxTotalBypassMinFeeMsgGasUsage) - - ctx.Logger().Info("Max total bypass min fee msg gas usage set successfully") - - err = MigrateFailures(ctx, storeKeys, cdc) - if err != nil { - ctx.Logger().Error("failed to migrate failures", "err", err) - } - - ctx.Logger().Info("Upgrade complete") - return vm, err - } -} diff --git a/app/upgrades/types.go b/app/upgrades/types.go index 3a6fa1583..91fe12f10 100644 --- a/app/upgrades/types.go +++ b/app/upgrades/types.go @@ -2,7 +2,7 @@ package upgrades import ( "github.com/cosmos/cosmos-sdk/codec" - storetypes "github.com/cosmos/cosmos-sdk/store/types" + store "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/types/module" capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" @@ -29,7 +29,7 @@ type Upgrade struct { CreateUpgradeHandler func(*module.Manager, module.Configurator, *UpgradeKeepers, StoreKeys, codec.Codec) upgradetypes.UpgradeHandler // Store upgrades, should be used for any new modules introduced, new modules deleted, or store names renamed. - StoreUpgrades storetypes.StoreUpgrades + StoreUpgrades store.StoreUpgrades } type UpgradeKeepers struct { @@ -47,5 +47,5 @@ type UpgradeKeepers struct { } type StoreKeys interface { - GetKey(string) *storetypes.KVStoreKey + GetKey(string) *store.KVStoreKey }