From 189e3d8af17a7c0a6b8393a34d5a83fe0a26cbce Mon Sep 17 00:00:00 2001 From: Alessio Treglia Date: Wed, 10 Apr 2019 03:49:31 +0100 Subject: [PATCH] Replace gaiad's --assert-invariants-blockly with --inv-check-freq. Closes: #4053 --- .pending/breaking/gaia/4053-Add-inv-che | 1 + client/config.go | 2 +- client/keys/add.go | 2 +- client/lcd/test_helpers.go | 2 +- client/rpc/codec.go | 2 +- cmd/gaia/app/app.go | 8 +++++--- cmd/gaia/app/app_test.go | 4 ++-- cmd/gaia/app/invariants.go | 3 ++- cmd/gaia/app/sim_test.go | 14 +++++++------- cmd/gaia/cmd/gaiacli/main.go | 2 +- cmd/gaia/cmd/gaiad/main.go | 15 ++++++++------- cmd/gaia/cmd/gaiareplay/main.go | 2 +- crypto/amino.go | 2 +- crypto/keys/hd/fundraiser_test.go | 2 +- crypto/keys/hd/hdpath_test.go | 2 +- x/auth/client/txbuilder/txbuilder.go | 2 +- x/mint/client/module_client.go | 2 +- 17 files changed, 36 insertions(+), 31 deletions(-) create mode 100644 .pending/breaking/gaia/4053-Add-inv-che diff --git a/.pending/breaking/gaia/4053-Add-inv-che b/.pending/breaking/gaia/4053-Add-inv-che new file mode 100644 index 000000000000..515d05ade902 --- /dev/null +++ b/.pending/breaking/gaia/4053-Add-inv-che @@ -0,0 +1 @@ +#4053 Add --inv-check-period flag to gaiad to set period at which invariants checks will run. diff --git a/client/config.go b/client/config.go index c49a6f9de30c..4946a96ea8ab 100644 --- a/client/config.go +++ b/client/config.go @@ -9,7 +9,7 @@ import ( "github.com/tendermint/tendermint/libs/cli" - "github.com/pelletier/go-toml" + toml "github.com/pelletier/go-toml" "github.com/spf13/cobra" "github.com/spf13/viper" ) diff --git a/client/keys/add.go b/client/keys/add.go index 49a275bf6ae1..390b1bc2a7c0 100644 --- a/client/keys/add.go +++ b/client/keys/add.go @@ -15,7 +15,7 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" - "github.com/cosmos/go-bip39" + bip39 "github.com/cosmos/go-bip39" "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/multisig" diff --git a/client/lcd/test_helpers.go b/client/lcd/test_helpers.go index 127e8992a9ea..329b93ff6964 100644 --- a/client/lcd/test_helpers.go +++ b/client/lcd/test_helpers.go @@ -221,7 +221,7 @@ func InitializeTestLCD(t *testing.T, nValidators int, initAddrs []sdk.AccAddress privVal.Reset() db := dbm.NewMemDB() - app := gapp.NewGaiaApp(logger, db, nil, true, false) + app := gapp.NewGaiaApp(logger, db, nil, true, 0) cdc = gapp.MakeCodec() genesisFile := config.GenesisFile() diff --git a/client/rpc/codec.go b/client/rpc/codec.go index 1a64ee4aee58..841366fef16b 100644 --- a/client/rpc/codec.go +++ b/client/rpc/codec.go @@ -1,7 +1,7 @@ package rpc import ( - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" ctypes "github.com/tendermint/tendermint/rpc/core/types" ) diff --git a/cmd/gaia/app/app.go b/cmd/gaia/app/app.go index a856094728a7..26d920d5ea8e 100644 --- a/cmd/gaia/app/app.go +++ b/cmd/gaia/app/app.go @@ -40,7 +40,7 @@ type GaiaApp struct { *bam.BaseApp cdc *codec.Codec - assertInvariantsBlockly bool + invCheckPeriod uint // keys to access the substores keyMain *sdk.KVStoreKey @@ -70,7 +70,8 @@ type GaiaApp struct { } // NewGaiaApp returns a reference to an initialized GaiaApp. -func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest, assertInvariantsBlockly bool, +func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool, + invCheckPeriod uint, baseAppOptions ...func(*bam.BaseApp)) *GaiaApp { cdc := MakeCodec() @@ -81,6 +82,7 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest, var app = &GaiaApp{ BaseApp: bApp, cdc: cdc, + invCheckPeriod: invCheckPeriod, keyMain: sdk.NewKVStoreKey(bam.MainStoreKey), keyAccount: sdk.NewKVStoreKey(auth.StoreKey), keyStaking: sdk.NewKVStoreKey(staking.StoreKey), @@ -242,7 +244,7 @@ func (app *GaiaApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.R validatorUpdates, endBlockerTags := staking.EndBlocker(ctx, app.stakingKeeper) tags = append(tags, endBlockerTags...) - if app.assertInvariantsBlockly { + if app.invCheckPeriod != 0 && ctx.BlockHeight()%int64(app.invCheckPeriod) == 0 { app.assertRuntimeInvariants() } diff --git a/cmd/gaia/app/app_test.go b/cmd/gaia/app/app_test.go index ec38f06a671b..95fa02119d68 100644 --- a/cmd/gaia/app/app_test.go +++ b/cmd/gaia/app/app_test.go @@ -55,11 +55,11 @@ func setGenesis(gapp *GaiaApp, accs ...*auth.BaseAccount) error { func TestGaiadExport(t *testing.T) { db := db.NewMemDB() - gapp := NewGaiaApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, false) + gapp := NewGaiaApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, 0) setGenesis(gapp) // Making a new app object with the db, so that initchain hasn't been called - newGapp := NewGaiaApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, false) + newGapp := NewGaiaApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, 0) _, _, err := newGapp.ExportAppStateAndValidators(false, []string{}) require.NoError(t, err, "ExportAppStateAndValidators should not have an error") } diff --git a/cmd/gaia/app/invariants.go b/cmd/gaia/app/invariants.go index 841732ca11e1..899d6bdbac22 100644 --- a/cmd/gaia/app/invariants.go +++ b/cmd/gaia/app/invariants.go @@ -26,5 +26,6 @@ func (app *GaiaApp) assertRuntimeInvariantsOnContext(ctx sdk.Context) { } end := time.Now() diff := end.Sub(start) - app.BaseApp.Logger().With("module", "invariants").Info("Asserted all invariants", "duration", diff) + app.BaseApp.Logger().With("module", "invariants").Info( + "Asserted all invariants", "duration", diff, "height", app.LastBlockHeight()) } diff --git a/cmd/gaia/app/sim_test.go b/cmd/gaia/app/sim_test.go index 7c6a2886de46..da4131fcb166 100644 --- a/cmd/gaia/app/sim_test.go +++ b/cmd/gaia/app/sim_test.go @@ -314,7 +314,7 @@ func BenchmarkFullGaiaSimulation(b *testing.B) { db.Close() os.RemoveAll(dir) }() - app := NewGaiaApp(logger, db, nil, true, false) + app := NewGaiaApp(logger, db, nil, true, 0) // Run randomized simulation // TODO parameterize numbers, save for a later PR @@ -349,7 +349,7 @@ func TestFullGaiaSimulation(t *testing.T) { db.Close() os.RemoveAll(dir) }() - app := NewGaiaApp(logger, db, nil, true, false, fauxMerkleModeOpt) + app := NewGaiaApp(logger, db, nil, true, 0, fauxMerkleModeOpt) require.Equal(t, "GaiaApp", app.Name()) // Run randomized simulation @@ -383,7 +383,7 @@ func TestGaiaImportExport(t *testing.T) { db.Close() os.RemoveAll(dir) }() - app := NewGaiaApp(logger, db, nil, true, false, fauxMerkleModeOpt) + app := NewGaiaApp(logger, db, nil, true, 0, fauxMerkleModeOpt) require.Equal(t, "GaiaApp", app.Name()) // Run randomized simulation @@ -410,7 +410,7 @@ func TestGaiaImportExport(t *testing.T) { newDB.Close() os.RemoveAll(newDir) }() - newApp := NewGaiaApp(log.NewNopLogger(), newDB, nil, true, false, fauxMerkleModeOpt) + newApp := NewGaiaApp(log.NewNopLogger(), newDB, nil, true, 0, fauxMerkleModeOpt) require.Equal(t, "GaiaApp", newApp.Name()) var genesisState GenesisState err = app.cdc.UnmarshalJSON(appState, &genesisState) @@ -473,7 +473,7 @@ func TestGaiaSimulationAfterImport(t *testing.T) { db.Close() os.RemoveAll(dir) }() - app := NewGaiaApp(logger, db, nil, true, false, fauxMerkleModeOpt) + app := NewGaiaApp(logger, db, nil, true, 0, fauxMerkleModeOpt) require.Equal(t, "GaiaApp", app.Name()) // Run randomized simulation @@ -509,7 +509,7 @@ func TestGaiaSimulationAfterImport(t *testing.T) { newDB.Close() os.RemoveAll(newDir) }() - newApp := NewGaiaApp(log.NewNopLogger(), newDB, nil, true, false, fauxMerkleModeOpt) + newApp := NewGaiaApp(log.NewNopLogger(), newDB, nil, true, 0, fauxMerkleModeOpt) require.Equal(t, "GaiaApp", newApp.Name()) newApp.InitChain(abci.RequestInitChain{ AppStateBytes: appState, @@ -537,7 +537,7 @@ func TestAppStateDeterminism(t *testing.T) { for j := 0; j < numTimesToRunPerSeed; j++ { logger := log.NewNopLogger() db := dbm.NewMemDB() - app := NewGaiaApp(logger, db, nil, true, false) + app := NewGaiaApp(logger, db, nil, true, 0) // Run randomized simulation simulation.SimulateFromSeed( diff --git a/cmd/gaia/cmd/gaiacli/main.go b/cmd/gaia/cmd/gaiacli/main.go index b440db8f94c0..4fd6d1c3ad75 100644 --- a/cmd/gaia/cmd/gaiacli/main.go +++ b/cmd/gaia/cmd/gaiacli/main.go @@ -12,7 +12,7 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" "github.com/tendermint/tendermint/libs/cli" "github.com/cosmos/cosmos-sdk/client" diff --git a/cmd/gaia/cmd/gaiad/main.go b/cmd/gaia/cmd/gaiad/main.go index 4aa8e49179f5..58e6cf576170 100644 --- a/cmd/gaia/cmd/gaiad/main.go +++ b/cmd/gaia/cmd/gaiad/main.go @@ -23,9 +23,9 @@ import ( ) // gaiad custom flags -const flagAssertInvariantsBlockly = "assert-invariants-blockly" +const flagInvCheckPeriod = "inv-check-period" -var assertInvariantsBlockly bool +var invCheckPeriod uint func main() { cdc := app.MakeCodec() @@ -43,6 +43,7 @@ func main() { Short: "Gaia Daemon (server)", PersistentPreRunE: server.PersistentPreRunEFn(ctx), } + rootCmd.AddCommand(gaiaInit.InitCmd(ctx, cdc)) rootCmd.AddCommand(gaiaInit.CollectGenTxsCmd(ctx, cdc)) rootCmd.AddCommand(gaiaInit.TestnetFilesCmd(ctx, cdc)) @@ -55,8 +56,8 @@ func main() { // prepare and add flags executor := cli.PrepareBaseCmd(rootCmd, "GA", app.DefaultNodeHome) - rootCmd.Flags().BoolVar(&assertInvariantsBlockly, flagAssertInvariantsBlockly, - false, "Assert registered invariants on a blockly basis") + rootCmd.PersistentFlags().UintVar(&invCheckPeriod, flagInvCheckPeriod, + 1, "Assert registered invariants every N blocks") err := executor.Execute() if err != nil { // handle with #870 @@ -66,7 +67,7 @@ func main() { func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer) abci.Application { return app.NewGaiaApp( - logger, db, traceStore, true, assertInvariantsBlockly, + logger, db, traceStore, true, invCheckPeriod, baseapp.SetPruning(store.NewPruningOptionsFromString(viper.GetString("pruning"))), baseapp.SetMinGasPrices(viper.GetString(server.FlagMinGasPrices)), ) @@ -77,13 +78,13 @@ func exportAppStateAndTMValidators( ) (json.RawMessage, []tmtypes.GenesisValidator, error) { if height != -1 { - gApp := app.NewGaiaApp(logger, db, traceStore, false, false) + gApp := app.NewGaiaApp(logger, db, traceStore, false, uint(1)) err := gApp.LoadHeight(height) if err != nil { return nil, nil, err } return gApp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList) } - gApp := app.NewGaiaApp(logger, db, traceStore, true, false) + gApp := app.NewGaiaApp(logger, db, traceStore, true, uint(1)) return gApp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList) } diff --git a/cmd/gaia/cmd/gaiareplay/main.go b/cmd/gaia/cmd/gaiareplay/main.go index fd2c518a44d1..d41a65c7ebbe 100644 --- a/cmd/gaia/cmd/gaiareplay/main.go +++ b/cmd/gaia/cmd/gaiareplay/main.go @@ -107,7 +107,7 @@ func run(rootDir string) { // Application fmt.Println("Creating application") myapp := app.NewGaiaApp( - ctx.Logger, appDB, traceStoreWriter, true, true, + ctx.Logger, appDB, traceStoreWriter, true, uint(1), baseapp.SetPruning(store.PruneEverything), // nothing ) diff --git a/crypto/amino.go b/crypto/amino.go index 327f8090d932..553a4723f9db 100644 --- a/crypto/amino.go +++ b/crypto/amino.go @@ -1,7 +1,7 @@ package crypto import ( - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino" ) diff --git a/crypto/keys/hd/fundraiser_test.go b/crypto/keys/hd/fundraiser_test.go index 5e3cf06f3f46..6fa4ca725f0d 100644 --- a/crypto/keys/hd/fundraiser_test.go +++ b/crypto/keys/hd/fundraiser_test.go @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/require" - "github.com/cosmos/go-bip39" + bip39 "github.com/cosmos/go-bip39" "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/secp256k1" diff --git a/crypto/keys/hd/hdpath_test.go b/crypto/keys/hd/hdpath_test.go index 275b714ceaf3..509cdb6c2f39 100644 --- a/crypto/keys/hd/hdpath_test.go +++ b/crypto/keys/hd/hdpath_test.go @@ -5,7 +5,7 @@ import ( "fmt" "testing" - "github.com/cosmos/go-bip39" + bip39 "github.com/cosmos/go-bip39" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/x/auth/client/txbuilder/txbuilder.go b/x/auth/client/txbuilder/txbuilder.go index a118dbbae257..fe9225eef01e 100644 --- a/x/auth/client/txbuilder/txbuilder.go +++ b/x/auth/client/txbuilder/txbuilder.go @@ -250,7 +250,7 @@ func (bldr TxBuilder) SignStdTx(name, passphrase string, stdTx auth.StdTx, appen if bldr.chainID == "" { return auth.StdTx{}, fmt.Errorf("chain ID required but not specified") } - + stdSignature, err := MakeSignature(bldr.keybase, name, passphrase, StdSignMsg{ ChainID: bldr.chainID, AccountNumber: bldr.accountNumber, diff --git a/x/mint/client/module_client.go b/x/mint/client/module_client.go index 2a9b1b855cf8..54ccea835105 100644 --- a/x/mint/client/module_client.go +++ b/x/mint/client/module_client.go @@ -2,7 +2,7 @@ package client import ( "github.com/spf13/cobra" - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" sdkclient "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/x/mint"