From 36d1bcbc81e1e59c7b9533bb381a8d41484e9c84 Mon Sep 17 00:00:00 2001 From: Jacob Gadikian Date: Wed, 6 Sep 2023 12:44:42 +0800 Subject: [PATCH] add ibc hooks and begin upgrade prep --- app/app.go | 54 +++++++++++++++++++++++++++++--- app/encoding.go | 2 +- app/test_access.go | 2 +- app/upgrades/v2/constants.go | 2 +- app/upgrades/v2_2_5/constants.go | 2 +- app/upgrades/v3/constants.go | 15 +++++++++ app/upgrades/v3/upgrades.go | 19 +++++++++++ cmd/migalood/cmd/cmd_test.go | 4 +-- cmd/migalood/cmd/root.go | 4 +-- cmd/migalood/main.go | 4 +-- go.mod | 8 ++--- go.sum | 9 ++++-- 12 files changed, 102 insertions(+), 23 deletions(-) create mode 100644 app/upgrades/v3/constants.go create mode 100644 app/upgrades/v3/upgrades.go diff --git a/app/app.go b/app/app.go index ac320552..e248b321 100644 --- a/app/app.go +++ b/app/app.go @@ -100,6 +100,12 @@ import ( ibcmock "github.com/cosmos/ibc-go/v6/testing/mock" bank "github.com/terra-money/alliance/custom/bank" custombankkeeper "github.com/terra-money/alliance/custom/bank/keeper" + + // use TFL's ibc-hooks from Osmosis' ibc-hooks + ibchooks "github.com/terra-money/core/v2/x/ibc-hooks" + ibchookskeeper "github.com/terra-money/core/v2/x/ibc-hooks/keeper" + ibchookstypes "github.com/terra-money/core/v2/x/ibc-hooks/types" + alliancemodule "github.com/terra-money/alliance/x/alliance" alliancemoduleclient "github.com/terra-money/alliance/x/alliance/client" alliancemodulekeeper "github.com/terra-money/alliance/x/alliance/keeper" @@ -131,15 +137,15 @@ import ( "github.com/CosmWasm/wasmd/x/wasm" wasmclient "github.com/CosmWasm/wasmd/x/wasm/client" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" - wasmappparams "github.com/White-Whale-Defi-Platform/migaloo-chain/v2/app/params" + wasmappparams "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/app/params" // unnamed import of statik for swagger UI support _ "github.com/cosmos/cosmos-sdk/client/docs/statik" // Upgrade Handler - upgrades "github.com/White-Whale-Defi-Platform/migaloo-chain/v2/app/upgrades" - v2 "github.com/White-Whale-Defi-Platform/migaloo-chain/v2/app/upgrades/v2" - v2_2_5 "github.com/White-Whale-Defi-Platform/migaloo-chain/v2/app/upgrades/v2_2_5" + upgrades "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/app/upgrades" + v2 "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/app/upgrades/v2" + v2_2_5 "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/app/upgrades/v2_2_5" ) const ( @@ -227,6 +233,7 @@ var ( ica.AppModuleBasic{}, intertx.AppModuleBasic{}, ibcfee.AppModuleBasic{}, + ibchooks.AppModuleBasic{}, ) // module account permissions @@ -292,6 +299,12 @@ type MigalooApp struct { WasmKeeper wasm.Keeper RouterKeeper routerkeeper.Keeper + // IBC hooks + IBCHooksKeeper *ibchookskeeper.Keeper + TransferStack *ibchooks.IBCMiddleware + Ics20WasmHooks *ibchooks.WasmHooks + HooksICS4Wrapper ibchooks.ICS4Middleware + ScopedIBCKeeper capabilitykeeper.ScopedKeeper ScopedICAHostKeeper capabilitykeeper.ScopedKeeper ScopedICAControllerKeeper capabilitykeeper.ScopedKeeper @@ -339,7 +352,7 @@ func NewMigalooApp( evidencetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey, feegrant.StoreKey, authzkeeper.StoreKey, wasm.StoreKey, icahosttypes.StoreKey, icacontrollertypes.StoreKey, intertxtypes.StoreKey, ibcfeetypes.StoreKey, tokenfactorytypes.StoreKey, - alliancemoduletypes.StoreKey, + alliancemoduletypes.StoreKey, ibchookstypes.StoreKey, ) tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey) memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) @@ -516,6 +529,22 @@ func NewMigalooApp( app.IBCKeeper.ChannelKeeper, ) + // Configure the hooks keeper + hooksKeeper := ibchookskeeper.NewKeeper( + keys[ibchookstypes.StoreKey], + ) + app.IBCHooksKeeper = &hooksKeeper + wasmHooks := ibchooks.NewWasmHooks(&hooksKeeper, nil, "whale") // The contract keeper needs to be set later + app.Ics20WasmHooks = &wasmHooks + app.HooksICS4Wrapper = ibchooks.NewICS4Middleware( + app.IBCKeeper.ChannelKeeper, + app.Ics20WasmHooks, + ) + + // Hooks Middleware + hooksTransferStack := ibchooks.NewIBCMiddleware(&transferIBCModule, &app.HooksICS4Wrapper) + app.TransferStack = &hooksTransferStack + // IBC Fee Module keeper app.IBCFeeKeeper = ibcfeekeeper.NewKeeper( appCodec, keys[ibcfeetypes.StoreKey], @@ -705,6 +734,7 @@ func NewMigalooApp( intertx.NewAppModule(appCodec, app.InterTxKeeper), tokenfactory.NewAppModule(app.TokenFactoryKeeper, app.AccountKeeper, app.BankKeeper), router.NewAppModule(&app.RouterKeeper), + ibchooks.NewAppModule(app.AccountKeeper), crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants), // always be last to make sure that it checks for all invariants and not only part of them ) @@ -736,6 +766,7 @@ func NewMigalooApp( icatypes.ModuleName, ibcfeetypes.ModuleName, intertxtypes.ModuleName, + ibchookstypes.ModuleName, wasm.ModuleName, tokenfactorytypes.ModuleName, alliancemoduletypes.ModuleName, @@ -765,6 +796,7 @@ func NewMigalooApp( icatypes.ModuleName, ibcfeetypes.ModuleName, intertxtypes.ModuleName, + ibchookstypes.ModuleName, wasm.ModuleName, tokenfactorytypes.ModuleName, alliancemoduletypes.ModuleName, @@ -803,6 +835,7 @@ func NewMigalooApp( intertxtypes.ModuleName, tokenfactorytypes.ModuleName, // wasm after ibc transfer + ibchookstypes.ModuleName, wasm.ModuleName, routertypes.ModuleName, alliancemoduletypes.ModuleName, @@ -1071,6 +1104,17 @@ func (app *MigalooApp) setupUpgradeHandlers(cfg module.Configurator) { } } +// TODO: ensure that we include this or its equivalent in the actual upgrade, referencing our v3 upgrade +// Add stores for new modules +// if upgradeInfo.Name == terraappconfig.Upgrade2_3_0 && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { +// storeUpgrades := storetypes.StoreUpgrades{ +// Added: []string{ +// ibchookstypes.StoreKey, +// }, +// } +// app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades)) +// } + // GetMaccPerms returns a copy of the module account permissions func GetMaccPerms() map[string][]string { dupMaccPerms := make(map[string][]string) diff --git a/app/encoding.go b/app/encoding.go index b3cee7a1..29c80f5b 100644 --- a/app/encoding.go +++ b/app/encoding.go @@ -3,7 +3,7 @@ package app import ( "github.com/cosmos/cosmos-sdk/std" - "github.com/White-Whale-Defi-Platform/migaloo-chain/v2/app/params" + "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/app/params" ) // MakeEncodingConfig creates a new EncodingConfig with all modules registered diff --git a/app/test_access.go b/app/test_access.go index 0e643ba5..0d52b4df 100644 --- a/app/test_access.go +++ b/app/test_access.go @@ -6,7 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" - "github.com/White-Whale-Defi-Platform/migaloo-chain/v2/app/params" + "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/app/params" "github.com/cosmos/cosmos-sdk/codec" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" diff --git a/app/upgrades/v2/constants.go b/app/upgrades/v2/constants.go index ba8a213e..de3950cd 100644 --- a/app/upgrades/v2/constants.go +++ b/app/upgrades/v2/constants.go @@ -1,7 +1,7 @@ package v2 import ( - "github.com/White-Whale-Defi-Platform/migaloo-chain/v2/app/upgrades" + "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/app/upgrades" store "github.com/cosmos/cosmos-sdk/store/types" alliancetypes "github.com/terra-money/alliance/x/alliance/types" ) diff --git a/app/upgrades/v2_2_5/constants.go b/app/upgrades/v2_2_5/constants.go index 92300d93..3b71041c 100644 --- a/app/upgrades/v2_2_5/constants.go +++ b/app/upgrades/v2_2_5/constants.go @@ -1,7 +1,7 @@ package v2_2_5 //nolint:revive // skip linter for this package name import ( - "github.com/White-Whale-Defi-Platform/migaloo-chain/v2/app/upgrades" + "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/app/upgrades" store "github.com/cosmos/cosmos-sdk/store/types" ) diff --git a/app/upgrades/v3/constants.go b/app/upgrades/v3/constants.go new file mode 100644 index 00000000..4f3817d1 --- /dev/null +++ b/app/upgrades/v3/constants.go @@ -0,0 +1,15 @@ +package v3 //nolint:revive // skip linter for this package name + +import ( + "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/app/upgrades" + store "github.com/cosmos/cosmos-sdk/store/types" +) + +// UpgradeName defines the on-chain upgrade name for the Migaloo v2 upgrade. +const UpgradeName = "v2.2.5" + +var Upgrade = upgrades.Upgrade{ + UpgradeName: UpgradeName, + CreateUpgradeHandler: CreateUpgradeHandler, + StoreUpgrades: store.StoreUpgrades{}, +} diff --git a/app/upgrades/v3/upgrades.go b/app/upgrades/v3/upgrades.go new file mode 100644 index 00000000..e8ab8fbe --- /dev/null +++ b/app/upgrades/v3/upgrades.go @@ -0,0 +1,19 @@ +package v3 //nolint:revive // skip linter for this package name + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" +) + +// We set the app version to pre-upgrade because it will be incremented by one +// after the upgrade is applied by the handler. + +func CreateUpgradeHandler( + mm *module.Manager, + configurator module.Configurator, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, _plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + return mm.RunMigrations(ctx, configurator, vm) + } +} diff --git a/cmd/migalood/cmd/cmd_test.go b/cmd/migalood/cmd/cmd_test.go index 597c8809..f27fd8bf 100644 --- a/cmd/migalood/cmd/cmd_test.go +++ b/cmd/migalood/cmd/cmd_test.go @@ -6,8 +6,8 @@ import ( "github.com/stretchr/testify/require" - "github.com/White-Whale-Defi-Platform/migaloo-chain/v2/app" - "github.com/White-Whale-Defi-Platform/migaloo-chain/v2/cmd/migalood/cmd" + "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/app" + "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/cmd/migalood/cmd" "github.com/cosmos/cosmos-sdk/client/flags" svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" "github.com/cosmos/cosmos-sdk/simapp" diff --git a/cmd/migalood/cmd/root.go b/cmd/migalood/cmd/root.go index 3f65d434..e7763650 100644 --- a/cmd/migalood/cmd/root.go +++ b/cmd/migalood/cmd/root.go @@ -23,8 +23,8 @@ import ( "github.com/CosmWasm/wasmd/x/wasm" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" - "github.com/White-Whale-Defi-Platform/migaloo-chain/v2/app" - "github.com/White-Whale-Defi-Platform/migaloo-chain/v2/app/params" + "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/app" + "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/app/params" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/cmd/migalood/main.go b/cmd/migalood/main.go index b0e90693..5278e631 100644 --- a/cmd/migalood/main.go +++ b/cmd/migalood/main.go @@ -3,8 +3,8 @@ package main import ( "os" - "github.com/White-Whale-Defi-Platform/migaloo-chain/v2/app" - "github.com/White-Whale-Defi-Platform/migaloo-chain/v2/cmd/migalood/cmd" + "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/app" + "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/cmd/migalood/cmd" "github.com/cosmos/cosmos-sdk/server" svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" ) diff --git a/go.mod b/go.mod index c2726d4e..1fcbc690 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/White-Whale-Defi-Platform/migaloo-chain/v2 +module github.com/White-Whale-Defi-Platform/migaloo-chain/v3 go 1.21 @@ -19,6 +19,7 @@ require ( github.com/tendermint/tendermint v0.34.29 github.com/tendermint/tm-db v0.6.8-0.20221109095132-774cdfe7e6b0 github.com/terra-money/alliance v0.1.2 + github.com/terra-money/core/v2 v2.4.1 ) require ( @@ -64,7 +65,7 @@ require ( github.com/dgraph-io/badger/v3 v3.2103.2 // indirect github.com/dgraph-io/ristretto v0.1.0 // indirect github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect - github.com/docker/distribution v2.8.1+incompatible // indirect + github.com/docker/distribution v2.8.2+incompatible // indirect github.com/dustin/go-humanize v1.0.1-0.20200219035652-afde56e7acac // indirect github.com/dvsekhvalnov/jose2go v1.5.0 // indirect github.com/felixge/httpsnoop v1.0.1 // indirect @@ -186,6 +187,3 @@ replace ( github.com/tendermint/tendermint => github.com/cometbft/cometbft v0.34.29 ) - -// subject to a bug in the group module and gov module migration -retract [v2.0.0, v2.2.2] diff --git a/go.sum b/go.sum index 5bdbe0b3..adf5f8be 100644 --- a/go.sum +++ b/go.sum @@ -444,8 +444,8 @@ github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8 github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc= github.com/dnaeon/go-vcr v1.1.0/go.mod h1:M7tiix8f0r6mKKJ3Yq/kqU1OYf3MnfmBWVbPx/yU9ko= github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ= -github.com/docker/distribution v2.8.1+incompatible h1:Q50tZOPR6T/hjNsyc9g8/syEs6bk8XXApsHjKukMl68= -github.com/docker/distribution v2.8.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= +github.com/docker/distribution v2.8.2+incompatible h1:T3de5rq0dB1j30rp0sA2rER+m322EBzniBPB6ZIzuh8= +github.com/docker/distribution v2.8.2+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= github.com/docker/docker v1.4.2-0.20180625184442-8e610b2b55bf/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= @@ -945,8 +945,9 @@ github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6 github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= -github.com/onsi/ginkgo v1.14.0 h1:2mOpI4JVVPBN+WQRa0WKH2eXR+Ey+uK4n7Zj0aYpIQA= github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= +github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc= +github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= @@ -1141,6 +1142,8 @@ github.com/tendermint/tm-db v0.6.8-0.20221109095132-774cdfe7e6b0 h1:mQuaSKG8GtmA github.com/tendermint/tm-db v0.6.8-0.20221109095132-774cdfe7e6b0/go.mod h1:J/0Izsq+rOsOHxSD2dirEhtpB576Fo5iyz0eTn26TBs= github.com/terra-money/alliance v0.1.2 h1:njhEhK0om+ODx+KuwuAS5vtgGM8PAv4pdDdHAXMQI84= github.com/terra-money/alliance v0.1.2/go.mod h1:trkbLiiHCx4CD5nlBVD9DjubDDL6437zO8/O3zB3efk= +github.com/terra-money/core/v2 v2.4.1 h1:r90bEXWai2hBs+8KP2ZyT7CBRsEHLb35qgsx1+lc2Fs= +github.com/terra-money/core/v2 v2.4.1/go.mod h1:WSFA0LWlni0X2Lj01gFAP7z/A3H92D/j7JkFZ4CXOn4= github.com/tidwall/btree v1.5.0 h1:iV0yVY/frd7r6qGBXfEYs7DH0gTDgrKTrDjS7xt/IyQ= github.com/tidwall/btree v1.5.0/go.mod h1:LGm8L/DZjPLmeWGjv5kFrY8dL4uVhMmzmmLYmsObdKE= github.com/tidwall/gjson v1.12.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=