Skip to content

Commit

Permalink
fix cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
agouin committed Nov 30, 2023
1 parent 41eedbc commit 9b84457
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
9 changes: 4 additions & 5 deletions cmd/horcrux/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,18 @@ func startCmd() *cobra.Command {
Args: cobra.NoArgs,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
err := signer.RequireNotRunning(config.PidFile)
out := cmd.OutOrStdout()
logger := cometlog.NewTMLogger(cometlog.NewSyncWriter(out))

err := signer.RequireNotRunning(logger, config.PidFile)
if err != nil {
return err
}

out := cmd.OutOrStdout()

if _, err := legacyConfig(); err == nil {
return fmt.Errorf("this is a legacy config. run `horcrux config migrate` to migrate to the latest format")
}

logger := cometlog.NewTMLogger(cometlog.NewSyncWriter(out))

// create all directories up to the state directory
if err = os.MkdirAll(config.StateDir, 0700); err != nil {
return err
Expand Down
21 changes: 14 additions & 7 deletions cmd/horcrux/cmd/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/strangelove-ventures/horcrux/signer"

cometjson "github.com/cometbft/cometbft/libs/json"
cometlog "github.com/cometbft/cometbft/libs/log"
)

// Snippet Taken from https://raw.githubusercontent.com/cometbft/cometbft/main/privval/file.go
Expand Down Expand Up @@ -82,14 +83,17 @@ func setStateCmd() *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
chainID := args[0]

out := cmd.OutOrStdout()
logger := cometlog.NewTMLogger(cometlog.NewSyncWriter(out))

if _, err := os.Stat(config.HomeDir); os.IsNotExist(err) {
cmd.SilenceUsage = false
return fmt.Errorf("%s does not exist, initialize config with horcrux config init and try again", config.HomeDir)
}

// Resetting the priv_validator_state.json should only be allowed if the
// signer is not running.
if err := signer.RequireNotRunning(config.PidFile); err != nil {
if err := signer.RequireNotRunning(logger, config.PidFile); err != nil {
return err
}

Expand All @@ -109,7 +113,7 @@ func setStateCmd() *cobra.Command {
return err
}

fmt.Fprintf(cmd.OutOrStdout(), "Setting height %d\n", height)
fmt.Fprintf(out, "Setting height %d\n", height)

pv.NoncePublic, cs.NoncePublic = nil, nil
signState := signer.SignStateConsensus{
Expand Down Expand Up @@ -150,9 +154,12 @@ func importStateCmd() *cobra.Command {
return fmt.Errorf("%s does not exist, initialize config with horcrux config init and try again", config.HomeDir)
}

out := cmd.OutOrStdout()
logger := cometlog.NewTMLogger(cometlog.NewSyncWriter(out))

// Resetting the priv_validator_state.json should only be allowed if the
// signer is not running.
if err := signer.RequireNotRunning(config.PidFile); err != nil {
if err := signer.RequireNotRunning(logger, config.PidFile); err != nil {
return err
}

Expand All @@ -170,11 +177,11 @@ func importStateCmd() *cobra.Command {

// Allow user to paste in priv_validator_state.json

fmt.Println("IMPORTANT: Your validator should already be STOPPED. You must copy the latest state..")
fmt.Fprintln(out, "IMPORTANT: Your validator should already be STOPPED. You must copy the latest state..")
<-time.After(2 * time.Second)
fmt.Println("")
fmt.Println("Paste your old priv_validator_state.json. Input a blank line after the pasted JSON to continue.")
fmt.Println("")
fmt.Fprintln(out, "")
fmt.Fprintln(out, "Paste your old priv_validator_state.json. Input a blank line after the pasted JSON to continue.")
fmt.Fprintln(out, "")

var textBuffer strings.Builder

Expand Down

0 comments on commit 9b84457

Please sign in to comment.