Skip to content

Commit

Permalink
Merge pull request #477 from notional-labs/feat/sdk50
Browse files Browse the repository at this point in the history
add migration 08-wasm
  • Loading branch information
hoank101 authored Apr 2, 2024
2 parents a326328 + 4b48df5 commit d631961
Show file tree
Hide file tree
Showing 23 changed files with 540 additions and 146 deletions.
14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,16 @@ ictest-push-wasm:

.PHONY: ictest-start-cosmos ictest-start-polkadot ictest-ibc ictest-push-wasm ictest-all

include contrib/make/release.mk
include contrib/make/release.mk


test-upgrade: clean-testing-data
@echo "Starting upgrade test"
./scripts/tweak-test-upgrade.sh


clean-testing-data:
@echo "Killing binary and removing previous data"
-@pkill centaurid 2>/dev/null
-@rm -rf ./mytestnet

39 changes: 32 additions & 7 deletions app/app.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package app

import (
"cosmossdk.io/client/v2/autocli"
"cosmossdk.io/core/appmodule"
"fmt"
runtimeservices "github.com/cosmos/cosmos-sdk/runtime/services"
authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec"
"io"
"os"
"path/filepath"
Expand Down Expand Up @@ -43,7 +47,7 @@ import (

"github.com/notional-labs/composable/v6/app/keepers"
"github.com/notional-labs/composable/v6/app/upgrades/v6_5_0"
"github.com/notional-labs/composable/v6/app/upgrades/v7_0_0"
"github.com/notional-labs/composable/v6/app/upgrades/v7_0_1"

// bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
"cosmossdk.io/x/evidence"
Expand Down Expand Up @@ -148,7 +152,7 @@ var (
// https://github.com/CosmWasm/wasmd/blob/02a54d33ff2c064f3539ae12d75d027d9c665f05/x/wasm/internal/types/proposal.go#L28-L34
EnableSpecificProposals = ""

Upgrades = []upgrades.Upgrade{v6_5_0.Upgrade, v7_0_0.Upgrade}
Upgrades = []upgrades.Upgrade{v6_5_0.Upgrade, v7_0_1.Upgrade}
Forks = []upgrades.Fork{}
)

Expand Down Expand Up @@ -195,7 +199,6 @@ var (
vesting.AppModuleBasic{},
tendermint.AppModuleBasic{},
mint.AppModuleBasic{},
wasm08.AppModuleBasic{},
wasm.AppModuleBasic{},
router.AppModuleBasic{},
ica.AppModuleBasic{},
Expand All @@ -207,6 +210,7 @@ var (
stakingmiddleware.AppModuleBasic{},
ibctransfermiddleware.AppModuleBasic{},
circuit.AppModuleBasic{},
wasm08.AppModuleBasic{},
// this line is used by starport scaffolding # stargate/app/moduleBasic
)

Expand Down Expand Up @@ -382,8 +386,8 @@ func NewComposableApp(
icqModule,
ibcHooksModule,
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
wasm08.NewAppModule(app.Wasm08Keeper),
wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)),
wasm08.NewAppModule(app.Wasm08Keeper),
routerModule,
transfermiddlewareModule,
txBoundaryModule,
Expand Down Expand Up @@ -433,11 +437,11 @@ func NewComposableApp(
paramstypes.ModuleName,
consensusparamtypes.ModuleName,
circuittypes.ModuleName,
wasm08types.ModuleName,
icatypes.ModuleName,
wasmtypes.ModuleName,
stakingmiddlewaretypes.ModuleName,
ibctransfermiddlewaretypes.ModuleName,
wasm08types.ModuleName,
// this line is used by starport scaffolding # stargate/app/beginBlockers
)

Expand Down Expand Up @@ -469,11 +473,11 @@ func NewComposableApp(
icqtypes.ModuleName,
consensusparamtypes.ModuleName,
circuittypes.ModuleName,
wasm08types.ModuleName,
icatypes.ModuleName,
wasmtypes.ModuleName,
stakingmiddlewaretypes.ModuleName,
ibctransfermiddlewaretypes.ModuleName,
wasm08types.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand Down Expand Up @@ -509,11 +513,11 @@ func NewComposableApp(
group.ModuleName,
consensusparamtypes.ModuleName,
circuittypes.ModuleName,
wasm08types.ModuleName,
icatypes.ModuleName,
wasmtypes.ModuleName,
stakingmiddlewaretypes.ModuleName,
ibctransfermiddlewaretypes.ModuleName,
wasm08types.ModuleName,
// this line is used by starport scaffolding # stargate/app/initGenesis
)

Expand Down Expand Up @@ -780,3 +784,24 @@ func (app *ComposableApp) setupUpgradeHandlers() {
)
}
}

// AutoCliOpts returns the autocli options for the app.
func (app *ComposableApp) AutoCliOpts() autocli.AppOptions {
modules := make(map[string]appmodule.AppModule, 0)
for _, m := range app.mm.Modules {
if moduleWithName, ok := m.(module.HasName); ok {
moduleName := moduleWithName.Name()
if appModule, ok := moduleWithName.(appmodule.AppModule); ok {
modules[moduleName] = appModule
}
}
}

return autocli.AppOptions{
Modules: modules,
ModuleOptions: runtimeservices.ExtractAutoCLIOptions(app.mm.Modules),
AddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()),
ValidatorAddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()),
ConsensusAddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()),
}
}
3 changes: 1 addition & 2 deletions app/ibctesting/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ func (endpoint *Endpoint) CreateClient() (err error) {
return err
}
consensusState = &wasmtypes.ConsensusState{
Data: wasmConsensusState,
Timestamp: tmConsensusState.GetTimestamp(),
Data: wasmConsensusState,
}
default:
err = fmt.Errorf("client type %s is not supported", endpoint.ClientConfig.GetClientType())
Expand Down
2 changes: 1 addition & 1 deletion app/ibctesting/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func NewPath(chainA, chainB *TestChain) *Path {
func NewDefaultEndpoint(chain *TestChain) *Endpoint {
return &Endpoint{
Chain: chain,
ClientConfig: ibctesting.NewTendermintConfig(chain.UseWasmClient),
ClientConfig: ibctesting.NewTendermintConfig(),
ConnectionConfig: ibctesting.NewConnectionConfig(),
ChannelConfig: ibctesting.NewChannelConfig(),
}
Expand Down
12 changes: 8 additions & 4 deletions app/ibctesting/simapp/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"log"

tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
Expand All @@ -18,7 +17,7 @@ func (app *SimApp) ExportAppStateAndValidators(
forZeroHeight bool, jailAllowedAddrs []string,
) (servertypes.ExportedApp, error) {
// as if they could withdraw from the start of the next block
ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()})
ctx := app.NewContext(true)

// We export at last height + 1, because that's the height at which
// Tendermint will start InitChain.
Expand Down Expand Up @@ -75,12 +74,17 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []

// withdraw all validator commission
app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
_, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator())

_, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator().String())
return false
})

// withdraw all delegator rewards
dels := app.StakingKeeper.GetAllDelegations(ctx)
dels, err := app.StakingKeeper.GetAllDelegations(ctx)
if err != nil {
panic(err)
}

for _, delegation := range dels {
valAddr, err := sdk.ValAddressFromBech32(delegation.ValidatorAddress)
if err != nil {
Expand Down
23 changes: 7 additions & 16 deletions app/ibctesting/wasm.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ibctesting

import (
"fmt"
"time"

"github.com/stretchr/testify/require"
Expand All @@ -13,13 +12,13 @@ import (

// ConstructUpdateWasmClientHeader will construct a valid 08-wasm Header with a zero height
// to update the light client on the source chain.
func (chain *TestChain) ConstructUpdateWasmClientHeader(counterparty *TestChain, clientID string) (*wasmtypes.Header, error) {
func (chain *TestChain) ConstructUpdateWasmClientHeader(counterparty *TestChain, clientID string) (*wasmtypes.ClientState, error) {
return chain.ConstructUpdateWasmClientHeaderWithTrustedHeight(counterparty, clientID, clienttypes.ZeroHeight())
}

// ConstructUpdateWasmClientHeaderWithTrustedHeight will construct a valid 08-wasm Header
// to update the light client on the source chain.
func (chain *TestChain) ConstructUpdateWasmClientHeaderWithTrustedHeight(counterparty *TestChain, clientID string, trustedHeight clienttypes.Height) (*wasmtypes.Header, error) {
func (chain *TestChain) ConstructUpdateWasmClientHeaderWithTrustedHeight(counterparty *TestChain, clientID string, trustedHeight clienttypes.Height) (*wasmtypes.ClientState, error) {
tmHeader, err := chain.ConstructUpdateTMClientHeaderWithTrustedHeight(counterparty, clientID, trustedHeight)
if err != nil {
return nil, err
Expand All @@ -30,26 +29,18 @@ func (chain *TestChain) ConstructUpdateWasmClientHeaderWithTrustedHeight(counter
return nil, err
}

height, ok := tmHeader.GetHeight().(clienttypes.Height)
if !ok {
return nil, fmt.Errorf("error casting exported height to clienttypes height")
}
wasmHeader := wasmtypes.Header{
Data: tmWasmHeaderData,
Height: height,
wasmHeader := wasmtypes.ClientState{
Data: tmWasmHeaderData,
}

return &wasmHeader, nil
}

func (chain *TestChain) CreateWasmClientHeader(chainID string, blockHeight int64, trustedHeight clienttypes.Height, timestamp time.Time, tmValSet, _, tmTrustedVals *tmtypes.ValidatorSet, signers []tmtypes.PrivValidator) *wasmtypes.Header {
func (chain *TestChain) CreateWasmClientHeader(chainID string, blockHeight int64, trustedHeight clienttypes.Height, timestamp time.Time, tmValSet, _, tmTrustedVals *tmtypes.ValidatorSet, signers []tmtypes.PrivValidator) *wasmtypes.ClientState {
tmHeader := chain.CreateTMClientHeader(chainID, blockHeight, trustedHeight, timestamp, tmValSet, tmTrustedVals, signers)
tmWasmHeaderData, err := chain.Codec.MarshalInterface(tmHeader)
require.NoError(chain.t, err)
height, ok := tmHeader.GetHeight().(clienttypes.Height)
require.True(chain.t, ok)
return &wasmtypes.Header{
Data: tmWasmHeaderData,
Height: height,
return &wasmtypes.ClientState{
Data: tmWasmHeaderData,
}
}
18 changes: 14 additions & 4 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keepers
import (
"fmt"
"github.com/cosmos/cosmos-sdk/x/params"
"math"
"path/filepath"
"strings"

Expand Down Expand Up @@ -447,14 +448,23 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
wasmOpts...,
)

wasmDataDir := filepath.Join(homePath, "wasm_client_data")
wasmSupportedFeatures := strings.Join([]string{"storage", "iterator"}, ",")
wasmMemoryLimitMb := uint32(math.Pow(2, 12))
wasmPrintDebug := true
wasmCacheSizeMb := uint32(math.Pow(2, 8))

vm, err := wasmvm.NewVM(wasmDataDir, wasmSupportedFeatures, wasmMemoryLimitMb, wasmPrintDebug, wasmCacheSizeMb)

// use same VM for wasm
appKeepers.Wasm08Keeper = wasm08Keeper.NewKeeper(
appKeepers.Wasm08Keeper = wasm08Keeper.NewKeeperWithVM(
appCodec,
runtime.NewKVStoreService(appKeepers.keys[wasm08types.StoreKey]),
govModAddress,
wasmDir,
&appKeepers.IBCKeeper.ClientKeeper,
bApp.GRPCQueryRouter())
"centauri1hj5fveer5cjtn4wd6wstzugjfdxzl0xpzxlwgs",
vm,
bApp.GRPCQueryRouter(),
)

appKeepers.Ics20WasmHooks.ContractKeeper = &appKeepers.WasmKeeper

Expand Down
24 changes: 0 additions & 24 deletions app/upgrades/v7_0_0/upgrade.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v7_0_0
package v7_0_1

import (
store "cosmossdk.io/store/types"
Expand All @@ -10,7 +10,7 @@ import (

const (
// UpgradeName defines the on-chain upgrade name for the composable upgrade.
UpgradeName = "v7_0_0"
UpgradeName = "v7_0_1"
)

var Upgrade = upgrades.Upgrade{
Expand Down
42 changes: 42 additions & 0 deletions app/upgrades/v7_0_1/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package v7_0_1

import (
"context"
upgradetypes "cosmossdk.io/x/upgrade/types"
"encoding/hex"
"fmt"
"github.com/cosmos/cosmos-sdk/runtime"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/notional-labs/composable/v6/app/keepers"
"github.com/notional-labs/composable/v6/app/upgrades"
)

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
_ upgrades.BaseAppParamManager,
codec codec.Codec,
keepers *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(goCtx context.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
fmt.Println("start v7.0.1 upgrade")
ctx := sdk.UnwrapSDKContext(goCtx)
store := runtime.NewKVStoreService(keepers.GetKVStoreKey()[types.StoreKey]).OpenKVStore(ctx)
checksumStr, err := hex.DecodeString("58c7623a3ab78f4cb2e4c5d02876ac36c3b38bb472118173a7ec7faa688a66d2")

checksum := types.Checksums{Checksums: [][]byte{checksumStr}}
bz, err := codec.Marshal(&checksum)
if err != nil {
panic(err)
}
err = store.Set([]byte(types.KeyChecksums), bz)
if err != nil {
panic(err)
}
return mm.RunMigrations(ctx, configurator, vm)
}
}
Loading

0 comments on commit d631961

Please sign in to comment.