Merge PR #4182: Cherry pick #4083 into v0.34.2

This commit is contained in:
Alexander Bezobchuk 2019-04-24 11:51:49 -04:00 committed by Jack Zampolin
parent 18b973e1a0
commit c0e6b38394
16 changed files with 47 additions and 29 deletions

View File

@ -1,5 +1,14 @@
# Changelog # Changelog
## 0.34.2
### Improvements
#### SDK
* [\#4053](https://github.com/cosmos/cosmos-sdk/issues/4053) Add `--inv-check-period`
flag to gaiad to set period at which invariants checks will run.
## 0.34.1 ## 0.34.1
### Bug Fixes ### Bug Fixes

View File

@ -9,7 +9,7 @@ import (
"github.com/tendermint/tendermint/libs/cli" "github.com/tendermint/tendermint/libs/cli"
"github.com/pelletier/go-toml" toml "github.com/pelletier/go-toml"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"
) )

View File

@ -221,7 +221,7 @@ func InitializeTestLCD(t *testing.T, nValidators int, initAddrs []sdk.AccAddress
privVal.Reset() privVal.Reset()
db := dbm.NewMemDB() db := dbm.NewMemDB()
app := gapp.NewGaiaApp(logger, db, nil, true, false) app := gapp.NewGaiaApp(logger, db, nil, true, 0)
cdc = gapp.MakeCodec() cdc = gapp.MakeCodec()
genesisFile := config.GenesisFile() genesisFile := config.GenesisFile()

View File

@ -1,7 +1,7 @@
package rpc package rpc
import ( import (
"github.com/tendermint/go-amino" amino "github.com/tendermint/go-amino"
ctypes "github.com/tendermint/tendermint/rpc/core/types" ctypes "github.com/tendermint/tendermint/rpc/core/types"
) )

View File

@ -42,7 +42,7 @@ type GaiaApp struct {
*bam.BaseApp *bam.BaseApp
cdc *codec.Codec cdc *codec.Codec
assertInvariantsBlockly bool invCheckPeriod uint
// keys to access the substores // keys to access the substores
keyMain *sdk.KVStoreKey keyMain *sdk.KVStoreKey
@ -72,7 +72,8 @@ type GaiaApp struct {
} }
// NewGaiaApp returns a reference to an initialized GaiaApp. // 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 { baseAppOptions ...func(*bam.BaseApp)) *GaiaApp {
cdc := MakeCodec() cdc := MakeCodec()
@ -83,6 +84,7 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest,
var app = &GaiaApp{ var app = &GaiaApp{
BaseApp: bApp, BaseApp: bApp,
cdc: cdc, cdc: cdc,
invCheckPeriod: invCheckPeriod,
keyMain: sdk.NewKVStoreKey(bam.MainStoreKey), keyMain: sdk.NewKVStoreKey(bam.MainStoreKey),
keyAccount: sdk.NewKVStoreKey(auth.StoreKey), keyAccount: sdk.NewKVStoreKey(auth.StoreKey),
keyStaking: sdk.NewKVStoreKey(staking.StoreKey), keyStaking: sdk.NewKVStoreKey(staking.StoreKey),
@ -244,7 +246,7 @@ func (app *GaiaApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.R
validatorUpdates, endBlockerTags := staking.EndBlocker(ctx, app.stakingKeeper) validatorUpdates, endBlockerTags := staking.EndBlocker(ctx, app.stakingKeeper)
tags = append(tags, endBlockerTags...) tags = append(tags, endBlockerTags...)
if app.assertInvariantsBlockly { if app.invCheckPeriod != 0 && ctx.BlockHeight()%int64(app.invCheckPeriod) == 0 {
app.assertRuntimeInvariants() app.assertRuntimeInvariants()
} }

View File

@ -55,11 +55,11 @@ func setGenesis(gapp *GaiaApp, accs ...*auth.BaseAccount) error {
func TestGaiadExport(t *testing.T) { func TestGaiadExport(t *testing.T) {
db := db.NewMemDB() 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) setGenesis(gapp)
// Making a new app object with the db, so that initchain hasn't been called // 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{}) _, _, err := newGapp.ExportAppStateAndValidators(false, []string{})
require.NoError(t, err, "ExportAppStateAndValidators should not have an error") require.NoError(t, err, "ExportAppStateAndValidators should not have an error")
} }

View File

@ -26,5 +26,6 @@ func (app *GaiaApp) assertRuntimeInvariantsOnContext(ctx sdk.Context) {
} }
end := time.Now() end := time.Now()
diff := end.Sub(start) 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())
} }

View File

@ -319,7 +319,7 @@ func BenchmarkFullGaiaSimulation(b *testing.B) {
db.Close() db.Close()
os.RemoveAll(dir) os.RemoveAll(dir)
}() }()
app := NewGaiaApp(logger, db, nil, true, false) app := NewGaiaApp(logger, db, nil, true, 0)
// Run randomized simulation // Run randomized simulation
// TODO parameterize numbers, save for a later PR // TODO parameterize numbers, save for a later PR
@ -354,7 +354,7 @@ func TestFullGaiaSimulation(t *testing.T) {
db.Close() db.Close()
os.RemoveAll(dir) 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()) require.Equal(t, "GaiaApp", app.Name())
// Run randomized simulation // Run randomized simulation
@ -388,7 +388,7 @@ func TestGaiaImportExport(t *testing.T) {
db.Close() db.Close()
os.RemoveAll(dir) 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()) require.Equal(t, "GaiaApp", app.Name())
// Run randomized simulation // Run randomized simulation
@ -415,7 +415,7 @@ func TestGaiaImportExport(t *testing.T) {
newDB.Close() newDB.Close()
os.RemoveAll(newDir) 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()) require.Equal(t, "GaiaApp", newApp.Name())
var genesisState GenesisState var genesisState GenesisState
err = app.cdc.UnmarshalJSON(appState, &genesisState) err = app.cdc.UnmarshalJSON(appState, &genesisState)
@ -478,7 +478,7 @@ func TestGaiaSimulationAfterImport(t *testing.T) {
db.Close() db.Close()
os.RemoveAll(dir) 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()) require.Equal(t, "GaiaApp", app.Name())
// Run randomized simulation // Run randomized simulation
@ -514,7 +514,7 @@ func TestGaiaSimulationAfterImport(t *testing.T) {
newDB.Close() newDB.Close()
os.RemoveAll(newDir) 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()) require.Equal(t, "GaiaApp", newApp.Name())
newApp.InitChain(abci.RequestInitChain{ newApp.InitChain(abci.RequestInitChain{
AppStateBytes: appState, AppStateBytes: appState,
@ -542,7 +542,7 @@ func TestAppStateDeterminism(t *testing.T) {
for j := 0; j < numTimesToRunPerSeed; j++ { for j := 0; j < numTimesToRunPerSeed; j++ {
logger := log.NewNopLogger() logger := log.NewNopLogger()
db := dbm.NewMemDB() db := dbm.NewMemDB()
app := NewGaiaApp(logger, db, nil, true, false) app := NewGaiaApp(logger, db, nil, true, 0)
// Run randomized simulation // Run randomized simulation
simulation.SimulateFromSeed( simulation.SimulateFromSeed(

View File

@ -12,7 +12,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"
"github.com/tendermint/go-amino" amino "github.com/tendermint/go-amino"
"github.com/tendermint/tendermint/libs/cli" "github.com/tendermint/tendermint/libs/cli"
"github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client"

View File

@ -23,9 +23,9 @@ import (
) )
// gaiad custom flags // gaiad custom flags
const flagAssertInvariantsBlockly = "assert-invariants-blockly" const flagInvCheckPeriod = "inv-check-period"
var assertInvariantsBlockly bool var invCheckPeriod uint
func main() { func main() {
cdc := app.MakeCodec() cdc := app.MakeCodec()
@ -43,6 +43,7 @@ func main() {
Short: "Gaia Daemon (server)", Short: "Gaia Daemon (server)",
PersistentPreRunE: server.PersistentPreRunEFn(ctx), PersistentPreRunE: server.PersistentPreRunEFn(ctx),
} }
rootCmd.AddCommand(gaiaInit.InitCmd(ctx, cdc)) rootCmd.AddCommand(gaiaInit.InitCmd(ctx, cdc))
rootCmd.AddCommand(gaiaInit.CollectGenTxsCmd(ctx, cdc)) rootCmd.AddCommand(gaiaInit.CollectGenTxsCmd(ctx, cdc))
rootCmd.AddCommand(gaiaInit.TestnetFilesCmd(ctx, cdc)) rootCmd.AddCommand(gaiaInit.TestnetFilesCmd(ctx, cdc))
@ -55,8 +56,8 @@ func main() {
// prepare and add flags // prepare and add flags
executor := cli.PrepareBaseCmd(rootCmd, "GA", app.DefaultNodeHome) executor := cli.PrepareBaseCmd(rootCmd, "GA", app.DefaultNodeHome)
rootCmd.PersistentFlags().BoolVar(&assertInvariantsBlockly, flagAssertInvariantsBlockly, rootCmd.PersistentFlags().UintVar(&invCheckPeriod, flagInvCheckPeriod,
false, "Assert registered invariants on a blockly basis") 1, "Assert registered invariants every N blocks")
err := executor.Execute() err := executor.Execute()
if err != nil { if err != nil {
// handle with #870 // handle with #870
@ -66,7 +67,7 @@ func main() {
func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer) abci.Application { func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer) abci.Application {
return app.NewGaiaApp( return app.NewGaiaApp(
logger, db, traceStore, true, assertInvariantsBlockly, logger, db, traceStore, true, invCheckPeriod,
baseapp.SetPruning(store.NewPruningOptionsFromString(viper.GetString("pruning"))), baseapp.SetPruning(store.NewPruningOptionsFromString(viper.GetString("pruning"))),
baseapp.SetMinGasPrices(viper.GetString(server.FlagMinGasPrices)), baseapp.SetMinGasPrices(viper.GetString(server.FlagMinGasPrices)),
) )
@ -77,13 +78,13 @@ func exportAppStateAndTMValidators(
) (json.RawMessage, []tmtypes.GenesisValidator, error) { ) (json.RawMessage, []tmtypes.GenesisValidator, error) {
if height != -1 { if height != -1 {
gApp := app.NewGaiaApp(logger, db, traceStore, false, false) gApp := app.NewGaiaApp(logger, db, traceStore, false, uint(1))
err := gApp.LoadHeight(height) err := gApp.LoadHeight(height)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
return gApp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList) 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) return gApp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList)
} }

View File

@ -107,7 +107,7 @@ func run(rootDir string) {
// Application // Application
fmt.Println("Creating application") fmt.Println("Creating application")
myapp := app.NewGaiaApp( myapp := app.NewGaiaApp(
ctx.Logger, appDB, traceStoreWriter, true, true, ctx.Logger, appDB, traceStoreWriter, true, uint(1),
baseapp.SetPruning(store.PruneEverything), // nothing baseapp.SetPruning(store.PruneEverything), // nothing
) )

View File

@ -1,8 +1,8 @@
package crypto package crypto
import ( import (
"github.com/tendermint/go-amino" amino "github.com/tendermint/go-amino"
"github.com/tendermint/tendermint/crypto/encoding/amino" cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
) )
var cdc = amino.NewCodec() var cdc = amino.NewCodec()

View File

@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/require" "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"
"github.com/tendermint/tendermint/crypto/secp256k1" "github.com/tendermint/tendermint/crypto/secp256k1"

View File

@ -5,7 +5,7 @@ import (
"fmt" "fmt"
"testing" "testing"
"github.com/cosmos/go-bip39" bip39 "github.com/cosmos/go-bip39"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )

View File

@ -248,6 +248,10 @@ func (bldr TxBuilder) BuildTxForSim(msgs []sdk.Msg) ([]byte, error) {
// SignStdTx appends a signature to a StdTx and returns a copy of it. If append // SignStdTx appends a signature to a StdTx and returns a copy of it. If append
// is false, it replaces the signatures already attached with the new signature. // is false, it replaces the signatures already attached with the new signature.
func (bldr TxBuilder) SignStdTx(name, passphrase string, stdTx auth.StdTx, appendSig bool) (signedStdTx auth.StdTx, err error) { func (bldr TxBuilder) SignStdTx(name, passphrase string, stdTx auth.StdTx, appendSig bool) (signedStdTx auth.StdTx, err error) {
if bldr.chainID == "" {
return auth.StdTx{}, fmt.Errorf("chain ID required but not specified")
}
stdSignature, err := MakeSignature(bldr.keybase, name, passphrase, StdSignMsg{ stdSignature, err := MakeSignature(bldr.keybase, name, passphrase, StdSignMsg{
ChainID: bldr.chainID, ChainID: bldr.chainID,
AccountNumber: bldr.accountNumber, AccountNumber: bldr.accountNumber,

View File

@ -4,6 +4,7 @@ import (
"github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/x/mint" "github.com/cosmos/cosmos-sdk/x/mint"
"github.com/cosmos/cosmos-sdk/x/mint/client/cli" "github.com/cosmos/cosmos-sdk/x/mint/client/cli"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/tendermint/go-amino" "github.com/tendermint/go-amino"
) )