From 30f3fa9fc59078952f263fa6c72e691fe2b38a80 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Wed, 31 May 2023 18:22:36 -0500 Subject: [PATCH 1/4] add ica auth messages --- app/upgrades/v16/upgrades.go | 45 ++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/app/upgrades/v16/upgrades.go b/app/upgrades/v16/upgrades.go index f65feda17e5..8d94975b28c 100644 --- a/app/upgrades/v16/upgrades.go +++ b/app/upgrades/v16/upgrades.go @@ -10,7 +10,15 @@ import ( "github.com/osmosis-labs/osmosis/v15/app/keepers" "github.com/osmosis-labs/osmosis/v15/app/upgrades" - distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + cosmwasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + icahosttypes "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/host/types" + ibctransfertypes "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types" + + gammtypes "github.com/osmosis-labs/osmosis/v15/x/gamm/types" cltypes "github.com/osmosis-labs/osmosis/v15/x/concentrated-liquidity/types" superfluidtypes "github.com/osmosis-labs/osmosis/v15/x/superfluid/types" @@ -77,6 +85,39 @@ func CreateUpgradeHandler( return nil, err } + // Specifying the whole list instead of adding and removing. Less fragile. + hostParams := icahosttypes.Params{ + HostEnabled: true, + AllowMessages: []string{ + sdk.MsgTypeURL(&ibctransfertypes.MsgTransfer{}), + sdk.MsgTypeURL(&banktypes.MsgSend{}), + sdk.MsgTypeURL(&stakingtypes.MsgDelegate{}), + sdk.MsgTypeURL(&stakingtypes.MsgBeginRedelegate{}), + sdk.MsgTypeURL(&stakingtypes.MsgCreateValidator{}), + sdk.MsgTypeURL(&stakingtypes.MsgEditValidator{}), + sdk.MsgTypeURL(&stakingtypes.MsgUndelegate{}), + sdk.MsgTypeURL(&distrtypes.MsgWithdrawDelegatorReward{}), + sdk.MsgTypeURL(&distrtypes.MsgSetWithdrawAddress{}), + sdk.MsgTypeURL(&distrtypes.MsgWithdrawValidatorCommission{}), + sdk.MsgTypeURL(&distrtypes.MsgFundCommunityPool{}), + sdk.MsgTypeURL(&govtypes.MsgVote{}), + sdk.MsgTypeURL(&gammtypes.MsgJoinPool{}), + sdk.MsgTypeURL(&gammtypes.MsgExitPool{}), + sdk.MsgTypeURL(&gammtypes.MsgSwapExactAmountIn{}), + sdk.MsgTypeURL(&gammtypes.MsgSwapExactAmountOut{}), + sdk.MsgTypeURL(&gammtypes.MsgJoinSwapExternAmountIn{}), + sdk.MsgTypeURL(&gammtypes.MsgJoinSwapShareAmountOut{}), + sdk.MsgTypeURL(&gammtypes.MsgExitSwapExternAmountOut{}), + sdk.MsgTypeURL(&gammtypes.MsgExitSwapShareAmountIn{}), + sdk.MsgTypeURL(&superfluidtypes.MsgSuperfluidUnbondLock{}), + // Change: Added MsgExecuteContract + sdk.MsgTypeURL(&cosmwasmtypes.MsgExecuteContract{}), + // Change: Added MsgInstantiateContract + sdk.MsgTypeURL(&cosmwasmtypes.MsgInstantiateContract{}), + }, + } + keepers.ICAHostKeeper.SetParams(ctx, hostParams) + // Although parameters are set on InitGenesis() in RunMigrations(), we reset them here // for visibility of the final configuration. defaultConcentratedLiquidityParams := keepers.ConcentratedLiquidityKeeper.GetParams(ctx) @@ -98,7 +139,7 @@ func CreateUpgradeHandler( // Create a position to initialize the balancerPool. // Get community pool and DAI/OSMO pool address. - communityPoolAddress := keepers.AccountKeeper.GetModuleAddress(distributiontypes.ModuleName) + communityPoolAddress := keepers.AccountKeeper.GetModuleAddress(distrtypes.ModuleName) daiOsmoPool, err := keepers.PoolManagerKeeper.GetPool(ctx, DaiOsmoPoolId) if err != nil { return nil, err From 23615fdf6c2fb28e5d9400e08e7776bf6330c968 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Wed, 31 May 2023 21:15:23 -0500 Subject: [PATCH 2/4] append instead --- app/upgrades/v16/upgrades.go | 42 ++++-------------------------------- 1 file changed, 4 insertions(+), 38 deletions(-) diff --git a/app/upgrades/v16/upgrades.go b/app/upgrades/v16/upgrades.go index 8d94975b28c..2de4f06bda2 100644 --- a/app/upgrades/v16/upgrades.go +++ b/app/upgrades/v16/upgrades.go @@ -11,14 +11,7 @@ import ( "github.com/osmosis-labs/osmosis/v15/app/upgrades" cosmwasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - icahosttypes "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/host/types" - ibctransfertypes "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types" - - gammtypes "github.com/osmosis-labs/osmosis/v15/x/gamm/types" cltypes "github.com/osmosis-labs/osmosis/v15/x/concentrated-liquidity/types" superfluidtypes "github.com/osmosis-labs/osmosis/v15/x/superfluid/types" @@ -85,37 +78,10 @@ func CreateUpgradeHandler( return nil, err } - // Specifying the whole list instead of adding and removing. Less fragile. - hostParams := icahosttypes.Params{ - HostEnabled: true, - AllowMessages: []string{ - sdk.MsgTypeURL(&ibctransfertypes.MsgTransfer{}), - sdk.MsgTypeURL(&banktypes.MsgSend{}), - sdk.MsgTypeURL(&stakingtypes.MsgDelegate{}), - sdk.MsgTypeURL(&stakingtypes.MsgBeginRedelegate{}), - sdk.MsgTypeURL(&stakingtypes.MsgCreateValidator{}), - sdk.MsgTypeURL(&stakingtypes.MsgEditValidator{}), - sdk.MsgTypeURL(&stakingtypes.MsgUndelegate{}), - sdk.MsgTypeURL(&distrtypes.MsgWithdrawDelegatorReward{}), - sdk.MsgTypeURL(&distrtypes.MsgSetWithdrawAddress{}), - sdk.MsgTypeURL(&distrtypes.MsgWithdrawValidatorCommission{}), - sdk.MsgTypeURL(&distrtypes.MsgFundCommunityPool{}), - sdk.MsgTypeURL(&govtypes.MsgVote{}), - sdk.MsgTypeURL(&gammtypes.MsgJoinPool{}), - sdk.MsgTypeURL(&gammtypes.MsgExitPool{}), - sdk.MsgTypeURL(&gammtypes.MsgSwapExactAmountIn{}), - sdk.MsgTypeURL(&gammtypes.MsgSwapExactAmountOut{}), - sdk.MsgTypeURL(&gammtypes.MsgJoinSwapExternAmountIn{}), - sdk.MsgTypeURL(&gammtypes.MsgJoinSwapShareAmountOut{}), - sdk.MsgTypeURL(&gammtypes.MsgExitSwapExternAmountOut{}), - sdk.MsgTypeURL(&gammtypes.MsgExitSwapShareAmountIn{}), - sdk.MsgTypeURL(&superfluidtypes.MsgSuperfluidUnbondLock{}), - // Change: Added MsgExecuteContract - sdk.MsgTypeURL(&cosmwasmtypes.MsgExecuteContract{}), - // Change: Added MsgInstantiateContract - sdk.MsgTypeURL(&cosmwasmtypes.MsgInstantiateContract{}), - }, - } + // Add both MsgExecuteContract and MsgInstantiateContract to the list of allowed messages. + hostParams := keepers.ICAHostKeeper.GetParams(ctx) + hostParams.AllowMessages = append(hostParams.AllowMessages, sdk.MsgTypeURL(&cosmwasmtypes.MsgExecuteContract{})) + hostParams.AllowMessages = append(hostParams.AllowMessages, sdk.MsgTypeURL(&cosmwasmtypes.MsgInstantiateContract{})) keepers.ICAHostKeeper.SetParams(ctx, hostParams) // Although parameters are set on InitGenesis() in RunMigrations(), we reset them here From 92a36b3278adb9060322c33522fb1c56a6b69894 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Thu, 1 Jun 2023 12:02:06 -0500 Subject: [PATCH 3/4] check if message is in list before adding --- app/upgrades/v16/upgrades.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/upgrades/v16/upgrades.go b/app/upgrades/v16/upgrades.go index 2de4f06bda2..7a460b0aa74 100644 --- a/app/upgrades/v16/upgrades.go +++ b/app/upgrades/v16/upgrades.go @@ -80,9 +80,18 @@ func CreateUpgradeHandler( // Add both MsgExecuteContract and MsgInstantiateContract to the list of allowed messages. hostParams := keepers.ICAHostKeeper.GetParams(ctx) - hostParams.AllowMessages = append(hostParams.AllowMessages, sdk.MsgTypeURL(&cosmwasmtypes.MsgExecuteContract{})) - hostParams.AllowMessages = append(hostParams.AllowMessages, sdk.MsgTypeURL(&cosmwasmtypes.MsgInstantiateContract{})) - keepers.ICAHostKeeper.SetParams(ctx, hostParams) + exists := false + for _, msg := range hostParams.AllowMessages { + if msg == sdk.MsgTypeURL(&cosmwasmtypes.MsgExecuteContract{}) || msg == sdk.MsgTypeURL(&cosmwasmtypes.MsgInstantiateContract{}) { + exists = true + break + } + } + if !exists { + hostParams.AllowMessages = append(hostParams.AllowMessages, sdk.MsgTypeURL(&cosmwasmtypes.MsgExecuteContract{})) + hostParams.AllowMessages = append(hostParams.AllowMessages, sdk.MsgTypeURL(&cosmwasmtypes.MsgInstantiateContract{})) + keepers.ICAHostKeeper.SetParams(ctx, hostParams) + } // Although parameters are set on InitGenesis() in RunMigrations(), we reset them here // for visibility of the final configuration. From da5a349de8cece126f22f8065439093166d7c522 Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 2 Jun 2023 14:46:08 -0400 Subject: [PATCH 4/4] updates --- app/upgrades/v16/upgrades.go | 18 ++++++++++++------ app/upgrades/v16/upgrades_test.go | 6 ++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/upgrades/v16/upgrades.go b/app/upgrades/v16/upgrades.go index 7a460b0aa74..0a247698996 100644 --- a/app/upgrades/v16/upgrades.go +++ b/app/upgrades/v16/upgrades.go @@ -80,18 +80,24 @@ func CreateUpgradeHandler( // Add both MsgExecuteContract and MsgInstantiateContract to the list of allowed messages. hostParams := keepers.ICAHostKeeper.GetParams(ctx) - exists := false + msgExecuteContractExists := false + msgInstantiateContractExists := false for _, msg := range hostParams.AllowMessages { - if msg == sdk.MsgTypeURL(&cosmwasmtypes.MsgExecuteContract{}) || msg == sdk.MsgTypeURL(&cosmwasmtypes.MsgInstantiateContract{}) { - exists = true - break + if msg == sdk.MsgTypeURL(&cosmwasmtypes.MsgExecuteContract{}) { + msgExecuteContractExists = true + } + if msg == sdk.MsgTypeURL(&cosmwasmtypes.MsgInstantiateContract{}) { + msgInstantiateContractExists = true } } - if !exists { + if !msgExecuteContractExists { hostParams.AllowMessages = append(hostParams.AllowMessages, sdk.MsgTypeURL(&cosmwasmtypes.MsgExecuteContract{})) + } + + if !msgInstantiateContractExists { hostParams.AllowMessages = append(hostParams.AllowMessages, sdk.MsgTypeURL(&cosmwasmtypes.MsgInstantiateContract{})) - keepers.ICAHostKeeper.SetParams(ctx, hostParams) } + keepers.ICAHostKeeper.SetParams(ctx, hostParams) // Although parameters are set on InitGenesis() in RunMigrations(), we reset them here // for visibility of the final configuration. diff --git a/app/upgrades/v16/upgrades_test.go b/app/upgrades/v16/upgrades_test.go index fa87d49052d..c95f22a5d3b 100644 --- a/app/upgrades/v16/upgrades_test.go +++ b/app/upgrades/v16/upgrades_test.go @@ -4,6 +4,7 @@ import ( "fmt" "testing" + cosmwasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/store/prefix" @@ -123,6 +124,11 @@ func (suite *UpgradeTestSuite) TestUpgrade() { // Ensure that the protorev upgrade was successful verifyProtorevUpdateSuccess(suite) + + // Validate MsgExecuteContract and MsgInstantiateContract were added to the whitelist + icaHostAllowList := suite.App.ICAHostKeeper.GetParams(suite.Ctx) + suite.Require().Contains(icaHostAllowList.AllowMessages, sdk.MsgTypeURL(&cosmwasmtypes.MsgExecuteContract{})) + suite.Require().Contains(icaHostAllowList.AllowMessages, sdk.MsgTypeURL(&cosmwasmtypes.MsgInstantiateContract{})) }, func() { // Validate that tokenfactory params have been updated