diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index f23ec5bfb..cfaa1b219 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -21,5 +21,9 @@ Special thanks to external contributors on this release: ### IMPROVEMENTS: ### BUG FIXES: -- [consensus] \#3297 Flush WAL on stop to prevent data corruption during + +* [consensus] \#3297 Flush WAL on stop to prevent data corruption during graceful shutdown +* [cmd] \#3314 Return an + error on `show_validator` when the private validator file does not exist. + diff --git a/cmd/tendermint/commands/show_node_id.go b/cmd/tendermint/commands/show_node_id.go index 02ab1a9bb..6026e3e18 100644 --- a/cmd/tendermint/commands/show_node_id.go +++ b/cmd/tendermint/commands/show_node_id.go @@ -16,12 +16,11 @@ var ShowNodeIDCmd = &cobra.Command{ } func showNodeID(cmd *cobra.Command, args []string) error { - nodeKey, err := p2p.LoadNodeKey(config.NodeKeyFile()) if err != nil { return err } - fmt.Println(nodeKey.ID()) + fmt.Println(nodeKey.ID()) return nil } diff --git a/cmd/tendermint/commands/show_validator.go b/cmd/tendermint/commands/show_validator.go index 78bc06034..fbf14f2f6 100644 --- a/cmd/tendermint/commands/show_validator.go +++ b/cmd/tendermint/commands/show_validator.go @@ -5,6 +5,7 @@ import ( "github.com/spf13/cobra" + cmn "github.com/tendermint/tendermint/libs/common" "github.com/tendermint/tendermint/privval" ) @@ -12,11 +13,21 @@ import ( var ShowValidatorCmd = &cobra.Command{ Use: "show_validator", Short: "Show this node's validator info", - Run: showValidator, + RunE: showValidator, } -func showValidator(cmd *cobra.Command, args []string) { - privValidator := privval.LoadOrGenFilePV(config.PrivValidatorKeyFile(), config.PrivValidatorStateFile()) - pubKeyJSONBytes, _ := cdc.MarshalJSON(privValidator.GetPubKey()) - fmt.Println(string(pubKeyJSONBytes)) +func showValidator(cmd *cobra.Command, args []string) error { + keyFilePath := config.PrivValidatorKeyFile() + if !cmn.FileExists(keyFilePath) { + return fmt.Errorf("private validator file %s does not exist", keyFilePath) + } + + pv := privval.LoadFilePV(keyFilePath, config.PrivValidatorStateFile()) + bz, err := cdc.MarshalJSON(pv.GetPubKey()) + if err != nil { + return err + } + + fmt.Println(string(bz)) + return nil }