From 7fa4daa21227ea95471f078dbaa9001499382bc1 Mon Sep 17 00:00:00 2001 From: Nicolas Lara Date: Tue, 5 Mar 2024 18:37:54 +0100 Subject: [PATCH] Wasm clients (#7637) * feat: introduce wasm clients * make tests run sequencially to avoid race conditions related to the wasm lightclient store key * use a tagged version of 08-wasm Signed-off-by: aeryz * add wasm light client to CHANGELOG.md Signed-off-by: aeryz * update go.sum * updated go version in workflows and readme * more version upgrades * undo init image base go version change * added store to upgrade * run e2e-setup * test * add back go setup * Revert "add back go setup" This reverts commit bf5226d4eec1a9c2b54c2f3ce616b1393d895a0d. * Revert "Revert "add back go setup"" This reverts commit ce50db76042f3a921ab397cefeef8ca4ea150631. * added comment for the future --------- Signed-off-by: aeryz Co-authored-by: aeryz Co-authored-by: Adam Tucker --- .../workflows/gen-upgrade-on-manual-input.yml | 5 +++-- .github/workflows/go-mod-auto-bump.yml | 2 +- .github/workflows/lint.yml | 3 ++- .github/workflows/mutest-issue-generate.yml | 2 +- .github/workflows/sim.yml | 5 +++-- .github/workflows/test.yml | 6 ++++++ .github/workflows/update-go-import-paths.yml | 3 ++- CHANGELOG.md | 1 + app/app.go | 20 +++++++++++++++++++ app/keepers/keepers.go | 17 ++++++++++++++++ app/keepers/modules.go | 2 ++ app/modules.go | 4 ++++ app/upgrades/v24/constants.go | 3 ++- go.mod | 1 + go.sum | 2 ++ proto/Dockerfile | 2 +- tests/localosmosis/README.md | 2 +- x/concentrated-liquidity/fuzz_test.go | 6 +++++- 18 files changed, 74 insertions(+), 12 deletions(-) diff --git a/.github/workflows/gen-upgrade-on-manual-input.yml b/.github/workflows/gen-upgrade-on-manual-input.yml index f59db19497d..6d205c3d1f2 100644 --- a/.github/workflows/gen-upgrade-on-manual-input.yml +++ b/.github/workflows/gen-upgrade-on-manual-input.yml @@ -29,8 +29,9 @@ jobs: - name: 🐿 Setup Golang uses: actions/setup-go@v5 with: - go-version: "^1.20" - - name: Specify input + go-version: '^1.21' + - + name: Specify input run: | env=${{ inputs.version }} if [[ $env != '' ]]; then diff --git a/.github/workflows/go-mod-auto-bump.yml b/.github/workflows/go-mod-auto-bump.yml index 16fb63651c9..0c2c31ec7ab 100644 --- a/.github/workflows/go-mod-auto-bump.yml +++ b/.github/workflows/go-mod-auto-bump.yml @@ -35,7 +35,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v5 with: - go-version: ">=1.20.0" + go-version: ">=1.21.0" - name: Fetch branches and checkout target run: | git fetch origin ${{ inputs.target-branch }} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index ee6f91ebc14..3c51aad0cc1 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -7,9 +7,10 @@ on: - concentrated-liquidity-main env: - GO_VERSION: "1.20.5" + GO_VERSION: "1.21" GIT_DIFF: + jobs: golangci: name: Run golangci-lint diff --git a/.github/workflows/mutest-issue-generate.yml b/.github/workflows/mutest-issue-generate.yml index 5078137e2f7..0f172c5d3d9 100644 --- a/.github/workflows/mutest-issue-generate.yml +++ b/.github/workflows/mutest-issue-generate.yml @@ -13,7 +13,7 @@ jobs: - name: 🐿 Setup Golang uses: actions/setup-go@v5 with: - go-version: "^1.20" + go-version: "^1.21" - name: Display go version run: go version - name: Run mutation test diff --git a/.github/workflows/sim.yml b/.github/workflows/sim.yml index f6f2a269f19..82e9b692952 100644 --- a/.github/workflows/sim.yml +++ b/.github/workflows/sim.yml @@ -14,8 +14,9 @@ jobs: - name: 🐿 Setup Golang uses: actions/setup-go@v5 with: - go-version: "^1.20" - - name: Get git diff + go-version: '^1.21' + - + name: Get git diff uses: technote-space/get-diff-action@v6.1.2 with: PATTERNS: | diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7f7376e6d8e..42466e36ee3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -45,6 +45,8 @@ jobs: steps: - name: Check out repository uses: actions/checkout@v4 + # Setup Golang based on the go.mod file. + # This is needed when the go version has changed and the code uses features from the new version.gi - name: 🐿 Setup Golang uses: actions/setup-go@v5 with: @@ -124,6 +126,10 @@ jobs: with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: 🐿 Setup Golang + uses: actions/setup-go@v5 + with: + go-version-file: go.mod - name: Build e2e image uses: docker/build-push-action@v5 with: diff --git a/.github/workflows/update-go-import-paths.yml b/.github/workflows/update-go-import-paths.yml index 8e9f8d1c175..676e6a7fc15 100644 --- a/.github/workflows/update-go-import-paths.yml +++ b/.github/workflows/update-go-import-paths.yml @@ -22,7 +22,8 @@ on: required: true env: - GO_VERSION: "1.20.5" + GO_VERSION: '1.21' + jobs: update-import-paths: diff --git a/CHANGELOG.md b/CHANGELOG.md index 849bd1809c8..85b8038e579 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [#7619](https://github.com/osmosis-labs/osmosis/pull/7619) Slight speedup/gas improvement to CL GetTotalPoolLiquidity queries * [#7623](https://github.com/osmosis-labs/osmosis/pull/7623) Add query for querying all before send hooks * [#7622](https://github.com/osmosis-labs/osmosis/pull/7622) Remove duplicate CL accumulator update logic. +* [#7503](https://github.com/osmosis-labs/osmosis/pull/7503) Add IBC wasm light clients module. ### State Compatible diff --git a/app/app.go b/app/app.go index 3f0d5f54d9c..4a5c0453d82 100644 --- a/app/app.go +++ b/app/app.go @@ -29,6 +29,8 @@ import ( slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + ibcwasmkeeper "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/keeper" + ibcwasmtypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" "github.com/cosmos/ibc-go/v7/modules/apps/transfer" ibc "github.com/cosmos/ibc-go/v7/modules/core" @@ -232,6 +234,12 @@ func NewOsmosisApp( app.homePath = homePath dataDir := filepath.Join(homePath, "data") wasmDir := filepath.Join(homePath, "wasm") + ibcWasmConfig := + ibcwasmtypes.WasmConfig{ + DataDir: filepath.Join(homePath, "ibc_08-wasm"), + SupportedCapabilities: "iterator", + ContractDebugMode: false, + } wasmConfig, err := wasm.ReadWasmConfig(appOpts) // Uncomment this for debugging contracts. In the future this could be made into a param passed by the tests // wasmConfig.ContractDebugMode = true @@ -258,6 +266,7 @@ func NewOsmosisApp( wasmConfig, wasmOpts, app.BlockedAddrs(), + ibcWasmConfig, ) // Initialize the ingest manager for propagating data to external sinks. @@ -393,6 +402,13 @@ func NewOsmosisApp( if err != nil { panic(fmt.Errorf("failed to register snapshot extension: %s", err)) } + + err = manager.RegisterExtensions( + ibcwasmkeeper.NewWasmSnapshotter(app.CommitMultiStore(), app.IBCWasmClientKeeper), + ) + if err != nil { + panic(fmt.Errorf("failed to register snapshot extension: %s", err)) + } } if loadLatest { @@ -406,6 +422,10 @@ func NewOsmosisApp( if err := app.WasmKeeper.InitializePinnedCodes(ctx); err != nil { tmos.Exit(fmt.Sprintf("failed initialize pinned codes %s", err)) } + + if err := ibcwasmkeeper.InitializePinnedCodes(ctx, appCodec); err != nil { + tmos.Exit(fmt.Sprintf("failed initialize pinned codes %s", err)) + } } return app diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 1785674e804..979cccc4baf 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -55,6 +55,8 @@ import ( ibchookstypes "github.com/osmosis-labs/osmosis/x/ibc-hooks/types" icqkeeper "github.com/cosmos/ibc-apps/modules/async-icq/v7/keeper" + ibcwasmkeeper "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/keeper" + ibcwasmtypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" icahost "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host" icahostkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/keeper" icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" @@ -143,6 +145,7 @@ type AppKeepers struct { ICAHostKeeper *icahostkeeper.Keeper ICQKeeper *icqkeeper.Keeper TransferKeeper *ibctransferkeeper.Keeper + IBCWasmClientKeeper *ibcwasmkeeper.Keeper EvidenceKeeper *evidencekeeper.Keeper GAMMKeeper *gammkeeper.Keeper TwapKeeper *twap.Keeper @@ -191,6 +194,7 @@ func (appKeepers *AppKeepers) InitNormalKeepers( wasmConfig wasmtypes.WasmConfig, wasmOpts []wasmkeeper.Option, blockedAddress map[string]bool, + ibcWasmConfig ibcwasmtypes.WasmConfig, ) { legacyAmino := encodingConfig.Amino // Add 'normal' keepers @@ -271,6 +275,18 @@ func (appKeepers *AppKeepers) InitNormalKeepers( ) appKeepers.IBCHooksKeeper = hooksKeeper + // We are using a separate VM here + ibcWasmClientKeeper := ibcwasmkeeper.NewKeeperWithConfig( + appCodec, + appKeepers.keys[ibcwasmtypes.StoreKey], + appKeepers.IBCKeeper.ClientKeeper, + authtypes.NewModuleAddress(govtypes.ModuleName).String(), + ibcWasmConfig, + bApp.GRPCQueryRouter(), + ) + + appKeepers.IBCWasmClientKeeper = &ibcWasmClientKeeper + appKeepers.WireICS20PreWasmKeeper(appCodec, bApp, appKeepers.IBCHooksKeeper) icaHostKeeper := icahostkeeper.NewKeeper( @@ -812,6 +828,7 @@ func KVStoreKeys() []string { upgradetypes.StoreKey, evidencetypes.StoreKey, ibctransfertypes.StoreKey, + ibcwasmtypes.StoreKey, capabilitytypes.StoreKey, gammtypes.StoreKey, twaptypes.StoreKey, diff --git a/app/keepers/modules.go b/app/keepers/modules.go index 6517a169efc..925d9bdee57 100644 --- a/app/keepers/modules.go +++ b/app/keepers/modules.go @@ -27,6 +27,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/upgrade" upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client" icq "github.com/cosmos/ibc-apps/modules/async-icq/v7" + ibcwasm "github.com/cosmos/ibc-go/modules/light-clients/08-wasm" ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts" "github.com/cosmos/cosmos-sdk/x/consensus" @@ -125,6 +126,7 @@ var AppModuleBasics = []module.AppModuleBasic{ ica.AppModuleBasic{}, ibc_hooks.AppModuleBasic{}, ibcratelimitmodule.AppModuleBasic{}, + ibcwasm.AppModuleBasic{}, packetforward.AppModuleBasic{}, cosmwasmpoolmodule.AppModuleBasic{}, tendermint.AppModuleBasic{}, diff --git a/app/modules.go b/app/modules.go index 3dd1b9192dc..51aba73d549 100644 --- a/app/modules.go +++ b/app/modules.go @@ -11,6 +11,8 @@ import ( stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" icq "github.com/cosmos/ibc-apps/modules/async-icq/v7" + ibcwasm "github.com/cosmos/ibc-go/modules/light-clients/08-wasm" + ibcwasmtypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" ibc "github.com/cosmos/ibc-go/v7/modules/core" ibchost "github.com/cosmos/ibc-go/v7/modules/core/exported" @@ -162,6 +164,7 @@ func appModules( evidence.NewAppModule(*app.EvidenceKeeper), authzmodule.NewAppModule(appCodec, *app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), ibc.NewAppModule(app.IBCKeeper), + ibcwasm.NewAppModule(*app.IBCWasmClientKeeper), ica.NewAppModule(nil, app.ICAHostKeeper), params.NewAppModule(*app.ParamsKeeper), consensus.NewAppModule(appCodec, *app.AppKeepers.ConsensusParamsKeeper), @@ -280,6 +283,7 @@ func OrderInitGenesis(allModuleNames []string) []string { ibcratelimittypes.ModuleName, // wasm after ibc transfer wasmtypes.ModuleName, + ibcwasmtypes.ModuleName, // ibc_hooks after auth keeper ibchookstypes.ModuleName, icqtypes.ModuleName, diff --git a/app/upgrades/v24/constants.go b/app/upgrades/v24/constants.go index 05afd03dc96..2573fa4a96a 100644 --- a/app/upgrades/v24/constants.go +++ b/app/upgrades/v24/constants.go @@ -1,6 +1,7 @@ package v24 import ( + ibcwasmtypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" "github.com/osmosis-labs/osmosis/v23/app/upgrades" store "github.com/cosmos/cosmos-sdk/store/types" @@ -13,7 +14,7 @@ var Upgrade = upgrades.Upgrade{ UpgradeName: UpgradeName, CreateUpgradeHandler: CreateUpgradeHandler, StoreUpgrades: store.StoreUpgrades{ - Added: []string{}, + Added: []string{ibcwasmtypes.StoreKey}, Deleted: []string{}, }, } diff --git a/go.mod b/go.mod index 10a277bf642..13ac0a27d5e 100644 --- a/go.mod +++ b/go.mod @@ -17,6 +17,7 @@ require ( github.com/cosmos/gogoproto v1.4.11 github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7 v7.1.1 github.com/cosmos/ibc-apps/modules/async-icq/v7 v7.1.1 + github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.1.1-0.20231213092633-b306e7a706e1 github.com/cosmos/ibc-go/v7 v7.3.2 github.com/golang/mock v1.6.0 github.com/golang/protobuf v1.5.3 diff --git a/go.sum b/go.sum index aabcfc913b5..6f167da32b5 100644 --- a/go.sum +++ b/go.sum @@ -778,6 +778,8 @@ github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7 v7.1.1 h1:PqI github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7 v7.1.1/go.mod h1:UvDmcGIWJPIytq+Q78/ff5NTOsuX/7IrNgEugTW5i0s= github.com/cosmos/ibc-apps/modules/async-icq/v7 v7.1.1 h1:02RCbih5lQ8aGdDMSvxhTnk5JDLEDitn17ytEE1Qhko= github.com/cosmos/ibc-apps/modules/async-icq/v7 v7.1.1/go.mod h1:LvVkEXTORVgd87W2Yu7ZY3acKKeTMq/txdTworn8EZI= +github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.1.1-0.20231213092633-b306e7a706e1 h1:fCtG9qasnNzhgxGR1jM9eBufZ5WQVpy0KdaOpKRfg8Y= +github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.1.1-0.20231213092633-b306e7a706e1/go.mod h1:h114vYKBtI5zKBeSyr8y5JZ8ZtpQJInO4TYww2IQr6o= github.com/cosmos/ibc-go/v7 v7.3.2 h1:FeUDcBX7VYY0e0iRmcVkPPUjYfAqIc//QuHXo8JHz9c= github.com/cosmos/ibc-go/v7 v7.3.2/go.mod h1:IMeOXb7gwpZ+/nOG5BuUkdW4weM1ezvN4PQPws4uzOI= github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM= diff --git a/proto/Dockerfile b/proto/Dockerfile index e390388b6ba..a72cb10a415 100644 --- a/proto/Dockerfile +++ b/proto/Dockerfile @@ -3,7 +3,7 @@ FROM bufbuild/buf:1.7.0 as BUILDER -FROM golang:1.20-alpine +FROM golang:1.21-alpine RUN apk add --no-cache \ diff --git a/tests/localosmosis/README.md b/tests/localosmosis/README.md index 416af4ff4ca..9039e2aa03a 100644 --- a/tests/localosmosis/README.md +++ b/tests/localosmosis/README.md @@ -268,7 +268,7 @@ services: # dockerfile: Dockerfile # args: # RUNNER_IMAGE: alpine:3.17 - # GO_VERSION: 1.20 + # GO_VERSION: 1.21 ``` 2. Checkout the Osmosis repository to a different `ref` that includes the new version, and then rebuild and restart LocalOsmosis using `make localnet-start`. Make sure to don't delete your `~/.osmosisd-local` folder. diff --git a/x/concentrated-liquidity/fuzz_test.go b/x/concentrated-liquidity/fuzz_test.go index 19b51e8b3b5..67aa680d71e 100644 --- a/x/concentrated-liquidity/fuzz_test.go +++ b/x/concentrated-liquidity/fuzz_test.go @@ -64,7 +64,11 @@ func fuzz(t *testing.T, numSwaps int, numPositions int, numIterations int) { currentSuite.iteration = i t.Run(fmt.Sprintf("Fuzz %d, seed: %d", i, currentSeed), func(t *testing.T) { - t.Parallel() + // This is commented out temporarily to avoid issues with the wasmStoreKey being + // a global in the wasm light client. + // See https://github.com/cosmos/ibc-go/blob/modules/light-clients/08-wasm/v0.1.0%2Bibc-go-v7.3-wasmvm-v1.5/modules/light-clients/08-wasm/internal/ibcwasm/wasm.go#L15-L17 + // Once we move to ibc v8 we can make these tests run in parallel again. + //t.Parallel() currentSuite.individualFuzz(r, i, numSwaps, numPositions) })