Skip to content

Commit

Permalink
IbcHooks param store migration (#1939)
Browse files Browse the repository at this point in the history
* migrate params to own store

* change key name

* move params into param file, add tests

* remove paramspace from attribute keeper

* remove init param keepers for modules that do not use them

* add migration function

* add change log

* fix migrate function, add remove todos

* add parent issue to changelog
  • Loading branch information
nullpointer0x00 authored Apr 19, 2024
1 parent 0ced31a commit b004ae3
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 33 deletions.
13 changes: 7 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ Ref: https://keepachangelog.com/en/1.0.0/
* Remove unused navs [#1920](https://github.com/provenance-io/provenance/issues/1920).
* Remove emitting of EventTypeMessage [#1760](https://github.com/provenance-io/provenance/issues/1760).
* Update genutil for sdk 50 [#1760](https://github.com/provenance-io/provenance/issues/1760).
* Migrate module params from param space to module store.
* Attribute module param migration [#1927](https://github.com/provenance-io/provenance/pull/1927)
* Marker module param migration [#1934](https://github.com/provenance-io/provenance/pull/1934)
* Metadata module param migration [#1932](https://github.com/provenance-io/provenance/pull/1932)
* Msgfees module param migration [#1936](https://github.com/provenance-io/provenance/pull/1936)
* Name module param migration [#1937](https://github.com/provenance-io/provenance/pull/1937)
* Migrate module params from param space to module store.[#1760](https://github.com/provenance-io/provenance/issues/1935)
* Attribute module param migration [#1927](https://github.com/provenance-io/provenance/pull/1927).
* Marker module param migration [#1934](https://github.com/provenance-io/provenance/pull/1934).
* Metadata module param migration [#1932](https://github.com/provenance-io/provenance/pull/1932).
* Msgfees module param migration [#1936](https://github.com/provenance-io/provenance/pull/1936).
* Name module param migration [#1937](https://github.com/provenance-io/provenance/pull/1937).
* IbcHooks module param migration [#1939](https://github.com/provenance-io/provenance/pull/1939).
* Restore the hold module [#1930](https://github.com/provenance-io/provenance/pull/1930).
* Restore gov-prop cli commands and fix next key decoding [#1930](https://github.com/provenance-io/provenance/pull/1930).
* Switch to InputOutputCoinsProv for exchange transfers [#1930](https://github.com/provenance-io/provenance/pull/1930).
Expand Down
6 changes: 1 addition & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,8 @@ func New(

// Configure the hooks keeper
hooksKeeper := ibchookskeeper.NewKeeper(
appCodec,
keys[ibchookstypes.StoreKey],
app.GetSubspace(ibchookstypes.ModuleName),
app.IBCKeeper.ChannelKeeper,
nil,
)
Expand Down Expand Up @@ -1361,7 +1361,6 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(crisistypes.ModuleName)

paramsKeeper.Subspace(wasmtypes.ModuleName)
paramsKeeper.Subspace(triggertypes.ModuleName) // TODO[1760]: params: Migrate trigger params.

// register the key tables for legacy param subspaces
keyTable := ibcclienttypes.ParamKeyTable()
Expand All @@ -1370,9 +1369,6 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(ibctransfertypes.ModuleName).WithKeyTable(ibctransfertypes.ParamKeyTable())
paramsKeeper.Subspace(icahosttypes.SubModuleName).WithKeyTable(icahosttypes.ParamKeyTable())

paramsKeeper.Subspace(icqtypes.ModuleName) // TODO[1760]: params: Migrate icq params.
paramsKeeper.Subspace(ibchookstypes.ModuleName) // TODO[1760]: params: Migrate ibc-hooks params.

return paramsKeeper
}

Expand Down
24 changes: 24 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
ibctmmigrations "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint/migrations"

attributetypes "github.com/provenance-io/provenance/x/attribute/types"
ibchookstypes "github.com/provenance-io/provenance/x/ibchooks/types"
markertypes "github.com/provenance-io/provenance/x/marker/types"
metadatatypes "github.com/provenance-io/provenance/x/metadata/types"
msgfeestypes "github.com/provenance-io/provenance/x/msgfees/types"
Expand Down Expand Up @@ -73,6 +74,7 @@ var upgrades = map[string]appUpgrade{
migrateMetadataOSLocatorParams(ctx, app)
migrateMsgFeesParams(ctx, app)
migrateNameParams(ctx, app)
migrateIbcHooksParams(ctx, app)

vm, err = runModuleMigrations(ctx, app, vm)
if err != nil {
Expand Down Expand Up @@ -111,6 +113,7 @@ var upgrades = map[string]appUpgrade{
migrateMetadataOSLocatorParams(ctx, app)
migrateMsgFeesParams(ctx, app)
migrateNameParams(ctx, app)
migrateIbcHooksParams(ctx, app)

vm, err = runModuleMigrations(ctx, app, vm)
if err != nil {
Expand Down Expand Up @@ -431,6 +434,7 @@ func migrateMsgFeesParams(ctx sdk.Context, app *App) {
ctx.Logger().Info("Migrating msgfees params.")
msgFeesParamSpace := app.ParamsKeeper.Subspace(msgfeestypes.ModuleName).WithKeyTable(msgfeestypes.ParamKeyTable())

// TODO: all param keys from types/params with the umber handlers.
var floorGasPrice sdk.Coin
if msgFeesParamSpace.Has(ctx, msgfeestypes.ParamStoreKeyFloorGasPrice) {
msgFeesParamSpace.Get(ctx, msgfeestypes.ParamStoreKeyFloorGasPrice, &floorGasPrice)
Expand All @@ -455,3 +459,23 @@ func migrateMsgFeesParams(ctx sdk.Context, app *App) {

ctx.Logger().Info("Done migrating msgfees params.")
}

// migrateIbcHooksParams migrates existing ibchooks parameters from paramSpace to a direct KVStore.
// TODO: Remove with the umber handlers.
func migrateIbcHooksParams(ctx sdk.Context, app *App) {
ctx.Logger().Info("Migrating ibchooks params.")
ibcHooksParamSpace := app.ParamsKeeper.Subspace(ibchookstypes.ModuleName)

params := ibchookstypes.DefaultParams()

// TODO: all param keys from types/params with the umber handlers.
var allowlist []string
if ibcHooksParamSpace.Has(ctx, ibchookstypes.KeyAsyncAckAllowList) {
ibcHooksParamSpace.Get(ctx, ibchookstypes.KeyAsyncAckAllowList, &allowlist)
}
params.AllowedAsyncAckContracts = allowlist

app.IBCHooksKeeper.SetParams(ctx, params)

ctx.Logger().Info("Done migrating ibchooks params.")
}
4 changes: 4 additions & 0 deletions app/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,8 @@ func (s *UpgradeTestSuite) TestUmberRC1() {
"INF Done migrating msgfees params.",
"INF Migrating name params.",
"INF Done migrating name params.",
"INF Migrating ibchooks params.",
"INF Done migrating ibchooks params.",
"INF Starting module migrations. This may take a significant amount of time to complete. Do not restart node.",
"INF Updating IBC AllowedClients.",
"INF Done updating IBC AllowedClients.",
Expand Down Expand Up @@ -419,6 +421,8 @@ func (s *UpgradeTestSuite) TestUmber() {
"INF Done migrating msgfees params.",
"INF Migrating name params.",
"INF Done migrating name params.",
"INF Migrating ibchooks params.",
"INF Done migrating ibchooks params.",
"INF Starting module migrations. This may take a significant amount of time to complete. Do not restart node.",
"INF Updating IBC AllowedClients.",
"INF Done updating IBC AllowedClients.",
Expand Down
28 changes: 6 additions & 22 deletions x/ibchooks/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ import (
"cosmossdk.io/log"
storetypes "cosmossdk.io/store/types"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"

"github.com/provenance-io/provenance/x/ibchooks/types"
)

type (
Keeper struct {
storeKey storetypes.StoreKey
paramSpace paramtypes.Subspace
cdc codec.BinaryCodec
storeKey storetypes.StoreKey

channelKeeper types.ChannelKeeper
ContractKeeper *wasmkeeper.PermissionedKeeper
Expand All @@ -34,17 +34,14 @@ type (

// NewKeeper returns a new instance of the x/ibchooks keeper
func NewKeeper(
cdc codec.BinaryCodec,
storeKey storetypes.StoreKey,
paramSpace paramtypes.Subspace,
channelKeeper types.ChannelKeeper,
contractKeeper *wasmkeeper.PermissionedKeeper,
) Keeper {
if !paramSpace.HasKeyTable() {
paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable())
}
keeper := Keeper{
cdc: cdc,
storeKey: storeKey,
paramSpace: paramSpace,
channelKeeper: channelKeeper,
ContractKeeper: contractKeeper,
}
Expand All @@ -56,17 +53,6 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName))
}

// GetParams returns the total set of the module's parameters.
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
k.paramSpace.GetParamSet(ctx, &params)
return params
}

// SetParams sets the module's parameters with the provided parameters.
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
k.paramSpace.SetParamSet(ctx, &params)
}

func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) {
k.SetParams(ctx, genState.Params)
}
Expand Down Expand Up @@ -112,9 +98,7 @@ func (k Keeper) GetPacketCallback(ctx sdk.Context, channel string, packetSequenc

// IsInAllowList checks the params to see if the contract is in the KeyAsyncAckAllowList param
func (k Keeper) IsInAllowList(ctx sdk.Context, contract string) bool {
var allowList []string
k.paramSpace.GetIfExists(ctx, types.KeyAsyncAckAllowList, &allowList)
for _, addr := range allowList {
for _, addr := range k.GetParams(ctx).AllowedAsyncAckContracts {
if addr == contract {
return true
}
Expand Down
24 changes: 24 additions & 0 deletions x/ibchooks/keeper/params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/provenance-io/provenance/x/ibchooks/types"
)

// GetParams returns the total set of the module's parameters.
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.IbcHooksParamStoreKey)
if bz == nil {
return types.DefaultParams()
}
k.cdc.MustUnmarshal(bz, &params)
return params
}

// SetParams sets the module's parameters with the provided parameters.
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshal(&params)
store.Set(types.IbcHooksParamStoreKey, bz)
}
44 changes: 44 additions & 0 deletions x/ibchooks/keeper/params_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package keeper_test

import (
"testing"
"time"

cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/provenance-io/provenance/app"
simapp "github.com/provenance-io/provenance/app"
"github.com/provenance-io/provenance/x/ibchooks/types"
"github.com/stretchr/testify/suite"
)

type IbcHooksParamTestSuite struct {
suite.Suite

app *app.App
ctx sdk.Context
}

func (s *IbcHooksParamTestSuite) SetupTest() {
s.app = simapp.Setup(s.T())
s.ctx = s.app.BaseApp.NewContextLegacy(false, cmtproto.Header{Time: time.Now()})
}

func TestIbcHooksParamTestSuite(t *testing.T) {
suite.Run(t, new(IbcHooksParamTestSuite))
}

func (s *IbcHooksParamTestSuite) TestGetSetParams() {
defaultParams := s.app.IBCHooksKeeper.GetParams(s.ctx)
s.Require().Len(defaultParams.AllowedAsyncAckContracts, 0, "Default AllowedAsyncAckContracts should be empty")

newAllowedAsyncAckContracts := []string{"contract1", "contract2", "contract3"}
newParams := types.Params{
AllowedAsyncAckContracts: newAllowedAsyncAckContracts,
}

s.app.IBCHooksKeeper.SetParams(s.ctx, newParams)

updatedParams := s.app.IBCHooksKeeper.GetParams(s.ctx)
s.Require().Equal(newAllowedAsyncAckContracts, updatedParams.AllowedAsyncAckContracts, "Updated AllowedAsyncAckContracts should match")
}
5 changes: 5 additions & 0 deletions x/ibchooks/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ const (

SenderPrefix = "ibc-wasm-hook-intermediary"
)

var (
// IbcHooksParamStoreKey key for ibchooks module's params
IbcHooksParamStoreKey = []byte{0x01}
)
1 change: 1 addition & 0 deletions x/ibchooks/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
)

// Parameter store keys.
// TODO: remove with the umber (v1.19.x) handlers.
var (
KeyAsyncAckAllowList = []byte("AsyncAckAllowList")

Expand Down

0 comments on commit b004ae3

Please sign in to comment.