Skip to content

Commit

Permalink
Problem: sdk 47 is not integrated
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Dec 28, 2023
1 parent 1b01cd8 commit a7c0242
Show file tree
Hide file tree
Showing 69 changed files with 751 additions and 951 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## UNRELEASED

- [#]() Integrate sdk 0.47

*Dec 6, 2023*

## v4.2.8
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ GOLANG_CROSS_VERSION = v1.20.1


VERSION := $(shell echo $(shell git describe --tags 2>/dev/null ) | sed 's/^v//')
TMVERSION := $(shell go list -m github.com/tendermint/tendermint | sed 's:.* ::')
TMVERSION := $(shell go list -m github.com/cometbft/cometbft | sed 's:.* ::')
COMMIT := $(shell git log -1 --format='%H')
NETWORK ?= mainnet
COVERAGE ?= coverage.txt
Expand Down
21 changes: 11 additions & 10 deletions MakefileDoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
### Documentation ###
###############################################################################

include third_party/cosmos-sdk/contrib/devtools/Makefile
# include third_party/cosmos-sdk/contrib/devtools/Makefile

containerProtoVer=v0.7
containerProtoImage=tendermintdev/sdk-proto-gen:$(containerProtoVer)
containerProtoGen=cosmos-sdk-proto-gen-$(containerProtoVer)
containerProtoGenSwagger=cosmos-sdk-proto-gen-swagger-$(containerProtoVer)
containerProtoFmt=cosmos-sdk-proto-fmt-$(containerProtoVer)
DOCKER := $(shell which docker)
protoVer=0.11.6
protoImageName=ghcr.io/cosmos/proto-builder:$(protoVer)
protoImage=$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(protoImageName)
BINDIR ?= ~/go/bin

all: update-swagger-docs
Expand All @@ -27,13 +26,15 @@ proto-swagger-gen:

proto-gen:
@echo "Generating Protobuf files"
@if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerProtoGen}$$"; then docker start -a $(containerProtoGen); else docker run --name $(containerProtoGen) -v $(CURDIR):/workspace --workdir /workspace $(containerProtoImage) \
sh ./scripts/protocgen.sh; fi
$(protoImage) sh ./scripts/protocgen.sh

proto-lint:
@echo "Linting Protobuf files"
@$(protoImage) buf lint --error-format=json

proto-format:
@echo "Formatting Protobuf files"
@if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerProtoFmt}$$"; then docker start -a $(containerProtoFmt); else docker run --name $(containerProtoFmt) -v $(CURDIR):/workspace --workdir /workspace tendermintdev/docker-build-proto \
find ./ -not -path "./third_party/*" -name "*.proto" -exec clang-format -i {} \; ; fi
@$(protoImage) find ./ -not -path "./third_party/*" -name "*.proto" -exec clang-format -i {} \;

proto-all: proto-format proto-gen proto-swagger-gen

Expand Down
4 changes: 2 additions & 2 deletions app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
ibcante "github.com/cosmos/ibc-go/v5/modules/core/ante"
"github.com/cosmos/ibc-go/v5/modules/core/keeper"
ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante"
"github.com/cosmos/ibc-go/v7/modules/core/keeper"
nfttypes "github.com/crypto-org-chain/chain-main/v4/x/nft-transfer/types"
)

Expand Down
187 changes: 98 additions & 89 deletions app/app.go

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"log"

tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"

sdk "github.com/cosmos/cosmos-sdk/types"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
Expand All @@ -18,7 +18,7 @@ import (
// ExportAppStateAndValidators exports the state of the application for a genesis
// file.
func (app *ChainApp) ExportAppStateAndValidators(
forZeroHeight bool, jailAllowedAddrs []string,
forZeroHeight bool, jailAllowedAddrs []string, modulesToExport []string,
) (servertypes.ExportedApp, error) {

// as if they could withdraw from the start of the next block
Expand All @@ -33,13 +33,13 @@ func (app *ChainApp) ExportAppStateAndValidators(
app.prepForZeroHeightGenesis(ctx, jailAllowedAddrs)
}

genState := app.mm.ExportGenesis(ctx, app.appCodec)
genState := app.mm.ExportGenesisForModules(ctx, app.appCodec, modulesToExport)
appState, err := json.MarshalIndent(genState, "", " ")
if err != nil {
return servertypes.ExportedApp{}, err
}

validators, err := staking.WriteValidators(ctx, app.StakingKeeper)
validators, err := staking.WriteValidators(ctx, &app.StakingKeeper)
if err != nil {
return servertypes.ExportedApp{}, err
}
Expand Down
23 changes: 11 additions & 12 deletions app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ import (
"strings"
"testing"

dbm "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/libs/log"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
dbm "github.com/tendermint/tm-db"

"cosmossdk.io/simapp"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/simapp/helpers"
"github.com/cosmos/cosmos-sdk/store"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -67,7 +66,7 @@ func TestFullAppSimulation(t *testing.T) {
}
require.NoError(t, err, "simulation setup failed")

config.ChainID = helpers.SimAppChainID
config.ChainID = simapp.SimAppChainID

Check failure on line 69 in app/sim_test.go

View workflow job for this annotation

GitHub Actions / codecov

undefined: simapp.SimAppChainID

Check failure on line 69 in app/sim_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: simapp.SimAppChainID

Check failure on line 69 in app/sim_test.go

View workflow job for this annotation

GitHub Actions / Build

undefined: simapp.SimAppChainID

defer func() {
db.Close()
Expand Down Expand Up @@ -107,7 +106,7 @@ func TestAppImportExport(t *testing.T) {
}
require.NoError(t, err, "simulation setup failed")

config.ChainID = helpers.SimAppChainID
config.ChainID = simapp.SimAppChainID

Check failure on line 109 in app/sim_test.go

View workflow job for this annotation

GitHub Actions / codecov

undefined: simapp.SimAppChainID

Check failure on line 109 in app/sim_test.go

View workflow job for this annotation

GitHub Actions / Build

undefined: simapp.SimAppChainID

defer func() {
db.Close()
Expand Down Expand Up @@ -175,7 +174,7 @@ func TestAppImportExport(t *testing.T) {
}
}()

header := tmproto.Header{Height: app.LastBlockHeight(), ChainID: helpers.SimAppChainID}
header := tmproto.Header{Height: app.LastBlockHeight(), ChainID: simapp.SimAppChainID}
ctxA := app.NewContext(true, header)
ctxB := newApp.NewContext(true, header)
newApp.mm.InitGenesis(ctxB, app.AppCodec(), genesisState)
Expand Down Expand Up @@ -223,7 +222,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
}
require.NoError(t, err, "simulation setup failed")

config.ChainID = helpers.SimAppChainID
config.ChainID = simapp.SimAppChainID

defer func() {
db.Close()
Expand Down Expand Up @@ -282,7 +281,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
require.Equal(t, "chain-maind", newApp.Name())

newApp.InitChain(abci.RequestInitChain{
ChainId: helpers.SimAppChainID,
ChainId: simapp.SimAppChainID,
AppStateBytes: exported.AppState,
})

Expand Down Expand Up @@ -312,7 +311,7 @@ func TestAppStateDeterminism(t *testing.T) {
config.ExportParamsPath = ""
config.OnOperation = false
config.AllInvariants = false
config.ChainID = helpers.SimAppChainID
config.ChainID = simapp.SimAppChainID

numSeeds := 3
numTimesToRunPerSeed := 5
Expand Down
4 changes: 2 additions & 2 deletions app/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package app

import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/simapp"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
)
Expand All @@ -14,5 +14,5 @@ import (
// If a file is not given for the genesis or the sim params, it creates a randomized one.
// nolint:revive
func AppStateFn(cdc codec.JSONCodec, simManager *module.SimulationManager) simtypes.AppStateFn {
return simapp.AppStateFnWithExtendedCb(cdc, simManager, NewDefaultGenesisState(cdc), nil)
return simtestutil.AppStateFnWithExtendedCb(cdc, simManager, NewDefaultGenesisState(cdc), nil)
}
28 changes: 14 additions & 14 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
"time"

sdkmath "cosmossdk.io/math"
dbm "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/libs/log"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
tmtypes "github.com/cometbft/cometbft/types"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmtypes "github.com/tendermint/tendermint/types"
dbm "github.com/tendermint/tm-db"

newsdkerrors "cosmossdk.io/errors"
bam "github.com/cosmos/cosmos-sdk/baseapp"
Expand All @@ -26,8 +26,8 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/simapp/helpers"
"github.com/cosmos/cosmos-sdk/testutil/mock"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/errors"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
Expand All @@ -38,8 +38,8 @@ import (

// DefaultConsensusParams defines the default Tendermint consensus params used in
// ChainApp testing.
var DefaultConsensusParams = &abci.ConsensusParams{
Block: &abci.BlockParams{
var DefaultConsensusParams = &tmproto.ConsensusParams{
Block: &tmproto.BlockParams{
MaxBytes: 200000,
MaxGas: 2000000,
},
Expand Down Expand Up @@ -141,7 +141,7 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs
})

// update total supply
bankGenesis := banktypes.NewGenesisState(banktypes.DefaultGenesisState().Params, balances, totalSupply, []banktypes.Metadata{})
bankGenesis := banktypes.NewGenesisState(banktypes.DefaultGenesisState().Params, balances, totalSupply, []banktypes.Metadata{}, []banktypes.SendEnabled{})
genesisState[banktypes.ModuleName] = app.AppCodec().MustMarshalJSON(bankGenesis)

stateBytes, err := json.MarshalIndent(genesisState, "", " ")
Expand Down Expand Up @@ -180,7 +180,7 @@ func SetupWithGenesisAccounts(genAccs []authtypes.GenesisAccount, balances ...ba
totalSupply = totalSupply.Add(b.Coins...)
}

bankGenesis := banktypes.NewGenesisState(banktypes.DefaultGenesisState().Params, balances, totalSupply, []banktypes.Metadata{})
bankGenesis := banktypes.NewGenesisState(banktypes.DefaultGenesisState().Params, balances, totalSupply, []banktypes.Metadata{}, []banktypes.SendEnabled{})
genesisState[banktypes.ModuleName] = app.AppCodec().MustMarshalJSON(bankGenesis)

stateBytes, err := json.MarshalIndent(genesisState, "", " ")
Expand Down Expand Up @@ -333,13 +333,13 @@ func SignCheckDeliver(
chainID string, accNums, accSeqs []uint64, expSimPass, expPass bool, priv ...cryptotypes.PrivKey,
) (sdk.GasInfo, *sdk.Result, error) {

tx, err := helpers.GenSignedMockTx(
tx, err := simtestutil.GenSignedMockTx(
// nolint: gosec
rand.New(rand.NewSource(time.Now().UnixNano())),
txCfg,
msgs,
sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 0)},
helpers.DefaultGenTxGas,
simtestutil.DefaultGenTxGas,
chainID,
accNums,
accSeqs,
Expand Down Expand Up @@ -385,13 +385,13 @@ func GenSequenceOfTxs(txGen client.TxConfig, msgs []sdk.Msg, accNums []uint64, i
txs := make([]sdk.Tx, numToGenerate)
var err error
for i := 0; i < numToGenerate; i++ {
txs[i], err = helpers.GenSignedMockTx(
txs[i], err = simtestutil.GenSignedMockTx(
// nolint: gosec
rand.New(rand.NewSource(time.Now().UnixNano())),
txGen,
msgs,
sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 0)},
helpers.DefaultGenTxGas,
simtestutil.DefaultGenTxGas,
"",
accNums,
initSeqNums,
Expand Down
4 changes: 2 additions & 2 deletions app/types.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package app

import (
abci "github.com/tendermint/tendermint/abci/types"
abci "github.com/cometbft/cometbft/abci/types"

"github.com/cosmos/cosmos-sdk/codec"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
Expand Down Expand Up @@ -34,7 +34,7 @@ type App interface {

// Exports the state of the application for a genesis file.
ExportAppStateAndValidators(
forZeroHeight bool, jailAllowedAddrs []string,
forZeroHeight bool, jailAllowedAddrs []string, modulesToExport []string,
) (servertypes.ExportedApp, error)

// All the registered module account addreses.
Expand Down
10 changes: 5 additions & 5 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
"github.com/cosmos/cosmos-sdk/x/group"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
ica "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts"
icacontrollertypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/types"
icahosttypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/types"
ibcfeetypes "github.com/cosmos/ibc-go/v5/modules/apps/29-fee/types"
ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts"
icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"
icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
ibcfeetypes "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types"
icaauthmoduletypes "github.com/crypto-org-chain/chain-main/v4/x/icaauth/types"
nfttransfertypes "github.com/crypto-org-chain/chain-main/v4/x/nft-transfer/types"
)
Expand Down
24 changes: 15 additions & 9 deletions cmd/chain-maind/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import (
conf "github.com/cosmos/cosmos-sdk/client/config"
serverconfig "github.com/cosmos/cosmos-sdk/server/config"

dbm "github.com/cometbft/cometbft-db"
tmcfg "github.com/cometbft/cometbft/config"
tmcli "github.com/cometbft/cometbft/libs/cli"
"github.com/cometbft/cometbft/libs/log"
"github.com/imdario/mergo"
"github.com/spf13/cast"
"github.com/spf13/cobra"
tmcfg "github.com/tendermint/tendermint/config"
tmcli "github.com/tendermint/tendermint/libs/cli"
"github.com/tendermint/tendermint/libs/log"
dbm "github.com/tendermint/tm-db"

rosettaCmd "cosmossdk.io/tools/rosetta/cmd"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/debug"
"github.com/cosmos/cosmos-sdk/client/flags"
Expand All @@ -34,6 +35,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"

"github.com/crypto-org-chain/chain-main/v4/app"
Expand Down Expand Up @@ -216,7 +218,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {

rootCmd.AddCommand(
initCmd,
genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome),
genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome, genutiltypes.DefaultMessageValidator),
genutilcli.MigrateGenesisCmd(),
genutilcli.GenTxCmd(app.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome),
genutilcli.ValidateGenesisCmd(app.ModuleBasics),
Expand All @@ -240,7 +242,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
)

// add rosetta
rootCmd.AddCommand(server.RosettaCommand(encodingConfig.InterfaceRegistry, encodingConfig.Marshaler))
rootCmd.AddCommand(rosettaCmd.RosettaCommand(encodingConfig.InterfaceRegistry, encodingConfig.Marshaler))

// versiondb changeset commands
changeSetCmd := ChangeSetCmd()
Expand Down Expand Up @@ -325,8 +327,12 @@ func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts serverty
// exportAppStateAndTMValidators creates a new chain app (optionally at a given height)
// and exports state.
func exportAppStateAndTMValidators(
logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailAllowedAddrs []string,
appOpts servertypes.AppOptions) (servertypes.ExportedApp, error) {
logger log.Logger, db dbm.DB,
traceStore io.Writer, height int64,
forZeroHeight bool, jailAllowedAddrs []string,
appOpts servertypes.AppOptions,
modulesToExport []string,
) (servertypes.ExportedApp, error) {

encCfg := app.MakeEncodingConfig() // Ideally, we would reuse the one created by NewRootCmd.
encCfg.Marshaler = codec.NewProtoCodec(encCfg.InterfaceRegistry)
Expand All @@ -342,5 +348,5 @@ func exportAppStateAndTMValidators(
a = app.New(logger, db, traceStore, true, map[int64]bool{}, "", uint(1), encCfg, appOpts)
}

return a.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs)
return a.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs, modulesToExport)
}
2 changes: 1 addition & 1 deletion cmd/chain-maind/opendb/opendb.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package opendb
import (
"path/filepath"

dbm "github.com/tendermint/tm-db"
dbm "github.com/cometbft/cometbft-db"
)

func OpenDB(home string, backendType dbm.BackendType) (dbm.DB, error) {
Expand Down
Loading

0 comments on commit a7c0242

Please sign in to comment.