From f287ca784bc5d4e42b11c4c7bac03ebed547d668 Mon Sep 17 00:00:00 2001 From: dongsam Date: Thu, 20 Jul 2023 19:53:01 +0900 Subject: [PATCH 1/4] fix: seperate antehandler for simulation --- Makefile | 12 +-- app/ante/ante.go | 6 +- app/ante/handler_options.go | 34 +++++++- app/app.go | 5 +- app/app_test.go | 7 +- app/export.go | 2 +- app/sim_test.go | 168 +++++++++++++++++++++++++++++------- app/state.go | 17 ++-- app/test_helpers.go | 4 +- cmd/cantod/root.go | 5 +- testutil/network/network.go | 4 +- 11 files changed, 209 insertions(+), 55 deletions(-) diff --git a/Makefile b/Makefile index 24b209ec..3f9da0a1 100755 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ COMMIT := $(shell git log -1 --format='%H') LEDGER_ENABLED ?= true BINDIR ?= $(GOPATH)/bin canto_BINARY = cantod -canto_DIR = canto +canto_DIR = cantod BUILDDIR ?= $(CURDIR)/build SIMAPP = ./app HTTPS_GIT := https://github.com/canto/canto.git @@ -371,13 +371,13 @@ test-rpc-pending: test-sim-nondeterminism: @echo "Running non-determinism test..." @go test -mod=readonly $(SIMAPP) -run TestAppStateDeterminism -Enabled=true \ - -NumBlocks=100 -BlockSize=200 -Commit=true -Period=0 -v -timeout 24h + -NumBlocks=100 -BlockSize=200 -Commit=true -Period=1 -v -timeout 1h test-sim-custom-genesis-fast: @echo "Running custom genesis simulation..." @echo "By default, ${HOME}/.$(canto_DIR)/config/genesis.json will be used." @go test -mod=readonly $(SIMAPP) -run TestFullAppSimulation -Genesis=${HOME}/.$(canto_DIR)/config/genesis.json \ - -Enabled=true -NumBlocks=100 -BlockSize=200 -Commit=true -Seed=99 -Period=5 -v -timeout 24h + -Enabled=true -NumBlocks=100 -BlockSize=200 -Commit=true -Seed=5 -Period=1 -v -timeout 1h test-sim-import-export: runsim @echo "Running application import/export simulation. This may take several minutes..." @@ -390,15 +390,15 @@ test-sim-after-import: runsim test-sim-custom-genesis-multi-seed: runsim @echo "Running multi-seed custom genesis simulation..." @echo "By default, ${HOME}/.$(canto_DIR)/config/genesis.json will be used." - @$(BINDIR)/runsim -Genesis=${HOME}/.$(canto_DIR)/config/genesis.json -SimAppPkg=$(SIMAPP) -ExitOnFail 400 5 TestFullAppSimulation + @$(BINDIR)/runsim -Genesis=${HOME}/.$(canto_DIR)/config/genesis.json -SimAppPkg=$(SIMAPP) -ExitOnFail 50 5 TestFullAppSimulation test-sim-multi-seed-long: runsim @echo "Running long multi-seed application simulation. This may take awhile!" - @$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(SIMAPP) -ExitOnFail 500 50 TestFullAppSimulation + @$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(SIMAPP) -ExitOnFail 500 10 TestFullAppSimulation test-sim-multi-seed-short: runsim @echo "Running short multi-seed application simulation. This may take awhile!" - @$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(SIMAPP) -ExitOnFail 50 10 TestFullAppSimulation + @$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(SIMAPP) -ExitOnFail 50 5 TestFullAppSimulation test-sim-benchmark-invariants: @echo "Running simulation invariant benchmarks..." diff --git a/app/ante/ante.go b/app/ante/ante.go index afe7e5ed..7cc12289 100644 --- a/app/ante/ante.go +++ b/app/ante/ante.go @@ -45,7 +45,11 @@ func NewAnteHandler(options HandlerOptions) sdk.AnteHandler { // handle as totally normal Cosmos SDK tx switch tx.(type) { case sdk.Tx: - anteHandler = newCosmosAnteHandler(options) + if options.Simulation { + anteHandler = newCosmosSimulationAnteHandler(options) + } else { + anteHandler = newCosmosAnteHandler(options) + } default: return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid transaction type: %T", tx) } diff --git a/app/ante/handler_options.go b/app/ante/handler_options.go index 3f544e08..bcb347e1 100644 --- a/app/ante/handler_options.go +++ b/app/ante/handler_options.go @@ -17,8 +17,9 @@ import ( cosmosante "github.com/Canto-Network/Canto/v6/app/ante/cosmos" - vestingtypes "github.com/Canto-Network/Canto/v6/x/vesting/types" sdkvesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" + + vestingtypes "github.com/Canto-Network/Canto/v6/x/vesting/types" ) // HandlerOptions defines the list of module keepers required to run the canto @@ -36,6 +37,7 @@ type HandlerOptions struct { SigGasConsumer func(meter sdk.GasMeter, sig signing.SignatureV2, params authtypes.Params) error Cdc codec.BinaryCodec MaxTxGasWanted uint64 + Simulation bool } // Validate checks if the keepers are defined @@ -113,6 +115,36 @@ func newCosmosAnteHandler(options HandlerOptions) sdk.AnteHandler { ) } +// newCosmosSimulationAnteHandler creates the ante handler for simulation, skipped few decorators for simulation +func newCosmosSimulationAnteHandler(options HandlerOptions) sdk.AnteHandler { + return sdk.ChainAnteDecorators( + ethante.RejectMessagesDecorator{}, // reject MsgEthereumTxs + cosmosante.NewAuthzLimiterDecorator( + sdk.MsgTypeURL(&evmtypes.MsgEthereumTx{}), + sdk.MsgTypeURL(&sdkvesting.MsgCreateVestingAccount{}), + ), + ante.NewSetUpContextDecorator(), + ante.NewRejectExtensionOptionsDecorator(), + ante.NewValidateBasicDecorator(), + ante.NewMempoolFeeDecorator(), + ethante.NewMinGasPriceDecorator(options.FeeMarketKeeper, options.EvmKeeper), + ante.NewTxTimeoutHeightDecorator(), + ante.NewValidateMemoDecorator(options.AccountKeeper), + ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper), + // NewParamChangeLimitDecorator(options.SlashingKeeper, options.Cdc), + ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper), + NewVestingDelegationDecorator(options.AccountKeeper, options.StakingKeeper, options.Cdc), + // NewValidatorCommissionDecorator(options.Cdc), + //ante.NewSetPubKeyDecorator(options.AccountKeeper), + ante.NewValidateSigCountDecorator(options.AccountKeeper), + //ante.NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer), + //ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler), + ante.NewIncrementSequenceDecorator(options.AccountKeeper), + ibcante.NewAnteDecorator(options.IBCKeeper), + ethante.NewGasWantedDecorator(options.EvmKeeper, options.FeeMarketKeeper), + ) +} + // newCosmosAnteHandlerEip712 creates the ante handler for transactions signed with EIP712 func newCosmosAnteHandlerEip712(options HandlerOptions) sdk.AnteHandler { return sdk.ChainAnteDecorators( diff --git a/app/app.go b/app/app.go index 6e11567c..c2577bba 100644 --- a/app/app.go +++ b/app/app.go @@ -339,6 +339,7 @@ func NewCanto( skipUpgradeHeights map[int64]bool, homePath string, invCheckPeriod uint, + simulation bool, encodingConfig simappparams.EncodingConfig, appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp), @@ -730,7 +731,6 @@ func NewCanto( erc20types.ModuleName, govshuttletypes.ModuleName, csrtypes.ModuleName, - // recoverytypes.ModuleName, feestypes.ModuleName, ) @@ -794,7 +794,7 @@ func NewCanto( bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper), capability.NewAppModule(appCodec, *app.CapabilityKeeper), gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper), - // staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), + staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), params.NewAppModule(app.ParamsKeeper), @@ -835,6 +835,7 @@ func NewCanto( SigGasConsumer: SigVerificationGasConsumer, Cdc: appCodec, MaxTxGasWanted: maxGasWanted, + Simulation: simulation, } if err := options.Validate(); err != nil { diff --git a/app/app_test.go b/app/app_test.go index c327839e..14da5c99 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -13,13 +13,14 @@ import ( "github.com/tendermint/tendermint/libs/log" dbm "github.com/tendermint/tm-db" - "github.com/Canto-Network/Canto/v6/types" "github.com/evmos/ethermint/encoding" + + "github.com/Canto-Network/Canto/v6/types" ) func TestCantoExport(t *testing.T) { db := dbm.NewMemDB() - app := NewCanto(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encoding.MakeConfig(ModuleBasics), simapp.EmptyAppOptions{}) + app := NewCanto(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, false, encoding.MakeConfig(ModuleBasics), simapp.EmptyAppOptions{}) genesisState := NewDefaultGenesisState() stateBytes, err := json.MarshalIndent(genesisState, "", " ") @@ -36,7 +37,7 @@ func TestCantoExport(t *testing.T) { app.Commit() // Making a new app object with the db, so that initchain hasn't been called - app2 := NewCanto(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encoding.MakeConfig(ModuleBasics), simapp.EmptyAppOptions{}) + app2 := NewCanto(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, false, encoding.MakeConfig(ModuleBasics), simapp.EmptyAppOptions{}) _, err = app2.ExportAppStateAndValidators(false, []string{}) require.NoError(t, err, "ExportAppStateAndValidators should not have an error") } diff --git a/app/export.go b/app/export.go index ba599134..8db7ec13 100644 --- a/app/export.go +++ b/app/export.go @@ -173,7 +173,7 @@ func (app *Canto) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []s counter := int16(0) for ; iter.Valid(); iter.Next() { - addr := sdk.ValAddress(iter.Key()[1:]) + addr := sdk.ValAddress(stakingtypes.AddressFromValidatorsKey(iter.Key())) validator, found := app.StakingKeeper.GetValidator(ctx, addr) if !found { return fmt.Errorf("expected validator %s not found", addr) diff --git a/app/sim_test.go b/app/sim_test.go index 71e4060c..ed6ba521 100644 --- a/app/sim_test.go +++ b/app/sim_test.go @@ -8,13 +8,13 @@ import ( "testing" "github.com/evmos/ethermint/encoding" + abci "github.com/tendermint/tendermint/abci/types" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/cosmos/cosmos-sdk/x/authz" authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" @@ -23,7 +23,6 @@ import ( paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/cosmos/cosmos-sdk/x/simulation" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" ibctransfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types" ibchost "github.com/cosmos/ibc-go/v3/modules/core/24-host" feemarkettypes "github.com/evmos/ethermint/x/feemarket/types" @@ -32,11 +31,8 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" dbm "github.com/tendermint/tm-db" - epochstypes "github.com/Canto-Network/Canto/v6/x/epochs/types" - liquidstakingtypes "github.com/Canto-Network/Canto/v6/x/liquidstaking/types" - cantoconfig "github.com/Canto-Network/Canto/v6/cmd/config" - inflationtypes "github.com/Canto-Network/Canto/v6/x/inflation/types" + liquidstakingtypes "github.com/Canto-Network/Canto/v6/x/liquidstaking/types" ) // Get flags every time the simulator is run @@ -77,7 +73,7 @@ func TestFullAppSimulation(t *testing.T) { // TODO: shadowed cantoApp := NewCanto(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, simapp.FlagPeriodValue, - encoding.MakeConfig(ModuleBasics), EmptyAppOptions{}, fauxMerkleModeOpt) + true, encoding.MakeConfig(ModuleBasics), EmptyAppOptions{}, fauxMerkleModeOpt) require.Equal(t, cantoconfig.AppName, cantoApp.Name()) // run randomized simulation @@ -116,6 +112,8 @@ func TestAppImportExport(t *testing.T) { require.NoError(t, os.RemoveAll(dir)) }() + sdk.DefaultPowerReduction = sdk.NewIntFromUint64(1000000) + app := NewCanto( logger, db, @@ -124,6 +122,7 @@ func TestAppImportExport(t *testing.T) { map[int64]bool{}, DefaultNodeHome, simapp.FlagPeriodValue, + true, encoding.MakeConfig(ModuleBasics), EmptyAppOptions{}, fauxMerkleModeOpt, @@ -175,6 +174,7 @@ func TestAppImportExport(t *testing.T) { map[int64]bool{}, DefaultNodeHome, simapp.FlagPeriodValue, + true, encoding.MakeConfig(ModuleBasics), EmptyAppOptions{}, fauxMerkleModeOpt, @@ -193,34 +193,34 @@ func TestAppImportExport(t *testing.T) { fmt.Println("comparing stores...") storeKeysPrefixes := []StoreKeysPrefixes{ - {app.keys[authtypes.StoreKey], newApp.keys[authtypes.ModuleName], [][]byte{}}, - {app.keys[banktypes.StoreKey], newApp.keys[banktypes.ModuleName], [][]byte{banktypes.BalancesPrefix}}, - {app.keys[stakingtypes.StoreKey], newApp.keys[stakingtypes.ModuleName], + {app.keys[authtypes.StoreKey], newApp.keys[authtypes.StoreKey], [][]byte{}}, + {app.keys[banktypes.StoreKey], newApp.keys[banktypes.StoreKey], [][]byte{banktypes.BalancesPrefix}}, + {app.keys[stakingtypes.StoreKey], newApp.keys[stakingtypes.StoreKey], [][]byte{ stakingtypes.UnbondingQueueKey, stakingtypes.RedelegationQueueKey, stakingtypes.ValidatorQueueKey, stakingtypes.HistoricalInfoKey, }, }, - {app.keys[distrtypes.StoreKey], newApp.keys[distrtypes.ModuleName], [][]byte{}}, - {app.keys[paramstypes.StoreKey], newApp.keys[paramstypes.ModuleName], [][]byte{}}, - {app.keys[upgradetypes.StoreKey], newApp.keys[upgradetypes.ModuleName], [][]byte{}}, - {app.keys[evidencetypes.StoreKey], newApp.keys[evidencetypes.ModuleName], [][]byte{}}, - {app.keys[capabilitytypes.StoreKey], newApp.keys[capabilitytypes.ModuleName], [][]byte{}}, - //{app.keys[feegrant.StoreKey], newApp.keys[feegrant.ModuleName], [][]byte{}}, - {app.keys[authzkeeper.StoreKey], newApp.keys[authz.ModuleName], [][]byte{}}, - {app.keys[ibchost.StoreKey], newApp.keys[ibchost.ModuleName], [][]byte{}}, - {app.keys[ibctransfertypes.StoreKey], newApp.keys[ibctransfertypes.ModuleName], [][]byte{}}, - //{app.keys[evmtypes.StoreKey], newApp.keys[evmtypes.ModuleName], [][]byte{}}, - {app.keys[feemarkettypes.StoreKey], newApp.keys[feemarkettypes.ModuleName], [][]byte{}}, - {app.keys[inflationtypes.StoreKey], newApp.keys[inflationtypes.ModuleName], [][]byte{}}, - //{app.keys[erc20types.StoreKey], newApp.keys[erc20types.ModuleName], [][]byte{}}, - {app.keys[epochstypes.StoreKey], newApp.keys[epochstypes.ModuleName], [][]byte{}}, - //{app.keys[vestingtypes.StoreKey], newApp.keys[vestingtypes.ModuleName], [][]byte{}}, - //{app.keys[recoverytypes.StoreKey], newApp.keys[recoverytypes.ModuleName], [][]byte{}}, - //{app.keys[feestypes.StoreKey], newApp.keys[feestypes.ModuleName], [][]byte{}}, - //{app.keys[csrtypes.StoreKey], newApp.keys[csrtypes.ModuleName], [][]byte{}}, - //{app.keys[govshuttletypes.StoreKey], newApp.keys[govshuttletypes.ModuleName], [][]byte{}}, - {app.keys[liquidstakingtypes.StoreKey], newApp.keys[liquidstakingtypes.ModuleName], [][]byte{}}, + {app.keys[distrtypes.StoreKey], newApp.keys[distrtypes.StoreKey], [][]byte{}}, + {app.keys[paramstypes.StoreKey], newApp.keys[paramstypes.StoreKey], [][]byte{}}, + //{app.keys[upgradetypes.StoreKey], newApp.keys[upgradetypes.StoreKey], [][]byte{}}, + {app.keys[evidencetypes.StoreKey], newApp.keys[evidencetypes.StoreKey], [][]byte{}}, + {app.keys[capabilitytypes.StoreKey], newApp.keys[capabilitytypes.StoreKey], [][]byte{}}, + // {app.keys[feegrant.StoreKey], newApp.keys[feegrant.StoreKey], [][]byte{}}, + {app.keys[authzkeeper.StoreKey], newApp.keys[authzkeeper.StoreKey], [][]byte{}}, + {app.keys[ibchost.StoreKey], newApp.keys[ibchost.StoreKey], [][]byte{}}, + {app.keys[ibctransfertypes.StoreKey], newApp.keys[ibctransfertypes.StoreKey], [][]byte{}}, + // {app.keys[evmtypes.StoreKey], newApp.keys[evmtypes.StoreKey], [][]byte{}}, + {app.keys[feemarkettypes.StoreKey], newApp.keys[feemarkettypes.StoreKey], [][]byte{}}, + //{app.keys[inflationtypes.StoreKey], newApp.keys[inflationtypes.StoreKey], [][]byte{}}, + // {app.keys[erc20types.StoreKey], newApp.keys[erc20types.StoreKey], [][]byte{}}, + //{app.keys[epochstypes.StoreKey], newApp.keys[epochstypes.StoreKey], [][]byte{}}, + // {app.keys[vestingtypes.StoreKey], newApp.keys[vestingtypes.StoreKey], [][]byte{}}, + // {app.keys[recoverytypes.StoreKey], newApp.keys[recoverytypes.StoreKey], [][]byte{}}, + // {app.keys[feestypes.StoreKey], newApp.keys[feestypes.StoreKey], [][]byte{}}, + // {app.keys[csrtypes.StoreKey], newApp.keys[csrtypes.StoreKey], [][]byte{}}, + // {app.keys[govshuttletypes.StoreKey], newApp.keys[govshuttletypes.StoreKey], [][]byte{}}, + {app.keys[liquidstakingtypes.StoreKey], newApp.keys[liquidstakingtypes.StoreKey], [][]byte{}}, } for _, skp := range storeKeysPrefixes { @@ -251,6 +251,8 @@ func TestAppStateDeterminism(t *testing.T) { numTimesToRunPerSeed := 5 appHashList := make([]json.RawMessage, numTimesToRunPerSeed) + sdk.DefaultPowerReduction = sdk.NewIntFromUint64(1000000) + for i := 0; i < numSeeds; i++ { config.Seed = rand.Int63() @@ -271,6 +273,7 @@ func TestAppStateDeterminism(t *testing.T) { map[int64]bool{}, DefaultNodeHome, simapp.FlagPeriodValue, + true, encoding.MakeConfig(ModuleBasics), EmptyAppOptions{}, fauxMerkleModeOpt, @@ -305,3 +308,108 @@ func TestAppStateDeterminism(t *testing.T) { } } } + +func TestAppSimulationAfterImport(t *testing.T) { + config, db, dir, logger, skip, err := simapp.SetupSimulation("leveldb-app-sim", "Simulation") + if skip { + t.Skip("skipping application simulation after import") + } + require.NoError(t, err, "simulation setup failed") + config.ChainID = "canto_9000-1" + + defer func() { + db.Close() + require.NoError(t, os.RemoveAll(dir)) + }() + + sdk.DefaultPowerReduction = sdk.NewIntFromUint64(1000000) + + app := NewCanto( + logger, + db, + nil, + true, + map[int64]bool{}, + DefaultNodeHome, + simapp.FlagPeriodValue, + true, + encoding.MakeConfig(ModuleBasics), + EmptyAppOptions{}, + fauxMerkleModeOpt, + ) + require.Equal(t, cantoconfig.AppName, app.Name()) + + // Run randomized simulation + stopEarly, simParams, simErr := simulation.SimulateFromSeed( + t, + os.Stdout, + app.BaseApp, + AppStateFn(app.AppCodec(), app.SimulationManager()), + RandomAccounts, // Replace with own random account function if using keys other than secp256k1 + simapp.SimulationOperations(app, app.AppCodec(), config), + app.ModuleAccountAddrs(), + config, + app.AppCodec(), + ) + + // export state and simParams before the simulation error is checked + err = simapp.CheckExportSimulation(app, config, simParams) + require.NoError(t, err) + require.NoError(t, simErr) + + if config.Commit { + simapp.PrintStats(db) + } + + if stopEarly { + fmt.Println("can't export or import a zero-validator genesis, exiting test...") + return + } + + fmt.Printf("exporting genesis...\n") + + exported, err := app.ExportAppStateAndValidators(true, []string{}) + require.NoError(t, err) + + fmt.Printf("importing genesis...\n") + + _, newDB, newDir, _, _, err := simapp.SetupSimulation("leveldb-app-sim-2", "Simulation-2") + require.NoError(t, err, "simulation setup failed") + + defer func() { + newDB.Close() + require.NoError(t, os.RemoveAll(newDir)) + }() + + newApp := NewCanto( + log.NewNopLogger(), + newDB, + nil, + true, + map[int64]bool{}, + DefaultNodeHome, + simapp.FlagPeriodValue, + true, + encoding.MakeConfig(ModuleBasics), + EmptyAppOptions{}, + fauxMerkleModeOpt, + ) + require.Equal(t, cantoconfig.AppName, newApp.Name()) + + newApp.InitChain(abci.RequestInitChain{ + AppStateBytes: exported.AppState, + }) + + _, _, err = simulation.SimulateFromSeed( + t, + os.Stdout, + newApp.BaseApp, + AppStateFn(app.AppCodec(), app.SimulationManager()), + RandomAccounts, // Replace with own random account function if using keys other than secp256k1 + simapp.SimulationOperations(newApp, newApp.AppCodec(), config), + app.ModuleAccountAddrs(), + config, + app.AppCodec(), + ) + require.NoError(t, err) +} diff --git a/app/state.go b/app/state.go index 0c1ca896..b1f6b670 100644 --- a/app/state.go +++ b/app/state.go @@ -3,8 +3,12 @@ package app import ( "encoding/json" "fmt" + "io" + "math/rand" + "os" + "time" + "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" simappparams "github.com/cosmos/cosmos-sdk/simapp/params" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" @@ -14,10 +18,8 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" tmjson "github.com/tendermint/tendermint/libs/json" tmtypes "github.com/tendermint/tendermint/types" - "io" - "math/rand" - "os" - "time" + + "github.com/evmos/ethermint/crypto/ethsecp256k1" ) var FlagGenesisTimeValue = int64(1640995200) @@ -219,7 +221,10 @@ func AppStateFromGenesisFileFn(r io.Reader, cdc codec.JSONCodec, genesisFile str if _, err := r.Read(privkeySeed); err != nil { panic(err) } - privKey := ed25519.GenPrivKeyFromSecret(privkeySeed) + privKey, err := ethsecp256k1.GenerateKey() + if err != nil { + panic(err) + } a, ok := acc.GetCachedValue().(authtypes.AccountI) if !ok { diff --git a/app/test_helpers.go b/app/test_helpers.go index 801bb4be..4f22b63d 100644 --- a/app/test_helpers.go +++ b/app/test_helpers.go @@ -61,7 +61,7 @@ func Setup( feemarketGenesis *feemarkettypes.GenesisState, ) *Canto { db := dbm.NewMemDB() - app := NewCanto(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5, encoding.MakeConfig(ModuleBasics), simapp.EmptyAppOptions{}) + app := NewCanto(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5, false, encoding.MakeConfig(ModuleBasics), simapp.EmptyAppOptions{}) if !isCheckTx { // init chain must be called to stop deliverState from being nil genesisState := NewDefaultGenesisState() @@ -97,7 +97,7 @@ func Setup( func SetupTestingApp() (ibctesting.TestingApp, map[string]json.RawMessage) { db := dbm.NewMemDB() cfg := encoding.MakeConfig(ModuleBasics) - app := NewCanto(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5, cfg, simapp.EmptyAppOptions{}) + app := NewCanto(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5, false, cfg, simapp.EmptyAppOptions{}) return app, NewDefaultGenesisState() } diff --git a/cmd/cantod/root.go b/cmd/cantod/root.go index 1609d451..10448857 100644 --- a/cmd/cantod/root.go +++ b/cmd/cantod/root.go @@ -242,6 +242,7 @@ func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, a logger, db, traceStore, true, skipUpgradeHeights, cast.ToString(appOpts.Get(flags.FlagHome)), cast.ToUint(appOpts.Get(sdkserver.FlagInvCheckPeriod)), + false, a.encCfg, appOpts, baseapp.SetPruning(pruningOpts), @@ -273,13 +274,13 @@ func (a appCreator) appExport( } if height != -1 { - cantoApp = app.NewCanto(logger, db, traceStore, false, map[int64]bool{}, "", uint(1), a.encCfg, appOpts) + cantoApp = app.NewCanto(logger, db, traceStore, false, map[int64]bool{}, "", uint(1), false, a.encCfg, appOpts) if err := cantoApp.LoadHeight(height); err != nil { return servertypes.ExportedApp{}, err } } else { - cantoApp = app.NewCanto(logger, db, traceStore, true, map[int64]bool{}, "", uint(1), a.encCfg, appOpts) + cantoApp = app.NewCanto(logger, db, traceStore, true, map[int64]bool{}, "", uint(1), false, a.encCfg, appOpts) } return cantoApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs) diff --git a/testutil/network/network.go b/testutil/network/network.go index 2fd58808..016d029b 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -27,7 +27,6 @@ import ( dbm "github.com/tendermint/tm-db" "google.golang.org/grpc" - "github.com/Canto-Network/Canto/v6/app" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/tx" @@ -50,6 +49,8 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/evmos/ethermint/crypto/hd" + "github.com/Canto-Network/Canto/v6/app" + "github.com/evmos/ethermint/encoding" "github.com/evmos/ethermint/server/config" ethermint "github.com/evmos/ethermint/types" @@ -127,6 +128,7 @@ func NewAppConstructor(encodingCfg params.EncodingConfig) AppConstructor { return func(val Validator) servertypes.Application { return app.NewCanto( val.Ctx.Logger, dbm.NewMemDB(), nil, true, make(map[int64]bool), val.Ctx.Config.RootDir, 0, + false, encodingCfg, simapp.EmptyAppOptions{}, baseapp.SetPruning(storetypes.NewPruningOptionsFromString(val.AppConfig.Pruning)), From c8306e2fcf261bb44fc975118837d1294e433998 Mon Sep 17 00:00:00 2001 From: poorphd Date: Thu, 20 Jul 2023 16:49:26 +0900 Subject: [PATCH 2/4] fix: simulation errors (cherry picked from commit 69619673432dd985fbd81ca75a7dc1dff9e2f6c1) --- app/sim_test.go | 16 +++++++++------- app/state.go | 2 ++ init_testnet.sh | 12 +++++++++++- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/app/sim_test.go b/app/sim_test.go index ed6ba521..795b2092 100644 --- a/app/sim_test.go +++ b/app/sim_test.go @@ -7,9 +7,6 @@ import ( "os" "testing" - "github.com/evmos/ethermint/encoding" - abci "github.com/tendermint/tendermint/abci/types" - "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/store" @@ -25,6 +22,7 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ibctransfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types" ibchost "github.com/cosmos/ibc-go/v3/modules/core/24-host" + "github.com/evmos/ethermint/encoding" feemarkettypes "github.com/evmos/ethermint/x/feemarket/types" "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/libs/log" @@ -186,7 +184,7 @@ func TestAppImportExport(t *testing.T) { require.NoError(t, err) ctxA := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}) - ctxB := newApp.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}) + ctxB := newApp.NewContext(true, tmproto.Header{ChainID: config.ChainID, Height: app.LastBlockHeight()}) newApp.mm.InitGenesis(ctxB, app.AppCodec(), genesisState) newApp.StoreConsensusParams(ctxB, exported.ConsensusParams) @@ -396,9 +394,13 @@ func TestAppSimulationAfterImport(t *testing.T) { ) require.Equal(t, cantoconfig.AppName, newApp.Name()) - newApp.InitChain(abci.RequestInitChain{ - AppStateBytes: exported.AppState, - }) + var genesisState GenesisState + err = json.Unmarshal(exported.AppState, &genesisState) + require.NoError(t, err) + + ctx := newApp.NewContext(true, tmproto.Header{ChainID: config.ChainID, Height: app.LastBlockHeight()}) + newApp.mm.InitGenesis(ctx, app.AppCodec(), genesisState) + newApp.StoreConsensusParams(ctx, exported.ConsensusParams) _, _, err = simulation.SimulateFromSeed( t, diff --git a/app/state.go b/app/state.go index b1f6b670..84b812e5 100644 --- a/app/state.go +++ b/app/state.go @@ -9,6 +9,7 @@ import ( "time" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" simappparams "github.com/cosmos/cosmos-sdk/simapp/params" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" @@ -235,6 +236,7 @@ func AppStateFromGenesisFileFn(r io.Reader, cdc codec.JSONCodec, genesisFile str PrivKey: privKey, PubKey: privKey.PubKey(), Address: a.GetAddress(), + ConsKey: ed25519.GenPrivKeyFromSecret(privkeySeed), } newAccs[i] = simAcc } diff --git a/init_testnet.sh b/init_testnet.sh index 5ea7b9f5..9845d5a9 100755 --- a/init_testnet.sh +++ b/init_testnet.sh @@ -1,4 +1,6 @@ KEY1="key1" +KEY2="key2" +KEY3="key3" CHAINID="canto_7701-1" MONIKER="plex-validator" KEYRING="test" @@ -21,6 +23,10 @@ cantod config chain-id $CHAINID # if $KEY exists it should be deleted cantod keys add $KEY1 --keyring-backend $KEYRING --algo $KEYALGO +cantod keys add $KEY2 --keyring-backend $KEYRING --algo $KEYALGO +cantod keys add $KEY3 --keyring-backend $KEYRING --algo $KEYALGO + + # Set moniker and chain-id for Canto (Moniker can be anything, chain-id must be an integer) cantod init $MONIKER --chain-id $CHAINID @@ -69,12 +75,16 @@ fi # Allocate genesis accounts (cosmos formatted addresses) cantod add-genesis-account $KEY1 1050000000000000000000000000acanto --keyring-backend $KEYRING +cantod add-genesis-account $KEY2 1000000000000000000000000000acanto --keyring-backend $KEYRING +cantod add-genesis-account $KEY3 1000000000000000000000000000acanto --keyring-backend $KEYRING + + # Update total supply with claim values #validators_supply=$(cat $HOME/.cantod/config/genesis.json | jq -r '.app_state["bank"]["supply"][0]["amount"]') # Bc is required to add this big numbers # total_supply=$(bc <<< "$amount_to_claim+$validators_supply") -total_supply=1050000000000000000000000000 +total_supply=3050000000000000000000000000 cat $HOME/.cantod/config/genesis.json | jq -r --arg total_supply "$total_supply" '.app_state["bank"]["supply"][0]["amount"]=$total_supply' > $HOME/.cantod/config/tmp_genesis.json && mv $HOME/.cantod/config/tmp_genesis.json $HOME/.cantod/config/genesis.json echo $KEYRING From 6760e613fa7e701afd345bf266cc9c9b11a4ac21 Mon Sep 17 00:00:00 2001 From: dongsam Date: Thu, 20 Jul 2023 21:04:03 +0900 Subject: [PATCH 3/4] fix: simulation workflow --- .github/workflows/sims.yml | 237 ++++++++++++++++++------------------- Makefile | 23 +++- 2 files changed, 137 insertions(+), 123 deletions(-) diff --git a/.github/workflows/sims.yml b/.github/workflows/sims.yml index c9447eb0..87993a50 100644 --- a/.github/workflows/sims.yml +++ b/.github/workflows/sims.yml @@ -1,121 +1,120 @@ -#name: Sims +name: Sims # Sims workflow runs multiple types of simulations (nondeterminism, import-export, after-import) # This workflow will run on all Pull Requests, if a .go, .mod or .sum file have been changed -# Temporary disable until it is fixed -#on: -# pull_request: -# push: -# branches: -# - main -# - develop -# -#jobs: -# build: -# runs-on: ubuntu-latest -# if: "!contains(github.event.head_commit.message, 'skip-sims')" -# steps: -# - uses: actions/checkout@v2 -# - uses: actions/setup-go@v2.1.3 -# with: -# go-version: 1.18 -# - name: Display go version -# run: go version -# - run: make build -# -# install-runsim: -# runs-on: ubuntu-latest -# needs: build -# steps: -# - uses: actions/setup-go@v2.1.3 -# with: -# go-version: 1.18 -# - name: Display go version -# run: go version -# - name: Install runsim -# run: export GO111MODULE="on" && go install github.com/cosmos/tools/cmd/runsim@v1.0.0 -# - uses: actions/cache@v2.1.6 -# with: -# path: ~/go/bin -# key: ${{ runner.os }}-go-runsim-binary -# -# test-sim-nondeterminism: -# runs-on: ubuntu-latest -# needs: [build, install-runsim] -# steps: -# - uses: actions/checkout@v2 -# - uses: actions/setup-go@v2.1.3 -# with: -# go-version: 1.18 -# - name: Display go version -# run: go version -# - uses: technote-space/get-diff-action@v4 -# with: -# PATTERNS: | -# **/**.go -# go.mod -# go.sum -# - uses: actions/cache@v2.1.6 -# with: -# path: ~/go/bin -# key: ${{ runner.os }}-go-runsim-binary -# if: env.GIT_DIFF -# - name: test-sim-nondeterminism -# run: | -# make test-sim-nondeterminism -# if: env.GIT_DIFF -# -# test-sim-import-export: -# runs-on: ubuntu-latest -# needs: [build, install-runsim] -# steps: -# - uses: actions/checkout@v2 -# - uses: actions/setup-go@v2.1.3 -# with: -# go-version: 1.18 -# - name: Display go version -# run: go version -# - uses: technote-space/get-diff-action@v4 -# with: -# SUFFIX_FILTER: | -# **/**.go -# go.mod -# go.sum -# SET_ENV_NAME_INSERTIONS: 1 -# SET_ENV_NAME_LINES: 1 -# - uses: actions/cache@v2.1.6 -# with: -# path: ~/go/bin -# key: ${{ runner.os }}-go-runsim-binary -# if: env.GIT_DIFF -# - name: test-sim-import-export -# run: | -# make test-sim-import-export -# if: env.GIT_DIFF -# -# test-sim-after-import: -# runs-on: ubuntu-latest -# needs: [build, install-runsim] -# steps: -# - uses: actions/checkout@v2 -# - uses: actions/setup-go@v2.1.3 -# with: -# go-version: 1.18 -# - name: Display go version -# run: go version -# - uses: technote-space/get-diff-action@v4 -# with: -# SUFFIX_FILTER: | -# **/**.go -# go.mod -# go.sum -# SET_ENV_NAME_INSERTIONS: 1 -# SET_ENV_NAME_LINES: 1 -# - uses: actions/cache@v2.1.6 -# with: -# path: ~/go/bin -# key: ${{ runner.os }}-go-runsim-binary -# if: env.GIT_DIFF -# - name: test-sim-after-import -# run: | -# make test-sim-after-import -# if: env.GIT_DIFF +on: + pull_request: + push: + branches: + - main + - develop + +jobs: + build: + runs-on: ubuntu-latest + if: "!contains(github.event.head_commit.message, 'skip-sims')" + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v2.1.3 + with: + go-version: 1.18 + - name: Display go version + run: go version + - run: make build + + install-runsim: + runs-on: ubuntu-latest + needs: build + steps: + - uses: actions/setup-go@v2.1.3 + with: + go-version: 1.18 + - name: Display go version + run: go version + - name: Install runsim + run: export GO111MODULE="on" && go install github.com/cosmos/tools/cmd/runsim@v1.0.0 + - uses: actions/cache@v2.1.6 + with: + path: ~/go/bin + key: ${{ runner.os }}-go-runsim-binary + + test-sim-nondeterminism: + runs-on: ubuntu-latest + needs: [build, install-runsim] + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v2.1.3 + with: + go-version: 1.18 + - name: Display go version + run: go version + - uses: technote-space/get-diff-action@v4 + with: + PATTERNS: | + **/**.go + go.mod + go.sum + - uses: actions/cache@v2.1.6 + with: + path: ~/go/bin + key: ${{ runner.os }}-go-runsim-binary + if: env.GIT_DIFF + - name: test-sim-nondeterminism + run: | + make test-sim-nondeterminism + if: env.GIT_DIFF + + test-sim-import-export: + runs-on: ubuntu-latest + needs: [build, install-runsim] + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v2.1.3 + with: + go-version: 1.18 + - name: Display go version + run: go version + - uses: technote-space/get-diff-action@v4 + with: + SUFFIX_FILTER: | + **/**.go + go.mod + go.sum + SET_ENV_NAME_INSERTIONS: 1 + SET_ENV_NAME_LINES: 1 + - uses: actions/cache@v2.1.6 + with: + path: ~/go/bin + key: ${{ runner.os }}-go-runsim-binary + if: env.GIT_DIFF + - name: test-sim-import-export + run: | + make test-sim-import-export + if: env.GIT_DIFF + + test-sim-after-import: + runs-on: ubuntu-latest + needs: [build, install-runsim] + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v2.1.3 + with: + go-version: 1.18 + - name: Display go version + run: go version + - uses: technote-space/get-diff-action@v4 + with: + SUFFIX_FILTER: | + **/**.go + go.mod + go.sum + SET_ENV_NAME_INSERTIONS: 1 + SET_ENV_NAME_LINES: 1 + - uses: actions/cache@v2.1.6 + with: + path: ~/go/bin + key: ${{ runner.os }}-go-runsim-binary + if: env.GIT_DIFF + - name: test-sim-after-import + run: | + make test-sim-after-import + if: env.GIT_DIFF diff --git a/Makefile b/Makefile index 3f9da0a1..3da80eb8 100755 --- a/Makefile +++ b/Makefile @@ -197,7 +197,7 @@ RUNSIM = $(TOOLS_DESTDIR)/runsim runsim: $(RUNSIM) $(RUNSIM): @echo "Installing runsim..." - @(cd /tmp && ${GO_MOD} go get github.com/cosmos/tools/cmd/runsim@master) + @(cd /tmp && go install github.com/cosmos/tools/cmd/runsim@v1.0.0) statik: $(STATIK) $(STATIK): @@ -371,7 +371,12 @@ test-rpc-pending: test-sim-nondeterminism: @echo "Running non-determinism test..." @go test -mod=readonly $(SIMAPP) -run TestAppStateDeterminism -Enabled=true \ - -NumBlocks=100 -BlockSize=200 -Commit=true -Period=1 -v -timeout 1h + -NumBlocks=20 -BlockSize=100 -Commit=true -Period=1 -v -timeout 10m + +test-sim-nondeterminism-long: + @echo "Running non-determinism-long test..." + @go test -mod=readonly $(SIMAPP) -run TestAppStateDeterminism -Enabled=true \ + -NumBlocks=100 -BlockSize=200 -Commit=true -Period=1 -v -timeout 10h test-sim-custom-genesis-fast: @echo "Running custom genesis simulation..." @@ -381,11 +386,21 @@ test-sim-custom-genesis-fast: test-sim-import-export: runsim @echo "Running application import/export simulation. This may take several minutes..." - @$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(SIMAPP) -ExitOnFail 50 5 TestAppImportExport + @$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(SIMAPP) -Seeds=1,10,100,1000 -ExitOnFail 50 5 TestAppImportExport + +test-sim-import-export-long: runsim + @echo "Running application simulation-import-export-long. This may take several minutes..." + $(eval SEED := $(shell awk 'BEGIN{srand(); for (i=1; i<=50; i++) {n=int(10000*rand())+1; printf "%d%s", n, (i==50 ? "" : ",")}}')) + @$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(SIMAPP) -Seeds="$(SEED)" -ExitOnFail 500 5 TestAppImportExport test-sim-after-import: runsim @echo "Running application simulation-after-import. This may take several minutes..." - @$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(SIMAPP) -ExitOnFail 50 5 TestAppSimulationAfterImport + @$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(SIMAPP) -Seeds=1,10,100,1000 -ExitOnFail 50 5 TestAppSimulationAfterImport + +test-sim-after-import-long: runsim + @echo "Running application simulation-after-import-long. This may take several minutes..." + $(eval SEED := $(shell awk 'BEGIN{srand(); for (i=1; i<=50; i++) {n=int(10000*rand())+1; printf "%d%s", n, (i==50 ? "" : ",")}}')) + @$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(SIMAPP) -Seeds="$(SEED)" -ExitOnFail 500 5 TestAppSimulationAfterImport test-sim-custom-genesis-multi-seed: runsim @echo "Running multi-seed custom genesis simulation..." From 0a53f003b057c325f039b8efcad171ccaa3077e7 Mon Sep 17 00:00:00 2001 From: dongsam Date: Thu, 20 Jul 2023 21:46:06 +0900 Subject: [PATCH 4/4] fix: update sims.yml, add GOPATH on makefile --- .github/workflows/sims.yml | 53 ++++++++++++++++++-------------------- Makefile | 18 +++++++++++++ 2 files changed, 43 insertions(+), 28 deletions(-) diff --git a/.github/workflows/sims.yml b/.github/workflows/sims.yml index 87993a50..7cb31de8 100644 --- a/.github/workflows/sims.yml +++ b/.github/workflows/sims.yml @@ -13,36 +13,22 @@ jobs: runs-on: ubuntu-latest if: "!contains(github.event.head_commit.message, 'skip-sims')" steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v2.1.3 + - uses: actions/checkout@v3.5.2 + - uses: actions/setup-go@v4 with: go-version: 1.18 + - name: Install runsim + run: go install github.com/cosmos/tools/cmd/runsim@v1.0.0 - name: Display go version run: go version - run: make build - install-runsim: - runs-on: ubuntu-latest - needs: build - steps: - - uses: actions/setup-go@v2.1.3 - with: - go-version: 1.18 - - name: Display go version - run: go version - - name: Install runsim - run: export GO111MODULE="on" && go install github.com/cosmos/tools/cmd/runsim@v1.0.0 - - uses: actions/cache@v2.1.6 - with: - path: ~/go/bin - key: ${{ runner.os }}-go-runsim-binary - test-sim-nondeterminism: runs-on: ubuntu-latest - needs: [build, install-runsim] + needs: build steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v2.1.3 + - uses: actions/checkout@v3.5.2 + - uses: actions/setup-go@v4 with: go-version: 1.18 - name: Display go version @@ -53,7 +39,7 @@ jobs: **/**.go go.mod go.sum - - uses: actions/cache@v2.1.6 + - uses: actions/cache@v3.3.1 with: path: ~/go/bin key: ${{ runner.os }}-go-runsim-binary @@ -63,12 +49,23 @@ jobs: make test-sim-nondeterminism if: env.GIT_DIFF + install-runsim: + runs-on: ubuntu-latest + needs: build + steps: + - name: Install runsim + run: go install github.com/cosmos/tools/cmd/runsim@v1.0.0 + - uses: actions/cache@v3.3.1 + with: + path: ~/go/bin + key: ${{ runner.os }}-go-runsim-binary + test-sim-import-export: runs-on: ubuntu-latest needs: [build, install-runsim] steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v2.1.3 + - uses: actions/checkout@v3.5.2 + - uses: actions/setup-go@v4 with: go-version: 1.18 - name: Display go version @@ -81,7 +78,7 @@ jobs: go.sum SET_ENV_NAME_INSERTIONS: 1 SET_ENV_NAME_LINES: 1 - - uses: actions/cache@v2.1.6 + - uses: actions/cache@v3.3.1 with: path: ~/go/bin key: ${{ runner.os }}-go-runsim-binary @@ -95,8 +92,8 @@ jobs: runs-on: ubuntu-latest needs: [build, install-runsim] steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v2.1.3 + - uses: actions/checkout@v3.5.2 + - uses: actions/setup-go@v4 with: go-version: 1.18 - name: Display go version @@ -109,7 +106,7 @@ jobs: go.sum SET_ENV_NAME_INSERTIONS: 1 SET_ENV_NAME_LINES: 1 - - uses: actions/cache@v2.1.6 + - uses: actions/cache@v3.3.1 with: path: ~/go/bin key: ${{ runner.os }}-go-runsim-binary diff --git a/Makefile b/Makefile index 3da80eb8..99f9d88e 100755 --- a/Makefile +++ b/Makefile @@ -1,5 +1,22 @@ #!/usr/bin/make -f +### +# Find OS and Go environment +# GO contains the Go binary +# FS contains the OS file separator +### +ifeq ($(OS),Windows_NT) + GO := $(shell where go.exe 2> NUL) + FS := \\ +else + GO := $(shell command -v go 2> /dev/null) + FS := / +endif + +ifeq ($(GO),) + $(error could not find go. Is it in PATH? $(GO)) +endif + PACKAGES_NOSIMULATION=$(shell go list ./... | grep -v '/simulation') PACKAGES_SIMTEST=$(shell go list ./... | grep '/simulation') DIFF_TAG=$(shell git rev-list --tags="v*" --max-count=1 --not $(shell git rev-list --tags="v*" "HEAD..origin")) @@ -8,6 +25,7 @@ VERSION ?= $(shell echo $(shell git describe --tags $(or $(DIFF_TAG), $(DEFAULT_ TMVERSION := $(shell go list -m github.com/tendermint/tendermint | sed 's:.* ::') COMMIT := $(shell git log -1 --format='%H') LEDGER_ENABLED ?= true +GOPATH ?= $(shell $(GO) env GOPATH) BINDIR ?= $(GOPATH)/bin canto_BINARY = cantod canto_DIR = cantod