From 3e82ab1751c54aca7ba5a82be7cd4d4275adea8e Mon Sep 17 00:00:00 2001 From: mmsqe Date: Fri, 11 Oct 2024 23:10:48 +0800 Subject: [PATCH 1/4] Problem: MsgModuleQuerySafe is not in allowed messages when upgrade --- CHANGELOG.md | 1 + app/app.go | 2 +- app/upgrades.go | 14 ++++++++++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09917aa56..ad439e781 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - [#1060](https://github.com/crypto-org-chain/chain-main/pull/1060) Upgrade rocksdb to `v9.2.1` and bump versiondb. - [#1061](https://github.com/crypto-org-chain/chain-main/pull/1061) Integrate sdk 0.50. - [#1068](https://github.com/crypto-org-chain/chain-main/pull/1068) Upgrade ibc-go to `v8.3.2` and remove icaauth module. +- [#1084](https://github.com/crypto-org-chain/chain-main/pull/1084) Add MsgModuleQuerySafe in allowed messages for ica host param. *Dec 6, 2023* diff --git a/app/app.go b/app/app.go index ee43ee0f4..308518ca9 100644 --- a/app/app.go +++ b/app/app.go @@ -771,7 +771,7 @@ func New( // upgrade. app.setPostHandler() - app.RegisterUpgradeHandlers(app.appCodec, app.IBCKeeper.ClientKeeper) + app.RegisterUpgradeHandlers(app.appCodec) if loadLatest { if err := app.LoadLatestVersion(); err != nil { diff --git a/app/upgrades.go b/app/upgrades.go index 824b5c73c..c236ff8f9 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -3,17 +3,27 @@ package app import ( "context" "fmt" + "slices" storetypes "cosmossdk.io/store/types" upgradetypes "cosmossdk.io/x/upgrade/types" "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" - clientkeeper "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper" ) -func (app *ChainApp) RegisterUpgradeHandlers(cdc codec.BinaryCodec, clientKeeper clientkeeper.Keeper) { +func (app *ChainApp) RegisterUpgradeHandlers(cdc codec.BinaryCodec) { planName := "v5.0" app.UpgradeKeeper.SetUpgradeHandler(planName, func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + sdkCtx := sdk.UnwrapSDKContext(ctx) + { + params := app.ICAHostKeeper.GetParams(sdkCtx) + msg := "/ibc.applications.interchain_accounts.host.v1.MsgModuleQuerySafe" + if !slices.Contains(params.AllowMessages, msg) { + params.AllowMessages = append(params.AllowMessages, msg) + app.ICAHostKeeper.SetParams(sdkCtx, params) + } + } return app.ModuleManager.RunMigrations(ctx, app.configurator, fromVM) }) From 71596365ff4cb0d5d858a250531c382cee29805a Mon Sep 17 00:00:00 2001 From: mmsqe Date: Sat, 12 Oct 2024 09:49:53 +0800 Subject: [PATCH 2/4] fix --- app/upgrades.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/upgrades.go b/app/upgrades.go index c236ff8f9..2288de996 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -10,21 +10,28 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types" ) func (app *ChainApp) RegisterUpgradeHandlers(cdc codec.BinaryCodec) { planName := "v5.0" app.UpgradeKeeper.SetUpgradeHandler(planName, func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + m, err := app.ModuleManager.RunMigrations(ctx, app.configurator, fromVM) + if err != nil { + return m, err + } sdkCtx := sdk.UnwrapSDKContext(ctx) { - params := app.ICAHostKeeper.GetParams(sdkCtx) + var params types.Params + params = app.ICAHostKeeper.GetParams(sdkCtx) msg := "/ibc.applications.interchain_accounts.host.v1.MsgModuleQuerySafe" - if !slices.Contains(params.AllowMessages, msg) { + if (len(params.AllowMessages) > 1 || params.AllowMessages[0] != "*") && + !slices.Contains(params.AllowMessages, msg) { params.AllowMessages = append(params.AllowMessages, msg) app.ICAHostKeeper.SetParams(sdkCtx, params) } } - return app.ModuleManager.RunMigrations(ctx, app.configurator, fromVM) + return m, nil }) upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk() From 5db4448370c488afffa2cf3354f376566d1a0cc9 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Sat, 12 Oct 2024 11:16:18 +0800 Subject: [PATCH 3/4] Update app/upgrades.go Signed-off-by: mmsqe --- app/upgrades.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/upgrades.go b/app/upgrades.go index 2288de996..e363e3984 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -25,8 +25,9 @@ func (app *ChainApp) RegisterUpgradeHandlers(cdc codec.BinaryCodec) { var params types.Params params = app.ICAHostKeeper.GetParams(sdkCtx) msg := "/ibc.applications.interchain_accounts.host.v1.MsgModuleQuerySafe" - if (len(params.AllowMessages) > 1 || params.AllowMessages[0] != "*") && - !slices.Contains(params.AllowMessages, msg) { + if !slices.ContainsFunc(params.AllowMessages, func(allowMsg string) bool { + return allowMsg == "*" || allowMsg == msg + }) { params.AllowMessages = append(params.AllowMessages, msg) app.ICAHostKeeper.SetParams(sdkCtx, params) } From 1b2ba8dad955873cde909bdd2bc6852f86f7dbca Mon Sep 17 00:00:00 2001 From: mmsqe Date: Mon, 14 Oct 2024 09:04:25 +0800 Subject: [PATCH 4/4] Apply suggestions from code review Signed-off-by: mmsqe --- app/upgrades.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/upgrades.go b/app/upgrades.go index e363e3984..df63304a6 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -10,7 +10,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" - "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types" ) func (app *ChainApp) RegisterUpgradeHandlers(cdc codec.BinaryCodec) { @@ -22,8 +21,7 @@ func (app *ChainApp) RegisterUpgradeHandlers(cdc codec.BinaryCodec) { } sdkCtx := sdk.UnwrapSDKContext(ctx) { - var params types.Params - params = app.ICAHostKeeper.GetParams(sdkCtx) + params := app.ICAHostKeeper.GetParams(sdkCtx) msg := "/ibc.applications.interchain_accounts.host.v1.MsgModuleQuerySafe" if !slices.ContainsFunc(params.AllowMessages, func(allowMsg string) bool { return allowMsg == "*" || allowMsg == msg