From 13bd5b62cf87a751a05e43c6f014d2e472d55c88 Mon Sep 17 00:00:00 2001 From: Alexander Bezobchuk Date: Thu, 25 Apr 2019 17:30:24 -0400 Subject: [PATCH 1/2] Release v0.34.2 * Merge PR #4163: Fix v0.33.x export script to port gov data correctly * Remove TOC * Add missing changelog entry for v0.34.1 * Merge PR #4182: Cherry pick #4083 into v0.34.2 * Merge PR #4181: Cherry pick 4135 v0.34.2 * Merge PR #4183: Cherry pick 4181 into v0.34.2 * Support pagination and status query params for /staking/validators * Rename BondStatusToString to String * Cherry pick 4181 * Remove pending log * Fix CODEOWNERS --- .github/CODEOWNERS | 7 +--- CHANGELOG.md | 51 +++++++++++++------------- client/config.go | 2 +- client/context/context.go | 4 +- client/flags.go | 2 +- client/lcd/swagger-ui/swagger.yaml | 18 ++++++++- client/lcd/test_helpers.go | 2 +- client/rpc/codec.go | 2 +- client/tx/query.go | 1 - 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 +- contrib/export/v0.33.x-to-v0.34.0.py | 35 +++++++++++++++++- crypto/amino.go | 4 +- crypto/keys/hd/fundraiser_test.go | 2 +- crypto/keys/hd/hdpath_test.go | 2 +- docs/cosmos-hub/gaiacli.md | 4 ++ types/result.go | 4 ++ types/staking.go | 16 +++++--- x/auth/client/txbuilder/txbuilder.go | 4 ++ x/mint/client/module_client.go | 1 + x/staking/alias.go | 10 +++-- x/staking/client/rest/query.go | 28 +++++++++++++- x/staking/keeper/validator_test.go | 5 +-- x/staking/querier/querier.go | 55 +++++++++++++++++++++++++--- x/staking/querier/querier_test.go | 40 +++++++++++++------- x/staking/types/validator.go | 2 +- 31 files changed, 250 insertions(+), 99 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 11f9e598b42c..3f2a5ac8a5e0 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,9 +1,4 @@ # CODEOWNERS: https://help.github.com/articles/about-codeowners/ # Primary repo maintainers -* @ebuchman @rigelrozanski @cwgoes - -# Precious documentation -/docs/README.md @zramsay -/docs/DOCS_README.md @zramsay -/docs/.vuepress/ @zramsay +* @alessio @alexanderbez @cwgoes @jackzampolin diff --git a/CHANGELOG.md b/CHANGELOG.md index ff1081e7c4bb..097d6b3c91c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,30 +1,31 @@ # Changelog -* [0.34.0](#0340) - * [Breaking Changes](#breaking-changes) - * [Gaia](#gaia) - * [Gaia CLI](#gaia-cli) - * [SDK](#sdk) - * [Tendermint](#tendermint) - * [New features](#new-features) - * [SDK](#sdk-1) - * [Gaia](#gaia-1) - * [Gaia CLI](#gaia-cli-1) - * [Gaia REST API](#gaia-rest-api) - * [Improvements](#improvements) - * [Gaia](#gaia-2) - * [Gaia CLI](#gaia-cli-2) - * [SDK](#sdk-2) - * [Bug Fixes](#bug-fixes) - * [Gaia](#gaia-3) - * [Gaia CLI](#gaia-cli-3) - * [SDK](#sdk-3) -* [0.33.2](#0332) - * [Improvements](#improvements-1) - * [Tendermint](#tendermint-1) -* [0.33.1](#0331) - * [Bug Fixes](#bug-fixes-1) - * [Gaia](#gaia-4) +## 0.34.2 + +### Improvements + +#### SDK + +* [\#4135](https://github.com/cosmos/cosmos-sdk/pull/4135) Add further clarification +to generate only usage. + +### Bug Fixes + +#### SDK + +* [\#4135](https://github.com/cosmos/cosmos-sdk/pull/4135) Fix `NewResponseFormatBroadcastTxCommit` +* [\#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. +* [\#4099](https://github.com/cosmos/cosmos-sdk/issues/4099) Update the /staking/validators endpoint to support +status and pagination query flags. + +## 0.34.1 + +### Bug Fixes + +#### Gaia + +* [#4163](https://github.com/cosmos/cosmos-sdk/pull/4163) Fix v0.33.x export script to port gov data correctly. ## 0.34.0 diff --git a/client/config.go b/client/config.go index d785093a3034..04ec8f80dfb3 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/context/context.go b/client/context/context.go index e9d7e6782c50..ea87533ff4fd 100644 --- a/client/context/context.go +++ b/client/context/context.go @@ -7,6 +7,8 @@ import ( "os" "path/filepath" + "github.com/pkg/errors" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/keys" "github.com/cosmos/cosmos-sdk/codec" @@ -292,7 +294,7 @@ func GetFromFields(from string, genOnly bool) (sdk.AccAddress, string, error) { if genOnly { addr, err := sdk.AccAddressFromBech32(from) if err != nil { - return nil, "", err + return nil, "", errors.Wrap(err, "must provide a valid Bech32 address for generate-only") } return addr, "", nil diff --git a/client/flags.go b/client/flags.go index 77aec7e24e6c..26ff68e82c23 100644 --- a/client/flags.go +++ b/client/flags.go @@ -93,7 +93,7 @@ func PostCommands(cmds ...*cobra.Command) []*cobra.Command { c.Flags().Bool(FlagPrintResponse, true, "return tx response (only works with async = false)") c.Flags().Bool(FlagTrustNode, true, "Trust connected full node (don't verify proofs for responses)") c.Flags().Bool(FlagDryRun, false, "ignore the --gas flag and perform a simulation of a transaction, but don't broadcast it") - c.Flags().Bool(FlagGenerateOnly, false, "build an unsigned transaction and write it to STDOUT") + c.Flags().Bool(FlagGenerateOnly, false, "Build an unsigned transaction and write it to STDOUT (when enabled, the local Keybase is not accessible)") c.Flags().BoolP(FlagSkipConfirmation, "y", false, "Skip tx broadcasting prompt confirmation") // --gas can accept integers and "simulate" diff --git a/client/lcd/swagger-ui/swagger.yaml b/client/lcd/swagger-ui/swagger.yaml index cb479a63f36b..11deeab65600 100644 --- a/client/lcd/swagger-ui/swagger.yaml +++ b/client/lcd/swagger-ui/swagger.yaml @@ -763,7 +763,23 @@ paths: description: Internal Server Error /staking/validators: get: - summary: Get all validator candidates + summary: Get all validator candidates. By default it returns only the bonded validators. + parameters: + - in: query + name: status + type: string + description: The validator bond status. Must be either 'bonded', 'unbonded', or 'unbonding'. + x-example: bonded + - in: query + name: page + description: The gage number. + type: integer + x-example: 1 + - in: query + name: limit + description: The maximum number of items per page. + type: integer + x-example: 1 tags: - ICS21 produces: diff --git a/client/lcd/test_helpers.go b/client/lcd/test_helpers.go index 856efaf95f19..9cd87362cff5 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/client/tx/query.go b/client/tx/query.go index 8bb8e10cd705..3cf290044548 100644 --- a/client/tx/query.go +++ b/client/tx/query.go @@ -162,7 +162,6 @@ func QueryTxsByTagsRequestHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) } tags, page, limit, err = rest.ParseHTTPArgs(r) - if err != nil { rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) return diff --git a/cmd/gaia/app/app.go b/cmd/gaia/app/app.go index 262115649f10..d257627b2965 100644 --- a/cmd/gaia/app/app.go +++ b/cmd/gaia/app/app.go @@ -42,7 +42,7 @@ type GaiaApp struct { *bam.BaseApp cdc *codec.Codec - assertInvariantsBlockly bool + invCheckPeriod uint // keys to access the substores keyMain *sdk.KVStoreKey @@ -72,7 +72,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() @@ -83,6 +84,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), @@ -244,7 +246,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 247cc262a308..80a268ee28d3 100644 --- a/cmd/gaia/app/sim_test.go +++ b/cmd/gaia/app/sim_test.go @@ -319,7 +319,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 @@ -354,7 +354,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 @@ -388,7 +388,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 @@ -415,7 +415,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) @@ -478,7 +478,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 @@ -514,7 +514,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, @@ -542,7 +542,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 b515f5236bfa..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.PersistentFlags().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/contrib/export/v0.33.x-to-v0.34.0.py b/contrib/export/v0.33.x-to-v0.34.0.py index bb7d6520cf8a..fd49e9b697ff 100755 --- a/contrib/export/v0.33.x-to-v0.34.0.py +++ b/contrib/export/v0.33.x-to-v0.34.0.py @@ -15,7 +15,10 @@ def process_raw_genesis(genesis, parsed_args): }, } - # default tm value + # migrate governance state as the internal structure of proposals has changed + migrate_gov_data(genesis['app_state']['gov']) + + # default Tendermint block time (ms) genesis['consensus_params']['block']['time_iota_ms'] = '1000' # proposal #1 updates @@ -36,6 +39,36 @@ def process_raw_genesis(genesis, parsed_args): return genesis +def migrate_gov_data(gov_data): + for p in gov_data['proposals']: + # get Amino type and value + t = p['type'] + v = p['value'] + + del p['type'] + del p['value'] + + assert t == 'gov/TextProposal', 'invalid proposal type: {t}' + assert p == {}, 'expected proposal to be empty after deleting contents' + + p['proposal_content'] = { + 'type': t, + 'value': { + 'title': v['title'], + 'description': v['description'] + } + } + + p['proposal_id'] = v['proposal_id'] + p['proposal_status'] = v['proposal_status'] + p['final_tally_result'] = v['final_tally_result'] + p['submit_time'] = v['submit_time'] + p['deposit_end_time'] = v['deposit_end_time'] + p['total_deposit'] = v['total_deposit'] + p['voting_start_time'] = v['voting_start_time'] + p['voting_end_time'] = v['voting_end_time'] + + if __name__ == '__main__': parser = lib.init_default_argument_parser( prog_desc='Convert genesis.json from v0.33.x to v0.34.0', diff --git a/crypto/amino.go b/crypto/amino.go index 3a12c96815d6..553a4723f9db 100644 --- a/crypto/amino.go +++ b/crypto/amino.go @@ -1,8 +1,8 @@ package crypto import ( - "github.com/tendermint/go-amino" - "github.com/tendermint/tendermint/crypto/encoding/amino" + amino "github.com/tendermint/go-amino" + cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino" ) var cdc = amino.NewCodec() 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/docs/cosmos-hub/gaiacli.md b/docs/cosmos-hub/gaiacli.md index 48756c6c081e..f502554d77be 100644 --- a/docs/cosmos-hub/gaiacli.md +++ b/docs/cosmos-hub/gaiacli.md @@ -256,6 +256,10 @@ gaiacli tx sign \ unsignedSendTx.json > signedSendTx.json ``` +::: tip Note +The `--generate-only` flag prevents `gaiacli` from accessing the local keybase. +::: + You can validate the transaction's signatures by typing the following: ```bash diff --git a/types/result.go b/types/result.go index e83ed56e16d6..7f0590241f65 100644 --- a/types/result.go +++ b/types/result.go @@ -107,6 +107,10 @@ func NewResponseResultTx(res *ctypes.ResultTx, tx Tx, timestamp string) TxRespon // NewResponseFormatBroadcastTxCommit returns a TxResponse given a // ResultBroadcastTxCommit from tendermint. func NewResponseFormatBroadcastTxCommit(res *ctypes.ResultBroadcastTxCommit) TxResponse { + if res == nil { + return TxResponse{} + } + if !res.CheckTx.IsOK() { return newTxResponseCheckTx(res) } diff --git a/types/staking.go b/types/staking.go index 79832ac00ab0..54f28f97279d 100644 --- a/types/staking.go +++ b/types/staking.go @@ -25,19 +25,23 @@ const ( // Constant as this should not change without a hard fork. // TODO: Link to some Tendermint docs, this is very unobvious. ValidatorUpdateDelay int64 = 1 + + BondStatusUnbonded = "Unbonded" + BondStatusUnbonding = "Unbonding" + BondStatusBonded = "Bonded" ) -//BondStatusToString for pretty prints of Bond Status -func BondStatusToString(b BondStatus) string { +// String implements the Stringer interface for BondStatus. +func (b BondStatus) String() string { switch b { case 0x00: - return "Unbonded" + return BondStatusUnbonded case 0x01: - return "Unbonding" + return BondStatusUnbonding case 0x02: - return "Bonded" + return BondStatusBonded default: - panic("improper use of BondStatusToString") + panic("invalid bond status") } } diff --git a/x/auth/client/txbuilder/txbuilder.go b/x/auth/client/txbuilder/txbuilder.go index 480d8fd4168c..034ef86f8d9a 100644 --- a/x/auth/client/txbuilder/txbuilder.go +++ b/x/auth/client/txbuilder/txbuilder.go @@ -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 // 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) { + 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 96f6c00fdf4b..857bb7992665 100644 --- a/x/mint/client/module_client.go +++ b/x/mint/client/module_client.go @@ -4,6 +4,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/x/mint" "github.com/cosmos/cosmos-sdk/x/mint/client/cli" + "github.com/spf13/cobra" "github.com/tendermint/go-amino" ) diff --git a/x/staking/alias.go b/x/staking/alias.go index cee0c7b4c475..d1e48ef79081 100644 --- a/x/staking/alias.go +++ b/x/staking/alias.go @@ -36,6 +36,7 @@ type ( QueryValidatorParams = querier.QueryValidatorParams QueryBondsParams = querier.QueryBondsParams QueryRedelegationParams = querier.QueryRedelegationParams + QueryValidatorsParams = querier.QueryValidatorsParams ) var ( @@ -97,10 +98,11 @@ var ( NewMsgUndelegate = types.NewMsgUndelegate NewMsgBeginRedelegate = types.NewMsgBeginRedelegate - NewQuerier = querier.NewQuerier - NewQueryDelegatorParams = querier.NewQueryDelegatorParams - NewQueryValidatorParams = querier.NewQueryValidatorParams - NewQueryBondsParams = querier.NewQueryBondsParams + NewQuerier = querier.NewQuerier + NewQueryDelegatorParams = querier.NewQueryDelegatorParams + NewQueryValidatorParams = querier.NewQueryValidatorParams + NewQueryBondsParams = querier.NewQueryBondsParams + NewQueryValidatorsParams = querier.NewQueryValidatorsParams ) const ( diff --git a/x/staking/client/rest/query.go b/x/staking/client/rest/query.go index 63fcc6d24b92..a9439bd803ae 100644 --- a/x/staking/client/rest/query.go +++ b/x/staking/client/rest/query.go @@ -1,6 +1,7 @@ package rest import ( + "fmt" "net/http" "strings" @@ -15,7 +16,6 @@ import ( ) func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) { - // Get all delegations from a delegator r.HandleFunc( "/staking/delegators/{delegatorAddr}/delegations", @@ -249,7 +249,31 @@ func delegatorValidatorHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) ht // HTTP request handler to query list of validators func validatorsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - res, err := cliCtx.QueryWithData("custom/staking/validators", nil) + _, page, limit, err := rest.ParseHTTPArgs(r) + if err != nil { + rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) + return + } + + // override default limit if it wasn't provided + if l := r.FormValue("limit"); l == "" { + limit = 0 + } + + status := r.FormValue("status") + if status == "" { + status = sdk.BondStatusBonded + } + + params := staking.NewQueryValidatorsParams(page, limit, status) + bz, err := cdc.MarshalJSON(params) + if err != nil { + rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) + return + } + + route := fmt.Sprintf("custom/%s/%s", staking.QuerierRoute, staking.QueryValidators) + res, err := cliCtx.QueryWithData(route, bz) if err != nil { rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return diff --git a/x/staking/keeper/validator_test.go b/x/staking/keeper/validator_test.go index d2aa5b270bea..d359d637c682 100644 --- a/x/staking/keeper/validator_test.go +++ b/x/staking/keeper/validator_test.go @@ -162,9 +162,8 @@ func TestUpdateBondedValidatorsDecreaseCliff(t *testing.T) { assert.Equal( t, status, val.GetStatus(), - fmt.Sprintf("expected validator at index %v to have status: %s", - valIdx, - sdk.BondStatusToString(status))) + fmt.Sprintf("expected validator at index %v to have status: %s", valIdx, status), + ) } } diff --git a/x/staking/querier/querier.go b/x/staking/querier/querier.go index 4230dc6a43bc..8694a35b9ca2 100644 --- a/x/staking/querier/querier.go +++ b/x/staking/querier/querier.go @@ -2,6 +2,7 @@ package querier import ( "fmt" + "strings" abci "github.com/tendermint/tendermint/abci/types" @@ -35,7 +36,7 @@ func NewQuerier(k keep.Keeper, cdc *codec.Codec) sdk.Querier { return func(ctx sdk.Context, path []string, req abci.RequestQuery) (res []byte, err sdk.Error) { switch path[0] { case QueryValidators: - return queryValidators(ctx, cdc, k) + return queryValidators(ctx, cdc, req, k) case QueryValidator: return queryValidator(ctx, cdc, req, k) case QueryValidatorDelegations: @@ -128,14 +129,47 @@ func NewQueryRedelegationParams(delegatorAddr sdk.AccAddress, srcValidatorAddr s } } -func queryValidators(ctx sdk.Context, cdc *codec.Codec, k keep.Keeper) (res []byte, err sdk.Error) { +func queryValidators(ctx sdk.Context, cdc *codec.Codec, req abci.RequestQuery, k keep.Keeper) ([]byte, sdk.Error) { + var params QueryValidatorsParams + + err := cdc.UnmarshalJSON(req.Data, ¶ms) + if err != nil { + return nil, sdk.ErrInternal(fmt.Sprintf("failed to parse params: %s", err)) + } + stakingParams := k.GetParams(ctx) - validators := k.GetValidators(ctx, stakingParams.MaxValidators) + if params.Limit == 0 { + params.Limit = int(stakingParams.MaxValidators) + } + + validators := k.GetAllValidators(ctx) + filteredVals := make([]types.Validator, 0, len(validators)) + + for _, val := range validators { + if strings.ToLower(val.GetStatus().String()) == strings.ToLower(params.Status) { + filteredVals = append(filteredVals, val) + } + } + + // get pagination bounds + start := (params.Page - 1) * params.Limit + end := params.Limit + start + if end >= len(filteredVals) { + end = len(filteredVals) + } - res, errRes := codec.MarshalJSONIndent(cdc, validators) + if start >= len(filteredVals) { + // page is out of bounds + filteredVals = []types.Validator{} + } else { + filteredVals = filteredVals[start:end] + } + + res, err := codec.MarshalJSONIndent(cdc, filteredVals) if err != nil { - return nil, sdk.ErrInternal(sdk.AppendMsgToErr("could not marshal result to JSON", errRes.Error())) + return nil, sdk.ErrInternal(sdk.AppendMsgToErr("failed to JSON marshal result: %s", err.Error())) } + return res, nil } @@ -354,3 +388,14 @@ func queryParameters(ctx sdk.Context, cdc *codec.Codec, k keep.Keeper) (res []by } return res, nil } + +// QueryValidatorsParams defines the params for the following queries: +// - 'custom/staking/validators' +type QueryValidatorsParams struct { + Page, Limit int + Status string +} + +func NewQueryValidatorsParams(page, limit int, status string) QueryValidatorsParams { + return QueryValidatorsParams{page, limit, status} +} diff --git a/x/staking/querier/querier_test.go b/x/staking/querier/querier_test.go index f4fe9592b33d..f83c950706e9 100644 --- a/x/staking/querier/querier_test.go +++ b/x/staking/querier/querier_test.go @@ -1,6 +1,7 @@ package querier import ( + "fmt" "testing" "github.com/stretchr/testify/require" @@ -44,9 +45,6 @@ func TestNewQuerier(t *testing.T) { require.NotNil(t, err) require.Nil(t, bz) - _, err = querier(ctx, []string{"validators"}, query) - require.Nil(t, err) - _, err = querier(ctx, []string{"pool"}, query) require.Nil(t, err) @@ -121,28 +119,44 @@ func TestQueryValidators(t *testing.T) { params := keeper.GetParams(ctx) // Create Validators - amts := []sdk.Int{sdk.NewInt(9), sdk.NewInt(8)} - var validators [2]types.Validator + amts := []sdk.Int{sdk.NewInt(9), sdk.NewInt(8), sdk.NewInt(7)} + status := []sdk.BondStatus{sdk.Bonded, sdk.Unbonded, sdk.Unbonding} + var validators [3]types.Validator for i, amt := range amts { validators[i] = types.NewValidator(sdk.ValAddress(keep.Addrs[i]), keep.PKs[i], types.Description{}) validators[i], pool, _ = validators[i].AddTokensFromDel(pool, amt) + validators[i], pool = validators[i].UpdateStatus(pool, status[i]) } + keeper.SetPool(ctx, pool) keeper.SetValidator(ctx, validators[0]) keeper.SetValidator(ctx, validators[1]) + keeper.SetValidator(ctx, validators[2]) // Query Validators queriedValidators := keeper.GetValidators(ctx, params.MaxValidators) - res, err := queryValidators(ctx, cdc, keeper) - require.Nil(t, err) + for i, s := range status { + queryValsParams := NewQueryValidatorsParams(1, int(params.MaxValidators), s.String()) + bz, errRes := cdc.MarshalJSON(queryValsParams) + require.Nil(t, errRes) - var validatorsResp []types.Validator - errRes := cdc.UnmarshalJSON(res, &validatorsResp) - require.Nil(t, errRes) + req := abci.RequestQuery{ + Path: fmt.Sprintf("/custom/%s/%s", types.QuerierRoute, QueryValidators), + Data: bz, + } + + res, err := queryValidators(ctx, cdc, req, keeper) + require.Nil(t, err) - require.Equal(t, len(queriedValidators), len(validatorsResp)) - require.ElementsMatch(t, queriedValidators, validatorsResp) + var validatorsResp []types.Validator + errRes = cdc.UnmarshalJSON(res, &validatorsResp) + require.Nil(t, errRes) + + require.Equal(t, 1, len(validatorsResp)) + require.ElementsMatch(t, validators[i].OperatorAddress, validatorsResp[0].OperatorAddress) + + } // Query each validator queryParams := NewQueryValidatorParams(addrVal1) @@ -153,7 +167,7 @@ func TestQueryValidators(t *testing.T) { Path: "/custom/staking/validator", Data: bz, } - res, err = queryValidator(ctx, cdc, query, keeper) + res, err := queryValidator(ctx, cdc, query, keeper) require.Nil(t, err) var validator types.Validator diff --git a/x/staking/types/validator.go b/x/staking/types/validator.go index c048de744c0d..962345aac59f 100644 --- a/x/staking/types/validator.go +++ b/x/staking/types/validator.go @@ -117,7 +117,7 @@ func (v Validator) String() string { Unbonding Completion Time: %v Minimum Self Delegation: %v Commission: %s`, v.OperatorAddress, bechConsPubKey, - v.Jailed, sdk.BondStatusToString(v.Status), v.Tokens, + v.Jailed, v.Status, v.Tokens, v.DelegatorShares, v.Description, v.UnbondingHeight, v.UnbondingCompletionTime, v.MinSelfDelegation, v.Commission) } From 1127446f71fa6aeada1bce2718f7f903cc18e548 Mon Sep 17 00:00:00 2001 From: Alexander Bezobchuk Date: Fri, 26 Apr 2019 11:01:10 -0400 Subject: [PATCH 2/2] Release v0.34.3 --- CHANGELOG.md | 9 +++++++++ client/lcd/swagger-ui/swagger.yaml | 2 +- cmd/gaia/cmd/gaiad/main.go | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 097d6b3c91c1..f815f19956b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## 0.34.3 + +### Bug Fixes + +#### Gaia + +* [\#4196](https://github.com/cosmos/cosmos-sdk/pull/4196) Set default invariant +check period to zero. + ## 0.34.2 ### Improvements diff --git a/client/lcd/swagger-ui/swagger.yaml b/client/lcd/swagger-ui/swagger.yaml index 11deeab65600..1507822a986c 100644 --- a/client/lcd/swagger-ui/swagger.yaml +++ b/client/lcd/swagger-ui/swagger.yaml @@ -772,7 +772,7 @@ paths: x-example: bonded - in: query name: page - description: The gage number. + description: The page number. type: integer x-example: 1 - in: query diff --git a/cmd/gaia/cmd/gaiad/main.go b/cmd/gaia/cmd/gaiad/main.go index 58e6cf576170..216b8df63c0b 100644 --- a/cmd/gaia/cmd/gaiad/main.go +++ b/cmd/gaia/cmd/gaiad/main.go @@ -57,7 +57,7 @@ func main() { // prepare and add flags executor := cli.PrepareBaseCmd(rootCmd, "GA", app.DefaultNodeHome) rootCmd.PersistentFlags().UintVar(&invCheckPeriod, flagInvCheckPeriod, - 1, "Assert registered invariants every N blocks") + 0, "Assert registered invariants every N blocks") err := executor.Execute() if err != nil { // handle with #870