fix: keys migration issue (#12122)
## Description Closes: #12093 --- ### 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/main/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/main/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/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)
This commit is contained in:
@@ -361,6 +361,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
* (store) [\#11117](https://github.com/cosmos/cosmos-sdk/pull/11117) Fix data race in store trace component
|
||||
* (x/authz) [\#11252](https://github.com/cosmos/cosmos-sdk/pull/11252) Allow insufficient funds error for authz simulation
|
||||
* (crypto) [\#11298](https://github.com/cosmos/cosmos-sdk/pull/11298) Fix cgo secp signature verification and update libscep256k1 library.
|
||||
* (crypto) [\#12122](https://github.com/cosmos/cosmos-sdk/pull/12122) Fix keyring migration issue.
|
||||
|
||||
### Improvements
|
||||
|
||||
|
||||
@@ -498,7 +498,10 @@ func (ks keystore) List() ([]*Record, error) {
|
||||
var res []*Record //nolint:prealloc
|
||||
sort.Strings(keys)
|
||||
for _, key := range keys {
|
||||
if strings.HasSuffix(key, addressSuffix) {
|
||||
// Recall that each key is twice in the keyring:
|
||||
// - once with the `.info` suffix, which holds the key info
|
||||
// - another time with the `.address` suffix, which only holds a reference to its associated `.info` key
|
||||
if !strings.HasSuffix(key, infoSuffix) {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -872,9 +875,8 @@ func (ks keystore) MigrateAll() error {
|
||||
}
|
||||
|
||||
for _, key := range keys {
|
||||
// The keyring items with `.address` suffix only holds as Data the
|
||||
// key name uid, so there's nothing to migrate.
|
||||
if strings.HasSuffix(key, addressSuffix) {
|
||||
// The keyring items only with `.info` consists the key info.
|
||||
if !strings.HasSuffix(key, infoSuffix) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ package keyring
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -59,7 +61,8 @@ func TestNewKeyring(t *testing.T) {
|
||||
|
||||
func TestKeyManagementKeyRing(t *testing.T) {
|
||||
cdc := getCodec()
|
||||
kb, err := New("keybasename", "test", t.TempDir(), nil, cdc)
|
||||
tempDir := t.TempDir()
|
||||
kb, err := New("keybasename", "test", tempDir, nil, cdc)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, cdc)
|
||||
|
||||
@@ -151,6 +154,15 @@ func TestKeyManagementKeyRing(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, len(keyS))
|
||||
|
||||
// create some random directory inside the keyring directory to check migrate ignores
|
||||
// all files other than *.info
|
||||
newPath := filepath.Join(tempDir, "random")
|
||||
require.NoError(t, os.Mkdir(newPath, 0755))
|
||||
items, err := os.ReadDir(tempDir)
|
||||
require.GreaterOrEqual(t, len(items), 2)
|
||||
keyS, err = kb.List()
|
||||
require.NoError(t, err)
|
||||
|
||||
// addr cache gets nuked - and test skip flag
|
||||
require.NoError(t, kb.Delete(n2))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user