Skip to content

Commit

Permalink
feat: add an option for selecting priv key type to unsafe_reset_all
Browse files Browse the repository at this point in the history
…, `unsafe_reset_priv_validator`, and `gen_validator`
  • Loading branch information
Kynea0b committed Feb 16, 2021
1 parent 009e7eb commit c68d620
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
42 changes: 31 additions & 11 deletions cmd/tendermint/commands/gen_validator.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package commands

import (
"fmt"

"github.com/spf13/cobra"

tmos "github.com/tendermint/tendermint/libs/os"
"github.com/tendermint/tendermint/privval"
)

Expand All @@ -13,15 +11,37 @@ import (
var GenValidatorCmd = &cobra.Command{
Use: "gen_validator",
Short: "Generate new validator keypair",
Run: genValidator,
RunE: func(cmd *cobra.Command, args []string) error {
return genValidator(cmd, args)
},
}

func init() {
GenValidatorCmd.Flags().String("priv_key_type", config.PrivKeyType,
"Specify validator's private key type (ed25519 | composite)")
}

func genValidator(cmd *cobra.Command, args []string) {
pv, _ := privval.GenFilePV("", "", privval.PrivKeyTypeEd25519)
jsbz, err := cdc.MarshalJSON(pv)
if err != nil {
panic(err)
func genValidator(cmd *cobra.Command, args []string) error {
// private validator
privValKeyFile := config.PrivValidatorKeyFile()
privValStateFile := config.PrivValidatorStateFile()
privKeyType := config.PrivValidatorKeyType()
var pv *privval.FilePV
if tmos.FileExists(privValKeyFile) {
pv = privval.LoadFilePV(privValKeyFile, privValStateFile)
logger.Info("Found private validator", "keyFile", privValKeyFile,
"stateFile", privValStateFile)
} else {
var err error
pv, err = privval.GenFilePV(privValKeyFile, privValStateFile, privKeyType)
if err != nil {
return err
}
if pv != nil {
pv.Save()
}
logger.Info("Generated private validator", "keyFile", privValKeyFile,
"stateFile", privValStateFile)
}
fmt.Printf(`%v
`, string(jsbz))
return nil
}
4 changes: 4 additions & 0 deletions cmd/tendermint/commands/reset_priv_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ var keepAddrBook bool

func init() {
ResetAllCmd.Flags().BoolVar(&keepAddrBook, "keep-addr-book", false, "Keep the address book intact")
ResetAllCmd.Flags().String("priv_key_type", config.PrivKeyType,
"Specify validator's private key type (ed25519 | composite)")
ResetPrivValidatorCmd.Flags().String("priv_key_type", config.PrivKeyType,
"Specify validator's private key type (ed25519 | composite)")
}

// XXX: this is totally unsafe.
Expand Down

0 comments on commit c68d620

Please sign in to comment.