Skip to content

Commit

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

<!--
The default pull request template is for types feat, fix, or refactor.
For other templates, add one of the following parameters to the url:
- template=docs.md
- template=other.md
-->

This PR adds a missing save inside the `InitializeNodeValidatorFilesFromMnemonic` method. 
Without it when using `gaiad init <name> --recover` no `priv_validator_key.json` file is created.

Closes: #XXXX

<!-- Add a description of the changes that this PR introduces and the files that
are the most critical to review. -->

---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed 
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
  • Loading branch information
leobragaz authored Jul 6, 2021
1 parent cd22168 commit 0dbc5de
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
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 0dbc5de

Please sign in to comment.