Skip to content

Commit

Permalink
Replace gaiad's --assert-invariants-blockly with --inv-check-freq.
Browse files Browse the repository at this point in the history
Closes: #4053
  • Loading branch information
alessio committed Apr 10, 2019
1 parent eb94252 commit 189e3d8
Show file tree
Hide file tree
Showing 17 changed files with 36 additions and 31 deletions.
1 change: 1 addition & 0 deletions .pending/breaking/gaia/4053-Add-inv-che
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#4053 Add --inv-check-period flag to gaiad to set period at which invariants checks will run.
2 changes: 1 addition & 1 deletion client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
2 changes: 1 addition & 1 deletion client/keys/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion client/lcd/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion client/rpc/codec.go
Original file line number Diff line number Diff line change
@@ -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"
)

Expand Down
8 changes: 5 additions & 3 deletions cmd/gaia/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type GaiaApp struct {
*bam.BaseApp
cdc *codec.Codec

assertInvariantsBlockly bool
invCheckPeriod uint

// keys to access the substores
keyMain *sdk.KVStoreKey
Expand Down Expand Up @@ -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()
Expand All @@ -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),
Expand Down Expand Up @@ -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()
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/gaia/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
3 changes: 2 additions & 1 deletion cmd/gaia/app/invariants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
14 changes: 7 additions & 7 deletions cmd/gaia/app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion cmd/gaia/cmd/gaiacli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 8 additions & 7 deletions cmd/gaia/cmd/gaiad/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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))
Expand All @@ -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
Expand All @@ -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)),
)
Expand All @@ -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)
}
2 changes: 1 addition & 1 deletion cmd/gaia/cmd/gaiareplay/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
2 changes: 1 addition & 1 deletion crypto/amino.go
Original file line number Diff line number Diff line change
@@ -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"
)

Expand Down
2 changes: 1 addition & 1 deletion crypto/keys/hd/fundraiser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion crypto/keys/hd/hdpath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
2 changes: 1 addition & 1 deletion x/auth/client/txbuilder/txbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion x/mint/client/module_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 189e3d8

Please sign in to comment.