Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBCWasm upgrade test and fix #269

Merged
merged 6 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
wasmvm "github.com/CosmWasm/wasmvm/v2"
"github.com/gorilla/mux"
aa "github.com/larry0x/abstract-account/x/abstractaccount"
aakeeper "github.com/larry0x/abstract-account/x/abstractaccount/keeper"
Expand Down Expand Up @@ -40,6 +41,9 @@ import (
"github.com/cosmos/ibc-go/modules/capability"
capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
ibcwasm "github.com/cosmos/ibc-go/modules/light-clients/08-wasm"
ibcwasmkeeper "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/keeper"
ibcwasmtypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types"
ica "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts"
icacontroller "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller"
icacontrollerkeeper "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/keeper"
Expand Down Expand Up @@ -274,6 +278,7 @@ type WasmApp struct {
ICAHostKeeper icahostkeeper.Keeper
TransferKeeper ibctransferkeeper.Keeper
WasmKeeper wasmkeeper.Keeper
WasmClientKeeper ibcwasmkeeper.Keeper
AbstractAccountKeeper aakeeper.Keeper
IBCHooksKeeper *ibchookskeeper.Keeper
ContractKeeper *wasmkeeper.PermissionedKeeper
Expand Down Expand Up @@ -353,7 +358,7 @@ func NewWasmApp(
nftkeeper.StoreKey, group.StoreKey,
// non sdk store keys
ibcexported.StoreKey, ibctransfertypes.StoreKey, ibcfeetypes.StoreKey,
wasmtypes.StoreKey, icahosttypes.StoreKey,
ibcwasmtypes.StoreKey, wasmtypes.StoreKey, icahosttypes.StoreKey,
aatypes.StoreKey, icacontrollertypes.StoreKey, globalfee.StoreKey,
xiontypes.StoreKey, ibchookstypes.StoreKey, packetforwardtypes.StoreKey,
feeabstypes.StoreKey, jwktypes.StoreKey, tokenfactorytypes.StoreKey,
Expand Down Expand Up @@ -708,6 +713,22 @@ func NewWasmApp(
wasmOpts = append(owasm.RegisterStargateQueries(*app.GRPCQueryRouter(), appCodec), wasmOpts...)
wasmOpts = append(wasmOpts, tokenFactoryOpts...)

// instantiate the Wasm VM with the chosen parameters
// we need to create this double wasm dir because the wasmd Keeper appends an extra `wasm/` to the value you give it
doubleWasmDir := filepath.Join(wasmDir, "wasm")
wasmVM, err := wasmvm.NewVM(
doubleWasmDir,
availableCapabilities,
WasmContractMemoryLimit, // default of 32
wasmConfig.ContractDebugMode,
wasmConfig.MemoryCacheSize,
)
if err != nil {
panic(err)
}

wasmOpts = append(wasmOpts, wasmkeeper.WithWasmEngine(wasmVM))

app.WasmKeeper = wasmkeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(keys[wasmtypes.StoreKey]),
Expand All @@ -729,6 +750,15 @@ func NewWasmApp(
wasmOpts...,
)

app.WasmClientKeeper = ibcwasmkeeper.NewKeeperWithVM(
appCodec,
runtime.NewKVStoreService(keys[ibcwasmtypes.StoreKey]),
app.IBCKeeper.ClientKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
wasmVM,
app.GRPCQueryRouter(),
)

app.AbstractAccountKeeper = aakeeper.NewKeeper(
appCodec,
keys[aatypes.StoreKey],
Expand Down Expand Up @@ -837,6 +867,7 @@ func NewWasmApp(
xion.NewAppModule(app.XionKeeper),
ibc.NewAppModule(app.IBCKeeper),
ibctm.NewAppModule(),
ibcwasm.NewAppModule(app.WasmClientKeeper),
transfer.NewAppModule(app.TransferKeeper),
ibcfee.NewAppModule(app.IBCFeeKeeper),
ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper),
Expand Down Expand Up @@ -889,6 +920,7 @@ func NewWasmApp(
feeabstypes.ModuleName,
icatypes.ModuleName,
ibcfeetypes.ModuleName,
ibcwasmtypes.ModuleName,
wasmtypes.ModuleName,
aatypes.ModuleName,
xiontypes.ModuleName,
Expand All @@ -914,6 +946,7 @@ func NewWasmApp(
feeabstypes.ModuleName,
icatypes.ModuleName,
ibcfeetypes.ModuleName,
ibcwasmtypes.ModuleName,
wasmtypes.ModuleName,
aatypes.ModuleName,
ibchookstypes.ModuleName,
Expand Down Expand Up @@ -945,6 +978,7 @@ func NewWasmApp(
feeabstypes.ModuleName,
icatypes.ModuleName,
ibcfeetypes.ModuleName,
ibcwasmtypes.ModuleName,
// wasm after ibc transfer
wasmtypes.ModuleName,
aatypes.ModuleName,
Expand Down Expand Up @@ -1313,6 +1347,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(aatypes.ModuleName)
paramsKeeper.Subspace(packetforwardtypes.ModuleName)
paramsKeeper.Subspace(feeabstypes.ModuleName)
paramsKeeper.Subspace(ibcwasmtypes.ModuleName)

// IBC params migration - legacySubspace to selfManaged
// https://github.com/cosmos/ibc-go/blob/main/docs/docs/05-migrations/11-v7-to-v8.md#params-migration
Expand Down
2 changes: 1 addition & 1 deletion app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/cosmos/cosmos-sdk/types/module"
)

const UpgradeName = "v12"
const UpgradeName = "v13"

func (app *WasmApp) RegisterUpgradeHandlers() {
app.WrapSetUpgradeHandler(UpgradeName)
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func InitializeWasmApp(b testing.TB, db dbm.DB, numAccounts int) AppInfo {
Label: "Demo contract",
Msg: initBz,
}
gasWanted := 500000 + 10000*uint64(numAccounts)
gasWanted := 500000 + 10000*uint64(numAccounts) // nolint:gosec
initTx, err := simtestutil.GenSignedMockTx(r, txGen, []sdk.Msg{&initMsg}, nil, gasWanted, "", []uint64{0}, []uint64{1}, minter)
require.NoError(b, err)
_, res, err := wasmApp.SimDeliver(txGen.TxEncoder(), initTx)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ require (
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8 v8.0.2
github.com/cosmos/ibc-apps/modules/ibc-hooks/v8 v8.0.0-20240530162148-4827cf263165
github.com/cosmos/ibc-go/modules/capability v1.0.1
github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.4.2-0.20240730185033-ccd4dc278e72
github.com/cosmos/ibc-go/v8 v8.5.1
github.com/cosmos/rosetta v0.50.6
github.com/dvsekhvalnov/jose2go v1.6.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ github.com/cosmos/ibc-go/modules/apps/callbacks v0.2.1-0.20231113120333-342c00b0
github.com/cosmos/ibc-go/modules/apps/callbacks v0.2.1-0.20231113120333-342c00b0f8bd/go.mod h1:JWfpWVKJKiKtd53/KbRoKfxWl8FsT2GPcNezTOk0o5Q=
github.com/cosmos/ibc-go/modules/capability v1.0.1 h1:ibwhrpJ3SftEEZRxCRkH0fQZ9svjthrX2+oXdZvzgGI=
github.com/cosmos/ibc-go/modules/capability v1.0.1/go.mod h1:rquyOV262nGJplkumH+/LeYs04P3eV8oB7ZM4Ygqk4E=
github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.4.2-0.20240730185033-ccd4dc278e72 h1:QjCi4bJoy9AXLL1e4jqi+4rHYN0gGZAQxf937cdWhw4=
github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.4.2-0.20240730185033-ccd4dc278e72/go.mod h1:yiulzyQAZ+Ci802z/kVQqTA3lGiSJOmDpTq7kZxOUNE=
github.com/cosmos/ibc-go/v8 v8.5.1 h1:3JleEMKBjRKa3FeTKt4fjg22za/qygLBo7mDkoYTNBs=
github.com/cosmos/ibc-go/v8 v8.5.1/go.mod h1:P5hkAvq0Qbg0h18uLxDVA9q1kOJ0l36htMsskiNwXbo=
github.com/cosmos/ics23/go v0.11.0 h1:jk5skjT0TqX5e5QJbEnwXIS2yI2vnmLOgpQPeM5RtnU=
Expand Down
1 change: 1 addition & 0 deletions integration_tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/cosmos/cosmos-sdk v0.50.10
github.com/cosmos/gogoproto v1.7.0
github.com/cosmos/ibc-go/modules/capability v1.0.1
github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.4.2-0.20240730185033-ccd4dc278e72
github.com/cosmos/ibc-go/v8 v8.5.1
github.com/cosmos/interchain-security/v5 v5.0.0-alpha1.0.20240424193412-7cd900ad2a74
github.com/docker/docker v24.0.9+incompatible
Expand Down
2 changes: 2 additions & 0 deletions integration_tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,8 @@ github.com/cosmos/ibc-go/modules/apps/callbacks v0.2.1-0.20231113120333-342c00b0
github.com/cosmos/ibc-go/modules/apps/callbacks v0.2.1-0.20231113120333-342c00b0f8bd/go.mod h1:JWfpWVKJKiKtd53/KbRoKfxWl8FsT2GPcNezTOk0o5Q=
github.com/cosmos/ibc-go/modules/capability v1.0.1 h1:ibwhrpJ3SftEEZRxCRkH0fQZ9svjthrX2+oXdZvzgGI=
github.com/cosmos/ibc-go/modules/capability v1.0.1/go.mod h1:rquyOV262nGJplkumH+/LeYs04P3eV8oB7ZM4Ygqk4E=
github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.4.2-0.20240730185033-ccd4dc278e72 h1:QjCi4bJoy9AXLL1e4jqi+4rHYN0gGZAQxf937cdWhw4=
github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.4.2-0.20240730185033-ccd4dc278e72/go.mod h1:yiulzyQAZ+Ci802z/kVQqTA3lGiSJOmDpTq7kZxOUNE=
github.com/cosmos/ibc-go/v8 v8.5.1 h1:3JleEMKBjRKa3FeTKt4fjg22za/qygLBo7mDkoYTNBs=
github.com/cosmos/ibc-go/v8 v8.5.1/go.mod h1:P5hkAvq0Qbg0h18uLxDVA9q1kOJ0l36htMsskiNwXbo=
github.com/cosmos/ics23/go v0.11.0 h1:jk5skjT0TqX5e5QJbEnwXIS2yI2vnmLOgpQPeM5RtnU=
Expand Down
151 changes: 142 additions & 9 deletions integration_tests/upgrade_ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,45 @@ package integration_tests

import (
"context"
"encoding/json"
"os"
"path"
"strconv"
"testing"
"time"

"cosmossdk.io/x/upgrade"

"github.com/CosmWasm/wasmd/x/wasm"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/burnt-labs/xion/x/jwk"
"github.com/burnt-labs/xion/x/mint"
"github.com/burnt-labs/xion/x/xion"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
"github.com/cosmos/cosmos-sdk/x/auth"
authz "github.com/cosmos/cosmos-sdk/x/authz/module"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/consensus"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
"github.com/cosmos/cosmos-sdk/x/gov"
govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
"github.com/cosmos/cosmos-sdk/x/params"
paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/cosmos/ibc-go/modules/capability"
ibcwasm "github.com/cosmos/ibc-go/modules/light-clients/08-wasm"
"github.com/cosmos/ibc-go/v8/modules/apps/transfer"
ibccore "github.com/cosmos/ibc-go/v8/modules/core"
ibcsolomachine "github.com/cosmos/ibc-go/v8/modules/light-clients/06-solomachine"
ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"
ibclocalhost "github.com/cosmos/ibc-go/v8/modules/light-clients/09-localhost"
ccvprovider "github.com/cosmos/interchain-security/v5/x/ccv/provider"
aa "github.com/larry0x/abstract-account/x/abstractaccount"
"github.com/strangelove-ventures/tokenfactory/x/tokenfactory"

"cosmossdk.io/math"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
"github.com/strangelove-ventures/interchaintest/v8/conformance"
Expand All @@ -22,10 +57,10 @@ import (

const (
xionImageFrom = "ghcr.io/burnt-labs/xion/heighliner"
xionVersionFrom = "9.0.1-rc2"
xionImageTo = "ghcr.io/burnt-labs/xion/heighliner"
xionVersionTo = "sha-7bba345"
xionUpgradeName = "v12"
xionVersionFrom = "12.0.1"
xionImageTo = "xion"
xionVersionTo = "local"
xionUpgradeName = "v13"

osmosisImage = "ghcr.io/strangelove-ventures/heighliner/osmosis"
osmosisVersion = "v25.2.1"
Expand Down Expand Up @@ -61,7 +96,45 @@ func TestXionUpgradeIBC(t *testing.T) {
Bech32Prefix: "xion",
Denom: "uxion",
TrustingPeriod: ibcClientTrustingPeriod,
ModifyGenesis: ModifyInterChainGenesis(ModifyInterChainGenesisFn{ModifyGenesisShortProposals}, [][]string{{votingPeriod, maxDepositPeriod}}),
EncodingConfig: func() *moduletestutil.TestEncodingConfig {
cfg := moduletestutil.MakeTestEncodingConfig(
auth.AppModuleBasic{},
genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator),
bank.AppModuleBasic{},
capability.AppModuleBasic{},
staking.AppModuleBasic{},
mint.AppModuleBasic{},
distr.AppModuleBasic{},
gov.NewAppModuleBasic(
[]govclient.ProposalHandler{
paramsclient.ProposalHandler,
},
),
params.AppModuleBasic{},
slashing.AppModuleBasic{},
upgrade.AppModuleBasic{},
consensus.AppModuleBasic{},
transfer.AppModuleBasic{},
ibccore.AppModuleBasic{},
ibctm.AppModuleBasic{},
ibcwasm.AppModuleBasic{},
ccvprovider.AppModuleBasic{},
ibcsolomachine.AppModuleBasic{},

// custom
wasm.AppModuleBasic{},
authz.AppModuleBasic{},
tokenfactory.AppModuleBasic{},
xion.AppModuleBasic{},
jwk.AppModuleBasic{},
aa.AppModuleBasic{},
)
// TODO: add encoding types here for the modules you want to use
ibclocalhost.RegisterInterfaces(cfg.InterfaceRegistry)
return &cfg
}(),

ModifyGenesis: ModifyInterChainGenesis(ModifyInterChainGenesisFn{ModifyGenesisShortProposals}, [][]string{{votingPeriod, maxDepositPeriod}}),
},
},
{
Expand Down Expand Up @@ -91,7 +164,7 @@ func TestXionUpgradeIBC(t *testing.T) {
chain, counterpartyChain := chains[0].(*cosmos.CosmosChain), chains[1].(*cosmos.CosmosChain)

const (
path = "ibc-upgrade-test-path"
testPath = "ibc-upgrade-test-testPath"
relayerName = "relayer"
)

Expand All @@ -112,7 +185,7 @@ func TestXionUpgradeIBC(t *testing.T) {
Chain1: chain,
Chain2: counterpartyChain,
Relayer: r,
Path: path,
Path: testPath,
})

ctx := context.Background()
Expand All @@ -134,8 +207,68 @@ func TestXionUpgradeIBC(t *testing.T) {
users := interchaintest.GetAndFundTestUsers(t, ctx, t.Name(), userFunds, chain)
chainUser := users[0]

// deploy the account contract, and pin it
fp, err := os.Getwd()
require.NoError(t, err)
codeIDStr, err := chain.StoreContract(ctx, chainUser.FormattedAddress(),
path.Join(fp, "integration_tests", "testdata", "contracts", "account_updatable-aarch64.wasm"))
require.NoError(t, err)

authority, err := chain.UpgradeQueryAuthority(ctx)
require.NoError(t, err)
codeID, err := strconv.Atoi(codeIDStr)
require.NoError(t, err)

pinCodeMsg := wasmtypes.MsgPinCodes{
Authority: authority,
CodeIDs: []uint64{uint64(codeID)},
}
msg, err := chain.Config().EncodingConfig.Codec.MarshalInterfaceJSON(&pinCodeMsg)
require.NoError(t, err)

pinCodeTx, err := chain.SubmitProposal(ctx, chainUser.KeyName(), cosmos.TxProposalv1{
Messages: []json.RawMessage{msg},
Metadata: "",
Deposit: "100uxion",
Title: "Pin AA Contract Code",
Summary: "To verify that the wasm cache doesn't move or change during upgrade",
})
require.NoError(t, err)

proposalID, err := strconv.Atoi(pinCodeTx.ProposalID)
require.NoError(t, err)

require.Eventuallyf(t, func() bool {
proposalInfo, err := chain.GovQueryProposal(ctx, uint64(proposalID))
if err != nil {
require.NoError(t, err)
} else {
if proposalInfo.Status == govv1beta1.StatusVotingPeriod {
return true
}
t.Logf("Waiting for proposal to enter voting status VOTING, current status: %s", proposalInfo.Status)
}
return false
}, time.Second*11, time.Second, "failed to reach status VOTING after 11s")

err = chain.VoteOnProposalAllValidators(ctx, uint64(proposalID), cosmos.ProposalVoteYes)
require.NoError(t, err)

require.Eventuallyf(t, func() bool {
proposalInfo, err := chain.GovQueryProposal(ctx, uint64(proposalID))
if err != nil {
require.NoError(t, err)
} else {
if proposalInfo.Status == govv1beta1.StatusPassed {
return true
}
t.Logf("Waiting for proposal to enter voting status PASSED, current status: %s", proposalInfo.Status)
}
return false
}, time.Second*11, time.Second, "failed to reach status PASSED after 11s")

// test IBC conformance before chain upgrade
conformance.TestChainPair(t, ctx, client, network, chain, counterpartyChain, rf, rep, r, path)
conformance.TestChainPair(t, ctx, client, network, chain, counterpartyChain, rf, rep, r, testPath)

height, err := chain.Height(ctx)
require.NoError(t, err, "error fetching height before submit upgrade proposal")
Expand Down Expand Up @@ -197,5 +330,5 @@ func TestXionUpgradeIBC(t *testing.T) {
require.NoError(t, err, "chain did not produce blocks after upgrade")

// test IBC conformance after chain upgrade on same path
conformance.TestChainPair(t, ctx, client, network, chain, counterpartyChain, rf, rep, r, path)
conformance.TestChainPair(t, ctx, client, network, chain, counterpartyChain, rf, rep, r, testPath)
}
1 change: 1 addition & 0 deletions x/mint/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"

// banktestutil "github.com/cosmos/cosmos-sdk/x/bank/testutil"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
Expand Down
Loading