From 39c49c6cacd7443939372fde48912f247016127a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Federico=20Kunze=20K=C3=BCllmer?= <31522760+fedekunze@users.noreply.github.com> Date: Sun, 24 Oct 2021 13:48:00 +0200 Subject: [PATCH] release: cherry-pick v0.7.2 (#696) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * changelog * go.mod * fix: handle file close logic (#679) * handle file close logic * Update rpc/ethereum/namespaces/debug/utils.go * update changelog Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * remove unused var (#680) Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * c++ * fix * tendermint * c++ * don't use IBC v2 * fix Co-authored-by: Tomas Tauber <2410580+tomtau@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: JayT106 --- CHANGELOG.md | 12 + app/export.go | 2 - app/simulation_test.go | 685 +++++++++++++------------ cmd/ethermintd/root.go | 8 +- go.mod | 7 +- go.sum | 12 +- rpc/ethereum/namespaces/debug/api.go | 7 +- rpc/ethereum/namespaces/debug/trace.go | 7 +- rpc/ethereum/namespaces/debug/utils.go | 31 +- server/start.go | 7 +- x/evm/keeper/state_transition_test.go | 2 +- 11 files changed, 413 insertions(+), 367 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 626dca1e4a..1c0ab5d616 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,18 @@ Ref: https://keepachangelog.com/en/1.0.0/ # Changelog +## [v0.7.2] - 2021-10-22 + +### Improvements + +* (deps) [tharsis#692](https://github.com/tharsis/ethermint/pull/692) Bump Cosmos SDK version to [`v0.44.3`](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.44.3). +* (rpc) [tharsis#679](https://github.com/tharsis/ethermint/pull/679) Fix file close handle. +* (deps) [tharsis#668](https://github.com/tharsis/ethermint/pull/668) Bump Tendermint version to [`v0.34.14`](https://github.com/tendermint/tendermint/releases/tag/v0.34.14). + +### Bug Fixes + +* (rpc) [tharsis#667](https://github.com/tharsis/ethermint/issues/667) Fix `ExpandHome` restrictions bypass + ## [v0.7.1] - 2021-10-08 ### Bug Fixes diff --git a/app/export.go b/app/export.go index 5394063297..e1fd1187e8 100644 --- a/app/export.go +++ b/app/export.go @@ -170,7 +170,6 @@ func (app *EthermintApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAd // update bond intra-tx counters. store := ctx.KVStore(app.keys[stakingtypes.StoreKey]) iter := sdk.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey) - counter := int16(0) for ; iter.Valid(); iter.Next() { addr := sdk.ValAddress(stakingtypes.AddressFromValidatorsKey(iter.Key())) @@ -185,7 +184,6 @@ func (app *EthermintApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAd } app.StakingKeeper.SetValidator(ctx, validator) - counter++ } iter.Close() diff --git a/app/simulation_test.go b/app/simulation_test.go index 34b013e0f6..ab7f981def 100644 --- a/app/simulation_test.go +++ b/app/simulation_test.go @@ -1,340 +1,349 @@ package app -// disable for now, enable it once SDK side fix the simulator issue for custom keys -//import ( -// "encoding/json" -// "fmt" -// "math/rand" -// "os" -// "testing" -// -// "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" -// -// "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" -// sdk "github.com/cosmos/cosmos-sdk/types" -// simtypes "github.com/cosmos/cosmos-sdk/types/simulation" -// authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" -// banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" -// capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" -// distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" -// evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" -// govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" -// ibctransfertypes "github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer/types" -// ibchost "github.com/cosmos/cosmos-sdk/x/ibc/core/24-host" -// minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" -// paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" -// "github.com/cosmos/cosmos-sdk/x/simulation" -// slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" -// stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" -//) -// -//func init() { -// simapp.GetSimulatorFlags() -//} -// -//type storeKeysPrefixes struct { -// A sdk.StoreKey -// B sdk.StoreKey -// Prefixes [][]byte -//} -// -//// fauxMerkleModeOpt returns a BaseApp option to use a dbStoreAdapter instead of -//// an IAVLStore for faster simulation speed. -//func fauxMerkleModeOpt(bapp *baseapp.BaseApp) { -// bapp.SetFauxMerkleMode() -//} -// -//// interBlockCacheOpt returns a BaseApp option function that sets the persistent -//// inter-block write-through cache. -//func interBlockCacheOpt() func(*baseapp.BaseApp) { -// return baseapp.SetInterBlockCache(store.NewCommitKVStoreCacheManager()) -//} -// -//func TestFullAppSimulation(t *testing.T) { -// config, db, dir, logger, skip, err := simapp.SetupSimulation("leveldb-app-sim", "Simulation") -// if skip { -// t.Skip("skipping application simulation") -// } -// require.NoError(t, err, "simulation setup failed") -// -// defer func() { -// db.Close() -// require.NoError(t, os.RemoveAll(dir)) -// }() -// -// app := NewEthermintApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, simapp.FlagPeriodValue, MakeEncodingConfig(), simapp.EmptyAppOptions{}, fauxMerkleModeOpt) -// require.Equal(t, appName, app.Name()) -// -// // run randomized simulation -// _, simParams, simErr := simulation.SimulateFromSeed( -// t, -// os.Stdout, -// app.BaseApp, -// simapp.AppStateFn(app.AppCodec(), app.SimulationManager()), -// simtypes.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) -// } -//} -// -//func TestAppImportExport(t *testing.T) { -// config, db, dir, logger, skip, err := simapp.SetupSimulation("leveldb-app-sim", "Simulation") -// if skip { -// t.Skip("skipping application import/export simulation") -// } -// require.NoError(t, err, "simulation setup failed") -// -// defer func() { -// db.Close() -// require.NoError(t, os.RemoveAll(dir)) -// }() -// -// app := NewEthermintApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, simapp.FlagPeriodValue, MakeEncodingConfig(), simapp.EmptyAppOptions{}, fauxMerkleModeOpt) -// require.Equal(t, appName, app.Name()) -// -// // Run randomized simulation -// _, simParams, simErr := simulation.SimulateFromSeed( -// t, -// os.Stdout, -// app.BaseApp, -// simapp.AppStateFn(app.AppCodec(), app.SimulationManager()), -// simtypes.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) -// } -// -// fmt.Printf("exporting genesis...\n") -// -// exported, err := app.ExportAppStateAndValidators(false, []string{}) -// require.NoError(t, err) -// -// fmt.Printf("importing genesis...\n") -// -// // nolint: dogsled -// _, 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 := NewEthermintApp(log.NewNopLogger(), newDB, nil, true, map[int64]bool{}, DefaultNodeHome, simapp.FlagPeriodValue, MakeEncodingConfig(), simapp.EmptyAppOptions{}, fauxMerkleModeOpt) -// require.Equal(t, appName, newApp.Name()) -// -// var genesisState simapp.GenesisState -// err = json.Unmarshal(exported.AppState, &genesisState) -// require.NoError(t, err) -// -// ctxA := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}) -// ctxB := newApp.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}) -// newApp.mm.InitGenesis(ctxB, app.AppCodec(), genesisState) -// newApp.StoreConsensusParams(ctxB, exported.ConsensusParams) -// -// fmt.Printf("comparing stores...\n") -// -// storeKeysPrefixes := []storeKeysPrefixes{ -// {app.keys[authtypes.StoreKey], newApp.keys[authtypes.StoreKey], [][]byte{}}, -// {app.keys[stakingtypes.StoreKey], newApp.keys[stakingtypes.StoreKey], -// [][]byte{ -// stakingtypes.UnbondingQueueKey, stakingtypes.RedelegationQueueKey, stakingtypes.ValidatorQueueKey, -// stakingtypes.HistoricalInfoKey, -// }}, // ordering may change but it doesn't matter -// {app.keys[slashingtypes.StoreKey], newApp.keys[slashingtypes.StoreKey], [][]byte{}}, -// {app.keys[minttypes.StoreKey], newApp.keys[minttypes.StoreKey], [][]byte{}}, -// {app.keys[distrtypes.StoreKey], newApp.keys[distrtypes.StoreKey], [][]byte{}}, -// {app.keys[banktypes.StoreKey], newApp.keys[banktypes.StoreKey], [][]byte{banktypes.BalancesPrefix}}, -// {app.keys[paramtypes.StoreKey], newApp.keys[paramtypes.StoreKey], [][]byte{}}, -// {app.keys[govtypes.StoreKey], newApp.keys[govtypes.StoreKey], [][]byte{}}, -// {app.keys[evidencetypes.StoreKey], newApp.keys[evidencetypes.StoreKey], [][]byte{}}, -// {app.keys[capabilitytypes.StoreKey], newApp.keys[capabilitytypes.StoreKey], [][]byte{}}, -// {app.keys[ibchost.StoreKey], newApp.keys[ibchost.StoreKey], [][]byte{}}, -// {app.keys[ibctransfertypes.StoreKey], newApp.keys[ibctransfertypes.StoreKey], [][]byte{}}, -// } -// -// for _, skp := range storeKeysPrefixes { -// storeA := ctxA.KVStore(skp.A) -// storeB := ctxB.KVStore(skp.B) -// -// failedKVAs, failedKVBs := sdk.DiffKVStores(storeA, storeB, skp.Prefixes) -// require.Equal(t, len(failedKVAs), len(failedKVBs), "unequal sets of key-values to compare") -// -// fmt.Printf("compared %d different key/value pairs between %s and %s\n", len(failedKVAs), skp.A, skp.B) -// require.Equal(t, len(failedKVAs), 0, simapp.GetSimulationLog(skp.A.Name(), app.SimulationManager().StoreDecoders, failedKVAs, failedKVBs)) -// } -//} -// -//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") -// -// defer func() { -// db.Close() -// require.NoError(t, os.RemoveAll(dir)) -// }() -// -// app := NewEthermintApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, simapp.FlagPeriodValue, MakeEncodingConfig(), simapp.EmptyAppOptions{}, fauxMerkleModeOpt) -// require.Equal(t, appName, app.Name()) -// -// // Run randomized simulation -// stopEarly, simParams, simErr := simulation.SimulateFromSeed( -// t, -// os.Stdout, -// app.BaseApp, -// simapp.AppStateFn(app.AppCodec(), app.SimulationManager()), -// simtypes.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 := NewEthermintApp(log.NewNopLogger(), newDB, nil, true, map[int64]bool{}, DefaultNodeHome, simapp.FlagPeriodValue, MakeEncodingConfig(), simapp.EmptyAppOptions{}, fauxMerkleModeOpt) -// require.Equal(t, appName, newApp.Name()) -// -// newApp.InitChain(abci.RequestInitChain{ -// AppStateBytes: exported.AppState, -// }) -// -// _, _, err = simulation.SimulateFromSeed( -// t, -// os.Stdout, -// newApp.BaseApp, -// simapp.AppStateFn(app.AppCodec(), app.SimulationManager()), -// simtypes.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) -//} -// -//// TODO: Make another test for the fuzzer itself, which just has noOp txs -//// and doesn't depend on the application. -//func TestAppStateDeterminism(t *testing.T) { -// if !simapp.FlagEnabledValue { -// t.Skip("skipping application simulation") -// } -// -// config := simapp.NewConfigFromFlags() -// config.InitialBlockHeight = 1 -// config.ExportParamsPath = "" -// config.OnOperation = false -// config.AllInvariants = false -// config.ChainID = helpers.SimAppChainID -// -// numSeeds := 3 -// numTimesToRunPerSeed := 5 -// appHashList := make([]json.RawMessage, numTimesToRunPerSeed) -// -// for i := 0; i < numSeeds; i++ { -// config.Seed = rand.Int63() -// -// for j := 0; j < numTimesToRunPerSeed; j++ { -// var logger log.Logger -// if simapp.FlagVerboseValue { -// logger = log.TestingLogger() -// } else { -// logger = log.NewNopLogger() -// } -// -// db := dbm.NewMemDB() -// app := NewEthermintApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, simapp.FlagPeriodValue, MakeEncodingConfig(), simapp.EmptyAppOptions{}, interBlockCacheOpt()) -// -// fmt.Printf( -// "running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n", -// config.Seed, i+1, numSeeds, j+1, numTimesToRunPerSeed, -// ) -// -// _, _, err := simulation.SimulateFromSeed( -// t, -// os.Stdout, -// app.BaseApp, -// simapp.AppStateFn(app.AppCodec(), app.SimulationManager()), -// simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1 -// simapp.SimulationOperations(app, app.AppCodec(), config), -// app.ModuleAccountAddrs(), -// config, -// app.AppCodec(), -// ) -// require.NoError(t, err) -// -// if config.Commit { -// simapp.PrintStats(db) -// } -// -// appHash := app.LastCommitID().Hash -// appHashList[j] = appHash -// -// if j != 0 { -// require.Equal( -// t, string(appHashList[0]), string(appHashList[j]), -// "non-determinism in seed %d: %d/%d, attempt: %d/%d\n", config.Seed, i+1, numSeeds, j+1, numTimesToRunPerSeed, -// ) -// } -// } -// } -//} +// TODO: COsmos SDK fix for the simulator issue for custom keys +import ( + "encoding/json" + "fmt" + "math/rand" + "os" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/simapp" + "github.com/cosmos/cosmos-sdk/simapp/params" + "github.com/cosmos/cosmos-sdk/store" + sdk "github.com/cosmos/cosmos-sdk/types" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/cosmos/cosmos-sdk/x/simulation" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + ibctransfertypes "github.com/cosmos/ibc-go/modules/apps/transfer/types" + ibchost "github.com/cosmos/ibc-go/modules/core/24-host" + 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" + evmenc "github.com/tharsis/ethermint/encoding" +) + +// MakeEncodingConfig creates the EncodingConfig +func MakeEncodingConfig() params.EncodingConfig { + return evmenc.MakeConfig(ModuleBasics) +} + +func init() { + simapp.GetSimulatorFlags() +} + +const SimAppChainID = "simulation_777-1" + +type storeKeysPrefixes struct { + A sdk.StoreKey + B sdk.StoreKey + Prefixes [][]byte +} + +// fauxMerkleModeOpt returns a BaseApp option to use a dbStoreAdapter instead of +// an IAVLStore for faster simulation speed. +func fauxMerkleModeOpt(bapp *baseapp.BaseApp) { + bapp.SetFauxMerkleMode() +} + +// interBlockCacheOpt returns a BaseApp option function that sets the persistent +// inter-block write-through cache. +func interBlockCacheOpt() func(*baseapp.BaseApp) { + return baseapp.SetInterBlockCache(store.NewCommitKVStoreCacheManager()) +} + +func TestFullAppSimulation(t *testing.T) { + config, db, dir, logger, skip, err := simapp.SetupSimulation("leveldb-app-sim", "Simulation") + if skip { + t.Skip("skipping application simulation") + } + require.NoError(t, err, "simulation setup failed") + + defer func() { + db.Close() + require.NoError(t, os.RemoveAll(dir)) + }() + + app := NewEthermintApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, simapp.FlagPeriodValue, MakeEncodingConfig(), simapp.EmptyAppOptions{}, fauxMerkleModeOpt) + require.Equal(t, appName, app.Name()) + + // run randomized simulation + _, simParams, simErr := simulation.SimulateFromSeed( + t, + os.Stdout, + app.BaseApp, + simapp.AppStateFn(app.AppCodec(), app.SimulationManager()), + simtypes.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) + } +} + +func TestAppImportExport(t *testing.T) { + config, db, dir, logger, skip, err := simapp.SetupSimulation("leveldb-app-sim", "Simulation") + if skip { + t.Skip("skipping application import/export simulation") + } + require.NoError(t, err, "simulation setup failed") + + defer func() { + db.Close() + require.NoError(t, os.RemoveAll(dir)) + }() + + app := NewEthermintApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, simapp.FlagPeriodValue, MakeEncodingConfig(), simapp.EmptyAppOptions{}, fauxMerkleModeOpt) + require.Equal(t, appName, app.Name()) + + // Run randomized simulation + _, simParams, simErr := simulation.SimulateFromSeed( + t, + os.Stdout, + app.BaseApp, + simapp.AppStateFn(app.AppCodec(), app.SimulationManager()), + simtypes.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) + } + + fmt.Printf("exporting genesis...\n") + + exported, err := app.ExportAppStateAndValidators(false, []string{}) + require.NoError(t, err) + + fmt.Printf("importing genesis...\n") + + // nolint: dogsled + _, 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 := NewEthermintApp(log.NewNopLogger(), newDB, nil, true, map[int64]bool{}, DefaultNodeHome, simapp.FlagPeriodValue, MakeEncodingConfig(), simapp.EmptyAppOptions{}, fauxMerkleModeOpt) + require.Equal(t, appName, newApp.Name()) + + var genesisState simapp.GenesisState + err = json.Unmarshal(exported.AppState, &genesisState) + require.NoError(t, err) + + ctxA := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}) + ctxB := newApp.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}) + newApp.mm.InitGenesis(ctxB, app.AppCodec(), genesisState) + newApp.StoreConsensusParams(ctxB, exported.ConsensusParams) + + fmt.Printf("comparing stores...\n") + + storeKeysPrefixes := []storeKeysPrefixes{ + {app.keys[authtypes.StoreKey], newApp.keys[authtypes.StoreKey], [][]byte{}}, + { + app.keys[stakingtypes.StoreKey], newApp.keys[stakingtypes.StoreKey], + [][]byte{ + stakingtypes.UnbondingQueueKey, stakingtypes.RedelegationQueueKey, stakingtypes.ValidatorQueueKey, + stakingtypes.HistoricalInfoKey, + }, + }, // ordering may change but it doesn't matter + {app.keys[slashingtypes.StoreKey], newApp.keys[slashingtypes.StoreKey], [][]byte{}}, + {app.keys[minttypes.StoreKey], newApp.keys[minttypes.StoreKey], [][]byte{}}, + {app.keys[distrtypes.StoreKey], newApp.keys[distrtypes.StoreKey], [][]byte{}}, + {app.keys[banktypes.StoreKey], newApp.keys[banktypes.StoreKey], [][]byte{banktypes.BalancesPrefix}}, + {app.keys[paramtypes.StoreKey], newApp.keys[paramtypes.StoreKey], [][]byte{}}, + {app.keys[govtypes.StoreKey], newApp.keys[govtypes.StoreKey], [][]byte{}}, + {app.keys[evidencetypes.StoreKey], newApp.keys[evidencetypes.StoreKey], [][]byte{}}, + {app.keys[capabilitytypes.StoreKey], newApp.keys[capabilitytypes.StoreKey], [][]byte{}}, + {app.keys[ibchost.StoreKey], newApp.keys[ibchost.StoreKey], [][]byte{}}, + {app.keys[ibctransfertypes.StoreKey], newApp.keys[ibctransfertypes.StoreKey], [][]byte{}}, + } + + for _, skp := range storeKeysPrefixes { + storeA := ctxA.KVStore(skp.A) + storeB := ctxB.KVStore(skp.B) + + failedKVAs, failedKVBs := sdk.DiffKVStores(storeA, storeB, skp.Prefixes) + require.Equal(t, len(failedKVAs), len(failedKVBs), "unequal sets of key-values to compare") + + fmt.Printf("compared %d different key/value pairs between %s and %s\n", len(failedKVAs), skp.A, skp.B) + require.Equal(t, len(failedKVAs), 0, simapp.GetSimulationLog(skp.A.Name(), app.SimulationManager().StoreDecoders, failedKVAs, failedKVBs)) + } +} + +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") + + defer func() { + db.Close() + require.NoError(t, os.RemoveAll(dir)) + }() + + app := NewEthermintApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, simapp.FlagPeriodValue, MakeEncodingConfig(), simapp.EmptyAppOptions{}, fauxMerkleModeOpt) + require.Equal(t, appName, app.Name()) + + // Run randomized simulation + stopEarly, simParams, simErr := simulation.SimulateFromSeed( + t, + os.Stdout, + app.BaseApp, + simapp.AppStateFn(app.AppCodec(), app.SimulationManager()), + simtypes.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 := NewEthermintApp(log.NewNopLogger(), newDB, nil, true, map[int64]bool{}, DefaultNodeHome, simapp.FlagPeriodValue, MakeEncodingConfig(), simapp.EmptyAppOptions{}, fauxMerkleModeOpt) + require.Equal(t, appName, newApp.Name()) + + newApp.InitChain(abci.RequestInitChain{ + AppStateBytes: exported.AppState, + }) + + _, _, err = simulation.SimulateFromSeed( + t, + os.Stdout, + newApp.BaseApp, + simapp.AppStateFn(app.AppCodec(), app.SimulationManager()), + simtypes.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) +} + +// TODO: Make another test for the fuzzer itself, which just has noOp txs +// and doesn't depend on the application. +func TestAppStateDeterminism(t *testing.T) { + if !simapp.FlagEnabledValue { + t.Skip("skipping application simulation") + } + + config := simapp.NewConfigFromFlags() + config.InitialBlockHeight = 1 + config.ExportParamsPath = "" + config.OnOperation = false + config.AllInvariants = false + config.ChainID = SimAppChainID + + numSeeds := 3 + numTimesToRunPerSeed := 5 + appHashList := make([]json.RawMessage, numTimesToRunPerSeed) + + for i := 0; i < numSeeds; i++ { + config.Seed = rand.Int63() + + for j := 0; j < numTimesToRunPerSeed; j++ { + var logger log.Logger + if simapp.FlagVerboseValue { + logger = log.TestingLogger() + } else { + logger = log.NewNopLogger() + } + + db := dbm.NewMemDB() + app := NewEthermintApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, simapp.FlagPeriodValue, MakeEncodingConfig(), simapp.EmptyAppOptions{}, interBlockCacheOpt()) + + fmt.Printf( + "running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n", + config.Seed, i+1, numSeeds, j+1, numTimesToRunPerSeed, + ) + + _, _, err := simulation.SimulateFromSeed( + t, + os.Stdout, + app.BaseApp, + simapp.AppStateFn(app.AppCodec(), app.SimulationManager()), + simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1 + simapp.SimulationOperations(app, app.AppCodec(), config), + app.ModuleAccountAddrs(), + config, + app.AppCodec(), + ) + require.NoError(t, err) + + if config.Commit { + simapp.PrintStats(db) + } + + appHash := app.LastCommitID().Hash + appHashList[j] = appHash + + if j != 0 { + require.Equal( + t, string(appHashList[0]), string(appHashList[j]), + "non-determinism in seed %d: %d/%d, attempt: %d/%d\n", config.Seed, i+1, numSeeds, j+1, numTimesToRunPerSeed, + ) + } + } + } +} diff --git a/cmd/ethermintd/root.go b/cmd/ethermintd/root.go index b87fb55371..41a54df4db 100644 --- a/cmd/ethermintd/root.go +++ b/cmd/ethermintd/root.go @@ -67,9 +67,12 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) { cmd.SetOut(cmd.OutOrStdout()) cmd.SetErr(cmd.ErrOrStderr()) - initClientCtx = client.ReadHomeFlag(initClientCtx, cmd) + initClientCtx, err := client.ReadPersistentCommandFlags(initClientCtx, cmd.Flags()) + if err != nil { + return err + } - initClientCtx, err := config.ReadFromClientConfig(initClientCtx) + initClientCtx, err = config.ReadFromClientConfig(initClientCtx) if err != nil { return err } @@ -78,6 +81,7 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) { return err } + // FIXME: replace AttoPhoton with bond denom customAppTemplate, customAppConfig := servercfg.AppConfig(ethermint.AttoPhoton) return sdkserver.InterceptConfigsPreRunHandler(cmd, customAppTemplate, customAppConfig) diff --git a/go.mod b/go.mod index e52cbedc28..efe402965c 100644 --- a/go.mod +++ b/go.mod @@ -5,9 +5,9 @@ go 1.17 require ( github.com/btcsuite/btcd v0.22.0-beta github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce - github.com/cosmos/cosmos-sdk v0.44.1 + github.com/cosmos/cosmos-sdk v0.44.3 github.com/cosmos/go-bip39 v1.0.0 - github.com/cosmos/ibc-go v1.2.1 + github.com/cosmos/ibc-go v1.2.2 github.com/ethereum/go-ethereum v1.10.3 github.com/gogo/protobuf v1.3.3 github.com/golang/protobuf v1.5.2 @@ -27,7 +27,7 @@ require ( github.com/spf13/viper v1.9.0 github.com/status-im/keycard-go v0.0.0-20200402102358-957c09536969 github.com/stretchr/testify v1.7.0 - github.com/tendermint/tendermint v0.34.13 + github.com/tendermint/tendermint v0.34.14 github.com/tendermint/tm-db v0.6.4 github.com/tyler-smith/go-bip39 v1.1.0 go.etcd.io/bbolt v1.3.6 // indirect @@ -98,6 +98,7 @@ require ( github.com/jmhodges/levigo v1.0.0 // indirect github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d // indirect github.com/klauspost/compress v1.11.9 // indirect + github.com/lib/pq v1.10.2 // indirect github.com/libp2p/go-buffer-pool v0.0.2 // indirect github.com/magiconair/properties v1.8.5 // indirect github.com/mattn/go-isatty v0.0.14 // indirect diff --git a/go.sum b/go.sum index 60580a0880..649395ac7e 100644 --- a/go.sum +++ b/go.sum @@ -252,15 +252,16 @@ github.com/coreos/go-systemd v0.0.0-20190620071333-e64a0ec8b42a/go.mod h1:F5haX7 github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= -github.com/cosmos/cosmos-sdk v0.44.1 h1:UspmTMwKNGf6mH8k388v2T5csP9BYpPJkbQ/eG30PtM= -github.com/cosmos/cosmos-sdk v0.44.1/go.mod h1:fwQJdw+aECatpTvQTo1tSfHEsxACdZYU80QCZUPnHr4= +github.com/cosmos/cosmos-sdk v0.44.2/go.mod h1:fwQJdw+aECatpTvQTo1tSfHEsxACdZYU80QCZUPnHr4= +github.com/cosmos/cosmos-sdk v0.44.3 h1:F71n1jCqPi4F0wXg8AU4AUdUF8llw0x3D3o6aLt/j2A= +github.com/cosmos/cosmos-sdk v0.44.3/go.mod h1:bA3+VenaR/l/vDiYzaiwbWvRPWHMBX2jG0ygiFtiBp0= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw= github.com/cosmos/iavl v0.17.1 h1:b/Cl8h1PRMvsu24+TYNlKchIu7W6tmxIBGe6E9u2Ybw= github.com/cosmos/iavl v0.17.1/go.mod h1:7aisPZK8yCpQdy3PMvKeO+bhq1NwDjUwjzxwwROUxFk= -github.com/cosmos/ibc-go v1.2.1 h1:eWi8EzcgSwVipvhyQ7Rh1KfBe66C1ZdDSskeKMtIg0Q= -github.com/cosmos/ibc-go v1.2.1/go.mod h1:YieSs25Y0TSFR67qg6Elge34yJNEOjYhYB+HNQQLoSQ= +github.com/cosmos/ibc-go v1.2.2 h1:bs6TZ8Es1kycIu2AHlRZ9dzJ+mveqlLN/0sjWtRH88o= +github.com/cosmos/ibc-go v1.2.2/go.mod h1:XmYjsRFOs6Q9Cz+CSsX21icNoH27vQKb3squgnCOCbs= github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76 h1:DdzS1m6o/pCqeZ8VOAit/gyATedRgjvkVI+UCrLpyuU= github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76/go.mod h1:0mkLWIoZuQ7uBoospo5Q9zIpqq6rYCPJDSUdeCJvPM8= github.com/cosmos/ledger-cosmos-go v0.11.1 h1:9JIYsGnXP613pb2vPjFeMMjBI5lEDsEaF6oYorTy6J4= @@ -1171,8 +1172,9 @@ github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15 h1:hqAk8riJvK4RM github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15/go.mod h1:z4YtwM70uOnk8h0pjJYlj3zdYwi9l03By6iAIF5j/Pk= github.com/tendermint/go-amino v0.16.0 h1:GyhmgQKvqF82e2oZeuMSp9JTN0N09emoSZlb2lyGa2E= github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME= -github.com/tendermint/tendermint v0.34.13 h1:fu+tsHudbOr5PvepjH0q47Jae59hQAvn3IqAHv2EbC8= github.com/tendermint/tendermint v0.34.13/go.mod h1:6RVVRBqwtKhA+H59APKumO+B7Nye4QXSFc6+TYxAxCI= +github.com/tendermint/tendermint v0.34.14 h1:GCXmlS8Bqd2Ix3TQCpwYLUNHe+Y+QyJsm5YE+S/FkPo= +github.com/tendermint/tendermint v0.34.14/go.mod h1:FrwVm3TvsVicI9Z7FlucHV6Znfd5KBc/Lpp69cCwtk0= github.com/tendermint/tm-db v0.6.4 h1:3N2jlnYQkXNQclQwd/eKV/NzlqPlfK21cpRRIx80XXQ= github.com/tendermint/tm-db v0.6.4/go.mod h1:dptYhIpJ2M5kUuenLr+Yyf3zQOv1SgBZcl8/BmWlMBw= github.com/tetafro/godot v1.4.9/go.mod h1:LR3CJpxDVGlYOWn3ZZg1PgNZdTUvzsZWu8xaEohUpn8= diff --git a/rpc/ethereum/namespaces/debug/api.go b/rpc/ethereum/namespaces/debug/api.go index d68461612f..f08d40b9a9 100644 --- a/rpc/ethereum/namespaces/debug/api.go +++ b/rpc/ethereum/namespaces/debug/api.go @@ -292,7 +292,12 @@ func (a *API) StartCPUProfile(file string) error { a.logger.Debug("CPU profiling already in progress") return errors.New("CPU profiling already in progress") default: - f, err := os.Create(ExpandHome(file)) + fp, err := ExpandHome(file) + if err != nil { + a.logger.Debug("failed to get filepath for the CPU profile file", "error", err.Error()) + return err + } + f, err := os.Create(fp) if err != nil { a.logger.Debug("failed to create CPU profile file", "error", err.Error()) return err diff --git a/rpc/ethereum/namespaces/debug/trace.go b/rpc/ethereum/namespaces/debug/trace.go index 423d808516..f550d3d283 100644 --- a/rpc/ethereum/namespaces/debug/trace.go +++ b/rpc/ethereum/namespaces/debug/trace.go @@ -35,7 +35,12 @@ func (a *API) StartGoTrace(file string) error { a.logger.Debug("trace already in progress") return errors.New("trace already in progress") } - f, err := os.Create(ExpandHome(file)) + fp, err := ExpandHome(file) + if err != nil { + a.logger.Debug("failed to get filepath for the CPU profile file", "error", err.Error()) + return err + } + f, err := os.Create(fp) if err != nil { a.logger.Debug("failed to create go trace file", "error", err.Error()) return err diff --git a/rpc/ethereum/namespaces/debug/utils.go b/rpc/ethereum/namespaces/debug/utils.go index ebc53df786..b8a2a40f7e 100644 --- a/rpc/ethereum/namespaces/debug/utils.go +++ b/rpc/ethereum/namespaces/debug/utils.go @@ -24,30 +24,35 @@ func isCPUProfileConfigurationActivated(ctx *server.Context) bool { // ExpandHome expands home directory in file paths. // ~someuser/tmp will not be expanded. -func ExpandHome(p string) string { +func ExpandHome(p string) (string, error) { if strings.HasPrefix(p, "~/") || strings.HasPrefix(p, "~\\") { - home := os.Getenv("HOME") - if home == "" { - if usr, err := user.Current(); err == nil { - home = usr.HomeDir - } - } - if home != "" { - p = home + p[1:] + usr, err := user.Current() + if err != nil { + return p, err } + home := usr.HomeDir + p = home + p[1:] } - return filepath.Clean(p) + return filepath.Clean(p), nil } // writeProfile writes the data to a file func writeProfile(name, file string, log log.Logger) error { p := pprof.Lookup(name) log.Info("Writing profile records", "count", p.Count(), "type", name, "dump", file) - f, err := os.Create(ExpandHome(file)) + fp, err := ExpandHome(file) + if err != nil { + return err + } + f, err := os.Create(fp) if err != nil { return err } - defer f.Close() - return p.WriteTo(f, 0) + if err := p.WriteTo(f, 0); err != nil { + f.Close() + return err + } + + return f.Close() } diff --git a/server/start.go b/server/start.go index 8b74452005..7a90c76361 100644 --- a/server/start.go +++ b/server/start.go @@ -223,7 +223,12 @@ func startInProcess(ctx *server.Context, clientCtx client.Context, appCreator ty var cpuProfileCleanup func() if cpuProfile := ctx.Viper.GetString(srvflags.CPUProfile); cpuProfile != "" { - f, err := os.Create(ethdebug.ExpandHome(cpuProfile)) + fp, err := ethdebug.ExpandHome(cpuProfile) + if err != nil { + ctx.Logger.Debug("failed to get filepath for the CPU profile file", "error", err.Error()) + return err + } + f, err := os.Create(fp) if err != nil { return err } diff --git a/x/evm/keeper/state_transition_test.go b/x/evm/keeper/state_transition_test.go index cefd96c42d..258d9dbd7d 100644 --- a/x/evm/keeper/state_transition_test.go +++ b/x/evm/keeper/state_transition_test.go @@ -147,7 +147,7 @@ func (suite *KeeperTestSuite) TestGetCoinbaseAddress() { header.ProposerAddress = valConsAddr.Bytes() suite.ctx = suite.ctx.WithBlockHeader(header) - validator, found := suite.app.StakingKeeper.GetValidatorByConsAddr(suite.ctx, valConsAddr.Bytes()) + _, found := suite.app.StakingKeeper.GetValidatorByConsAddr(suite.ctx, valConsAddr.Bytes()) suite.Require().True(found) suite.app.EvmKeeper.WithContext(suite.ctx)