Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Migrate key names correctly #10328

Merged
merged 35 commits into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
5656854
migrate key names correctly
likhita-809 Oct 7, 2021
7e9400e
fix keynames migration
likhita-809 Oct 8, 2021
9a5da88
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into li…
likhita-809 Oct 8, 2021
603d3a3
fix something
likhita-809 Oct 8, 2021
2b6402f
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into li…
likhita-809 Oct 8, 2021
0ff4ffa
small fix
likhita-809 Oct 8, 2021
ea1ef5f
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into li…
likhita-809 Oct 11, 2021
2b173f2
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into li…
likhita-809 Oct 11, 2021
f6f5e0d
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into li…
likhita-809 Oct 11, 2021
3c3cc74
migrate key names correctly
likhita-809 Oct 12, 2021
9b10a09
address review comments
likhita-809 Oct 13, 2021
ad7220e
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into li…
likhita-809 Oct 13, 2021
b23c1b9
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into li…
likhita-809 Oct 13, 2021
5936464
fix failing tests
likhita-809 Oct 13, 2021
73ba70b
fix failing tests
likhita-809 Oct 13, 2021
7ccdf66
try fix failing tests
likhita-809 Oct 13, 2021
0d5c4c7
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into li…
likhita-809 Oct 13, 2021
48ab5ed
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into li…
likhita-809 Oct 14, 2021
0c81146
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into li…
likhita-809 Oct 18, 2021
7565c92
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into li…
likhita-809 Oct 18, 2021
db383eb
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into li…
likhita-809 Oct 18, 2021
7e65f07
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into li…
likhita-809 Oct 18, 2021
8cb5ced
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into li…
likhita-809 Oct 19, 2021
1b48b73
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into li…
likhita-809 Oct 19, 2021
87c2cec
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into li…
likhita-809 Oct 20, 2021
7207fee
address review comments
likhita-809 Oct 20, 2021
de79be4
fix failing tests
likhita-809 Oct 20, 2021
1552a13
small fix
likhita-809 Oct 20, 2021
99fdeca
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into li…
likhita-809 Oct 20, 2021
7247840
small fix
likhita-809 Oct 20, 2021
079aa5f
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into li…
likhita-809 Oct 21, 2021
574065b
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into li…
likhita-809 Oct 22, 2021
f3cb280
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into li…
likhita-809 Oct 25, 2021
a221b7f
fix nits
likhita-809 Oct 26, 2021
0d375f1
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into li…
likhita-809 Oct 26, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions client/keys/add_ledger_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build ledger test_ledger_mock
//go:build ledger || test_ledger_mock
// +build ledger test_ledger_mock
likhita-809 marked this conversation as resolved.
Show resolved Hide resolved

package keys

Expand Down Expand Up @@ -194,7 +195,7 @@ func Test_runAddCmdLedgerDryRun(t *testing.T) {
} else {
_, err = kb.Key("testkey")
require.Error(t, err)
require.Equal(t, "testkey: key not found", err.Error())
require.Equal(t, "testkey.info: key not found", err.Error())
likhita-809 marked this conversation as resolved.
Show resolved Hide resolved
}
})
}
Expand Down
3 changes: 1 addition & 2 deletions client/keys/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"testing"

"github.com/stretchr/testify/require"

"github.com/tendermint/tendermint/libs/cli"

"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -226,7 +225,7 @@ func Test_runAddCmdDryRun(t *testing.T) {
} else {
_, err = kb.Key("testkey")
require.Error(t, err)
require.Equal(t, "testkey: key not found", err.Error())
require.Equal(t, "testkey.info: key not found", err.Error())
}
})
}
Expand Down
4 changes: 2 additions & 2 deletions client/keys/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package keys
import (
"bufio"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/input"
"github.com/cosmos/cosmos-sdk/crypto/keyring"

"github.com/spf13/cobra"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion client/keys/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func Test_runDeleteCmd(t *testing.T) {

err = cmd.ExecuteContext(ctx)
require.Error(t, err)
require.EqualError(t, err, "blah: key not found")
require.EqualError(t, err, "blah.info: key not found")

// User confirmation missing
cmd.SetArgs([]string{
Expand Down
3 changes: 2 additions & 1 deletion client/keys/rename.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"bufio"
"fmt"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/input"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/spf13/cobra"
)

// RenameKeyCommand renames a key from the key store.
Expand Down
2 changes: 1 addition & 1 deletion client/keys/rename_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func Test_runRenameCmd(t *testing.T) {
cmd.SetArgs([]string{"blah", "blaah", fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome)})
err = cmd.ExecuteContext(ctx)
require.Error(t, err)
require.EqualError(t, err, "blah: key not found")
require.EqualError(t, err, "blah.info: key not found")

// User confirmation missing
cmd.SetArgs([]string{
Expand Down
12 changes: 9 additions & 3 deletions crypto/keyring/keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"strings"

"github.com/99designs/keyring"
"github.com/cosmos/go-bip39"
"github.com/pkg/errors"
"github.com/tendermint/crypto/bcrypt"
tmcrypto "github.com/tendermint/tendermint/crypto"
Expand All @@ -24,6 +23,7 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/go-bip39"
)

// Backend options for Keyring
Expand Down Expand Up @@ -456,6 +456,9 @@ func (ks keystore) Delete(uid string) error {
return err
}

if !(strings.HasSuffix(uid, infoSuffix)) {
uid = infoKey(uid)
}
err = ks.db.Remove(uid)
likhita-809 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
Expand Down Expand Up @@ -770,7 +773,7 @@ func (ks keystore) writeRecord(k *Record) error {
return err
}

key := k.Name
key := infoKey(k.Name)

exists, err := ks.existsInDb(addr, key)
if err != nil {
Expand All @@ -786,7 +789,7 @@ func (ks keystore) writeRecord(k *Record) error {
}

item := keyring.Item{
Key: key,
Key: string(key),
likhita-809 marked this conversation as resolved.
Show resolved Hide resolved
Data: serializedRecord,
}

Expand Down Expand Up @@ -877,6 +880,9 @@ func (ks keystore) MigrateAll() (bool, error) {

// migrate converts keyring.Item from amino to proto serialization format.
func (ks keystore) migrate(key string) (*Record, bool, error) {
if !(strings.HasSuffix(key, infoSuffix)) && !(strings.HasPrefix(key, sdk.Bech32PrefixAccAddr)) {
key = infoKey(key)
}
item, err := ks.db.Get(key)
if err != nil {
return nil, false, wrapKeyNotFound(err, key)
Expand Down
4 changes: 2 additions & 2 deletions crypto/keyring/keyring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"testing"

"github.com/99designs/keyring"
bip39 "github.com/cosmos/go-bip39"
"github.com/cosmos/go-bip39"
"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/codec"
Expand Down Expand Up @@ -432,7 +432,7 @@ func TestKeyringKeybaseExportImportPrivKey(t *testing.T) {

// try export non existing key
_, err = kb.ExportPrivKeyArmor("john3", "wrongpassword")
require.EqualError(t, err, "john3: key not found")
require.EqualError(t, err, "john3.info: key not found")
}

func TestInMemoryLanguage(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions crypto/keyring/legacy_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ type legacyLocalInfo struct {
Algo hd.PubKeyType `json:"algo"`
}

func infoKey(name string) string { return fmt.Sprintf("%s.%s", name, infoSuffix) }

// GetType implements Info interface
func (i legacyLocalInfo) GetType() KeyType {
return TypeLocal
Expand Down
1 change: 1 addition & 0 deletions crypto/keyring/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const (
// bits of entropy to draw when creating a mnemonic
defaultEntropySize = 256
addressSuffix = "address"
infoSuffix = "info"
)

// KeyType reflects a human-readable type for key listing.
Expand Down
3 changes: 1 addition & 2 deletions server/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package server
import (
"fmt"

"github.com/cosmos/cosmos-sdk/crypto/keyring"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
sdk "github.com/cosmos/cosmos-sdk/types"
)

Expand Down