Skip to content

Commit

Permalink
fix: Added missing validator key save when recovering from mnemonic (c…
Browse files Browse the repository at this point in the history
…osmos#9638)

(cherry picked from commit 0dbc5de)
  • Loading branch information
leobragaz authored and RiccardoM committed Aug 26, 2021
1 parent 0e951b4 commit 864fc99
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion x/genutil/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func InitializeNodeValidatorFiles(config *cfg.Config) (nodeID string, valPubKey
return InitializeNodeValidatorFilesFromMnemonic(config, "")
}

// InitializeNodeValidatorFiles creates private validator and p2p configuration files using the given mnemonic.
// InitializeNodeValidatorFilesFromMnemonic creates private validator and p2p configuration files using the given mnemonic.
// If no valid mnemonic is given, a random one will be used instead.
func InitializeNodeValidatorFilesFromMnemonic(config *cfg.Config, mnemonic string) (nodeID string, valPubKey cryptotypes.PubKey, err error) {
if len(mnemonic) > 0 && !bip39.IsMnemonicValid(mnemonic) {
Expand Down Expand Up @@ -84,6 +84,7 @@ func InitializeNodeValidatorFilesFromMnemonic(config *cfg.Config, mnemonic strin
} else {
privKey := tmed25519.GenPrivKeyFromSecret([]byte(mnemonic))
filePV = privval.NewFilePV(privKey, pvKeyFile, pvStateFile)
filePV.Save()
}

tmValPubKey, err := filePV.GetPubKey()
Expand Down
9 changes: 9 additions & 0 deletions x/genutil/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package genutil

import (
"encoding/json"
tmed25519 "github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/privval"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -57,6 +59,13 @@ func TestInitializeNodeValidatorFilesFromMnemonic(t *testing.T) {
require.Error(t, err)
} else {
require.NoError(t, err)

if tt.mnemonic != "" {
actualPVFile := privval.LoadFilePV(cfg.PrivValidatorKeyFile(), cfg.PrivValidatorStateFile())
expectedPrivateKey := tmed25519.GenPrivKeyFromSecret([]byte(tt.mnemonic))
expectedFile := privval.NewFilePV(expectedPrivateKey, cfg.PrivValidatorKeyFile(), cfg.PrivValidatorStateFile())
require.Equal(t, expectedFile, actualPVFile)
}
}
})
}
Expand Down

0 comments on commit 864fc99

Please sign in to comment.