diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d11c6ed9996..190615fb26fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -76,7 +76,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (types) [\#9627](https://github.com/cosmos/cosmos-sdk/pull/9627) Fix nil pointer panic on `NewBigIntFromInt` * (x/genutil) [\#9574](https://github.com/cosmos/cosmos-sdk/pull/9575) Actually use the `gentx` client tx flags (like `--keyring-dir`) * (x/distribution) [\#9599](https://github.com/cosmos/cosmos-sdk/pull/9599) Withdraw rewards event now includes a value attribute even if there are 0 rewards (due to situations like 100% commission). - +* (x/genutil) [\#9638](https://github.com/cosmos/cosmos-sdk/pull/9638) Added missing validator key save when recovering from mnemonic ## [v0.43.0-rc0](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.43.0-rc0) - 2021-06-25 diff --git a/x/genutil/utils.go b/x/genutil/utils.go index 4c46bdb6f121..4851a4081d7b 100644 --- a/x/genutil/utils.go +++ b/x/genutil/utils.go @@ -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) { @@ -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() diff --git a/x/genutil/utils_test.go b/x/genutil/utils_test.go index a845cc68cd96..df0984a4a150 100644 --- a/x/genutil/utils_test.go +++ b/x/genutil/utils_test.go @@ -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" @@ -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) + } } }) }