privval: Query validator key (#5876)

## Description

- Query validator key when a remote signer is used. This is supported gRPC remote signing and filePV only. 


Closes: #3009
This commit is contained in:
Marko
2021-01-12 10:06:33 +00:00
committed by GitHub
parent 5b698ed13b
commit f05788e632
4 changed files with 74 additions and 37 deletions
+31 -8
View File
@@ -5,9 +5,12 @@ import (
"github.com/spf13/cobra"
"github.com/tendermint/tendermint/crypto"
tmjson "github.com/tendermint/tendermint/libs/json"
tmnet "github.com/tendermint/tendermint/libs/net"
tmos "github.com/tendermint/tendermint/libs/os"
"github.com/tendermint/tendermint/privval"
tmgrpc "github.com/tendermint/tendermint/privval/grpc"
)
// ShowValidatorCmd adds capabilities for showing the validator info.
@@ -20,16 +23,36 @@ var ShowValidatorCmd = &cobra.Command{
}
func showValidator(cmd *cobra.Command, args []string) error {
keyFilePath := config.PrivValidatorKeyFile()
if !tmos.FileExists(keyFilePath) {
return fmt.Errorf("private validator file %s does not exist", keyFilePath)
}
var (
pubKey crypto.PubKey
err error
)
pv := privval.LoadFilePV(keyFilePath, config.PrivValidatorStateFile())
//TODO: remove once gRPC is the only supported protocol
protocol, _ := tmnet.ProtocolAndAddress(config.PrivValidatorListenAddr)
switch protocol {
case "grpc":
pvsc, err := tmgrpc.DialRemoteSigner(config, config.ChainID(), logger)
if err != nil {
return fmt.Errorf("can't connect to remote validator %w", err)
}
pubKey, err = pvsc.GetPubKey()
if err != nil {
return fmt.Errorf("can't get pubkey: %w", err)
}
default:
pubKey, err := pv.GetPubKey()
if err != nil {
return fmt.Errorf("can't get pubkey: %w", err)
keyFilePath := config.PrivValidatorKeyFile()
if !tmos.FileExists(keyFilePath) {
return fmt.Errorf("private validator file %s does not exist", keyFilePath)
}
pv := privval.LoadFilePV(keyFilePath, config.PrivValidatorStateFile())
pubKey, err = pv.GetPubKey()
if err != nil {
return fmt.Errorf("can't get pubkey: %w", err)
}
}
bz, err := tmjson.Marshal(pubKey)