Skip to content

Commit

Permalink
Merge PR #65: Add cosigner address command
Browse files Browse the repository at this point in the history
* Add cosigner address command to get public key hex and consval addresses from CLI

* Update docs with administration commands

* Rename ConsVal to ValCons to avoid confusion

* Fix goreleaser version command
  • Loading branch information
agouin authored Mar 22, 2022
1 parent 8f08c3a commit 7e4a6d0
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 14 deletions.
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
VERSION := $(shell echo $(shell git describe --tags) | sed 's/^v//')
SDKVERSION := $(shell go list -m -u -f '{{.Version}}' github.com/cosmos/cosmos-sdk)
TMVERSION := $(shell go list -m -u -f '{{.Version}}' github.com/tendermint/tendermint)
COMMIT := $(shell git log -1 --format='%H')

all: install

LD_FLAGS = -X github.com/strangelove-ventures/horcrux/cmd/horcrux/cmd.Version=$(VERSION) \
-X github.com/strangelove-ventures/horcrux/cmd/horcrux/cmd.Commit=$(COMMIT) \
-X github.com/strangelove-ventures/horcrux/cmd/horcrux/cmd.SDKVersion=$(SDKVERSION) \
-X github.com/strangelove-ventures/horcrux/cmd/horcrux/cmd.TMVersion=$(TMVERSION)
-X github.com/strangelove-ventures/horcrux/cmd/horcrux/cmd.Commit=$(COMMIT)

BUILD_FLAGS := -ldflags '$(LD_FLAGS)'

Expand Down
61 changes: 61 additions & 0 deletions cmd/horcrux/cmd/cosigner.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package cmd

import (
"encoding/hex"
"encoding/json"
"fmt"
"log"
"os"
"path"
"strings"
"time"

"github.com/cosmos/cosmos-sdk/types/bech32"
"github.com/spf13/cobra"
"github.com/strangelove-ventures/horcrux/signer"
tmlog "github.com/tendermint/tendermint/libs/log"
Expand All @@ -16,6 +20,7 @@ import (

func init() {
cosignerCmd.AddCommand(StartCosignerCmd())
cosignerCmd.AddCommand(AddressCmd())
rootCmd.AddCommand(cosignerCmd)
}

Expand All @@ -24,6 +29,62 @@ var cosignerCmd = &cobra.Command{
Short: "Threshold mpc signer for TM based nodes",
}

type AddressCmdOutput struct {
HexAddress string
ValConsAddress string
}

func AddressCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "address",
Short: "Get public key hex address and valcons address",
Args: cobra.RangeArgs(0, 1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
err = validateCosignerConfig(config)
if err != nil {
return
}

var privValKeyFile string
if config.PrivValKeyFile == "" {
privValKeyFile = path.Join(config.HomeDir, "share.json")
} else {
privValKeyFile = config.PrivValKeyFile
}

key, err := signer.LoadCosignerKey(privValKeyFile)
if err != nil {
return fmt.Errorf("error reading cosigner key: %s", err)
}

pubKey := key.PubKey.Address()

output := AddressCmdOutput{
HexAddress: strings.ToUpper(hex.EncodeToString(pubKey)),
}

if len(args) == 1 {
bech32ValConsAddress, err := bech32.ConvertAndEncode(args[0], pubKey)
if err != nil {
return err
}
output.ValConsAddress = bech32ValConsAddress
}

jsonOut, err := json.Marshal(output)
if err != nil {
return err
}

fmt.Println(string(jsonOut))

return nil
},
}

return cmd
}

func StartCosignerCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "start",
Expand Down
13 changes: 11 additions & 2 deletions cmd/horcrux/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"encoding/json"
"fmt"
"runtime"
dbg "runtime/debug"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -48,12 +49,20 @@ type Info struct {
}

func NewInfo() Info {
bi, _ := dbg.ReadBuildInfo()

dependencyVersions := map[string]string{}

for _, dep := range bi.Deps {
dependencyVersions[dep.Path] = dep.Version
}

return Info{
Version: Version,
GitCommit: Commit,
GoVersion: fmt.Sprintf("%s %s/%s", runtime.Version(), runtime.GOOS, runtime.GOARCH),
CosmosSdkVersion: SDKVersion,
TendermintVersion: TMVersion,
CosmosSdkVersion: dependencyVersions["github.com/cosmos/cosmos-sdk"],
TendermintVersion: dependencyVersions["github.com/tendermint/tendermint"],
}
}

Expand Down
6 changes: 6 additions & 0 deletions docs/migrating.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,9 @@ Common failure modes:
### 7. CONGRATS!

You now can sleep much better at night because you are much less likely to have a down validator wake you up in the middle of the night. You have also completed a stressful migration on a production system. Go run around outside screaming, pet your dog, eat a nice meal, hug your kids/significant other, etc... and enjoy the rest of your day!

### 8. Administration Commands

`horcrux elect` - Elect a new cluster leader. Pass an optional argument with the intended leader ID to elect that cosigner as the new leader, e.g. `horcrux elect 3` to elect cosigner with `ID: 3` as leader

`horcrux cosigner address` - Get the public key address as both hex and optionally the validator consensus bech32 address. To retrieve the valcons bech32 address, pass an optional argument with the chain's bech32 valcons prefix, e.g. `horcrux cosigner address cosmosvalcons`
8 changes: 2 additions & 6 deletions goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@ env:
# Require use of Go modules.
- GO111MODULE=on

# TODO: figure out how to embed the sdk and tendermint versions in here
# https://goreleaser.com/customization/env/ set the env on the go releaser job
builds:
- id: "horcrux"
main: ./cmd/horcrux/main.go
ldflags:
- -X "github.com/strangelove-ventures/horcrux/version.Version={{ .Version }}"
- -X "github.com/strangelove-ventures/horcrux/version.Commit={{ .Commit }}"
- -X "github.com/strangelove-ventures/horcrux/version.SDKVersion=v0.43.2"
- -X "github.com/strangelove-ventures/horcrux/version.TMVersion=v0.34.8"
- -X "github.com/strangelove-ventures/horcrux/cmd/horcrux/cmd.Version={{ .Version }}"
- -X "github.com/strangelove-ventures/horcrux/cmd/horcrux/cmd.Commit={{ .Commit }}"
goos:
- darwin
- linux
Expand Down
5 changes: 4 additions & 1 deletion test/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ func (tn *TestNode) CliContext() client.Context {
// MakeTestNodes creates the test node objects required for bootstrapping tests
func MakeTestNodes(count int, home, chainid string, chainType *ChainType,
pool *dockertest.Pool, t *testing.T) (out TestNodes) {
err := pool.Client.PullImage(docker.PullImageOptions{Repository: chainType.Repository}, docker.AuthConfiguration{})
err := pool.Client.PullImage(docker.PullImageOptions{
Repository: chainType.Repository,
Tag: chainType.Version,
}, docker.AuthConfiguration{})
if err != nil {
t.Logf("Error pulling image: %v", err)
}
Expand Down

0 comments on commit 7e4a6d0

Please sign in to comment.