Skip to content

Commit

Permalink
Merge branch 'master' into sahith/index-supply
Browse files Browse the repository at this point in the history
  • Loading branch information
jgimeno authored Mar 2, 2021
2 parents a3559ce + 8106056 commit 7c55f94
Show file tree
Hide file tree
Showing 87 changed files with 3,504 additions and 1,152 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ jobs:
if: env.GIT_DIFF
- name: test & coverage report creation
run: |
cat pkgs.txt.part.${{ matrix.part }} | xargs go test -mod=readonly -json -timeout 30m -race -tags='cgo ledger test_ledger_mock' > ${{ matrix.part }}-race-output.txt
xargs --arg-file=pkgs.txt.part.${{ matrix.part }} go test -mod=readonly -json -timeout 30m -race -tags='cgo ledger test_ledger_mock' | tee ${{ matrix.part }}-race-output.txt
if: env.GIT_DIFF
- uses: actions/upload-artifact@v2
with:
Expand Down
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/distribution) [\#8473](https://github.com/cosmos/cosmos-sdk/pull/8473) On genesis init, if the distribution module account balance, coming from bank module state, does not match the one in distribution module state, the initialization will panic.
* (client/keys) [\#8500](https://github.com/cosmos/cosmos-sdk/pull/8500) `InfoImporter` interface is removed from legacy keybase.
* [\#8629](https://github.com/cosmos/cosmos-sdk/pull/8629) Deprecated `SetFullFundraiserPath` from `Config` in favor of `SetPurpose` and `SetCoinType`.
* (x/upgrade) [\#8673](https://github.com/cosmos/cosmos-sdk/pull/8673) Remove IBC logic from x/upgrade. Deprecates IBC fields in an Upgrade Plan. IBC upgrade logic moved to 02-client and an IBC UpgradeProposal is added.

### State Machine Breaking

Expand All @@ -65,11 +66,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

* (x/bank) [\#8614](https://github.com/cosmos/cosmos-sdk/issues/8614) Add `Name` and `Symbol` fields to denom metadata
* (x/auth) [\#8522](https://github.com/cosmos/cosmos-sdk/pull/8522) Allow to query all stored accounts
* (x/ibc) [\#7949](https://github.com/cosmos/cosmos-sdk/issues/7949) Standardized channel `Acknowledgement` moved to its own file. Codec registration redundancy removed.
* (crypto/types) [\#8600](https://github.com/cosmos/cosmos-sdk/pull/8600) `CompactBitArray`: optimize the `NumTrueBitsBefore` method and add an `Equal` method.
* (store/cachekv), (x/bank/types) [\#8719](https://github.com/cosmos/cosmos-sdk/pull/8719) algorithmically fix pathologically slow code



### Bug Fixes

* (keyring) [#\8635](https://github.com/cosmos/cosmos-sdk/issues/8635) Remove hardcoded default passphrase value on `NewMnemonic`
Expand All @@ -78,6 +78,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/slashing) [\#8427](https://github.com/cosmos/cosmos-sdk/pull/8427) Fix query signing infos command
* (server) [\#8399](https://github.com/cosmos/cosmos-sdk/pull/8399) fix gRPC-web flag default value
* (server) [\#8641](https://github.com/cosmos/cosmos-sdk/pull/8641) Fix Tendermint and application configuration reading from file
* (rest) [\#8730](https://github.com/cosmos/cosmos-sdk/pull/8730) Fix querying txs with multisigs on legacy REST endpoints.
* (client/keys) [\#8639] (https://github.com/cosmos/cosmos-sdk/pull/8639) Fix keys migrate for mulitisig, offline, and ledger keys. The migrate command now takes a positional old_home_dir argument.

## [v0.41.3](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.41.3) - 2021-02-18

Expand Down
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ endif
ifeq (cleveldb,$(findstring cleveldb,$(COSMOS_BUILD_OPTIONS)))
build_tags += gcc
endif
build_tags += $(BUILD_TAGS)
build_tags := $(strip $(build_tags))

whitespace :=
whitespace += $(whitespace)
Expand All @@ -68,6 +66,7 @@ ifeq (cleveldb,$(findstring cleveldb,$(COSMOS_BUILD_OPTIONS)))
endif
ifeq (badgerdb,$(findstring badgerdb,$(COSMOS_BUILD_OPTIONS)))
ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=badgerdb
BUILD_TAGS += badgerdb
endif
# handle rocksdb
ifeq (rocksdb,$(findstring rocksdb,$(COSMOS_BUILD_OPTIONS)))
Expand All @@ -87,6 +86,9 @@ endif
ldflags += $(LDFLAGS)
ldflags := $(strip $(ldflags))

build_tags += $(BUILD_TAGS)
build_tags := $(strip $(build_tags))

BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)'
# check for nostrip option
ifeq (,$(findstring nostrip,$(COSMOS_BUILD_OPTIONS)))
Expand Down
35 changes: 20 additions & 15 deletions client/keys/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@ const migratePassphrase = "NOOP_PASSPHRASE"
// MigrateCommand migrates key information from legacy keybase to OS secret store.
func MigrateCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "migrate",
Use: "migrate <old_home_dir>",
Short: "Migrate keys from the legacy (db-based) Keybase",
Long: `Migrate key information from the legacy (db-based) Keybase to the new keyring-based Keybase.
Long: `Migrate key information from the legacy (db-based) Keybase to the new keyring-based Keyring.
The legacy Keybase used to persist keys in a LevelDB database stored in a 'keys' sub-directory of
the old client application's home directory, e.g. $HOME/.gaiacli/keys/.
For each key material entry, the command will prompt if the key should be skipped or not. If the key
is not to be skipped, the passphrase must be entered. The key will only be migrated if the passphrase
is correct. Otherwise, the command will exit and migration must be repeated.
It is recommended to run in 'dry-run' mode first to verify all key migration material.
`,
Args: cobra.ExactArgs(0),
Args: cobra.ExactArgs(1),
RunE: runMigrateCmd,
}

Expand All @@ -44,12 +46,12 @@ func runMigrateCmd(cmd *cobra.Command, args []string) error {

// instantiate legacy keybase
var legacyKb keyring.LegacyKeybase
legacyKb, err := NewLegacyKeyBaseFromDir(rootDir)
legacyKb, err := NewLegacyKeyBaseFromDir(args[0])
if err != nil {
return err
}

defer legacyKb.Close()
defer func() { _ = legacyKb.Close() }()

// fetch list of keys from legacy keybase
oldKeys, err := legacyKb.List()
Expand All @@ -71,7 +73,7 @@ func runMigrateCmd(cmd *cobra.Command, args []string) error {
return errors.Wrap(err, "failed to create temporary directory for dryrun migration")
}

defer os.RemoveAll(tmpDir)
defer func() { _ = os.RemoveAll(tmpDir) }()

migrator, err = keyring.New(keyringServiceName, keyring.BackendTest, tmpDir, buf)
} else {
Expand All @@ -91,11 +93,11 @@ func runMigrateCmd(cmd *cobra.Command, args []string) error {
return nil
}

for _, key := range oldKeys {
keyName := key.GetName()
keyType := key.GetType()
for _, oldInfo := range oldKeys {
keyName := oldInfo.GetName()
keyType := oldInfo.GetType()

cmd.PrintErrf("Migrating key: '%s (%s)' ...\n", key.GetName(), keyType)
cmd.PrintErrf("Migrating key: '%s (%s)' ...\n", keyName, keyType)

// allow user to skip migrating specific keys
ok, err := input.GetConfirmation("Skip key migration?", buf, cmd.ErrOrStderr())
Expand All @@ -106,13 +108,15 @@ func runMigrateCmd(cmd *cobra.Command, args []string) error {
continue
}

// TypeLocal needs an additional step to ask password.
// The other keyring types are handled by ImportInfo.
if keyType != keyring.TypeLocal {
pubkeyArmor, err := legacyKb.ExportPubKey(keyName)
if err != nil {
return err
infoImporter, ok := migrator.(keyring.LegacyInfoImporter)
if !ok {
return fmt.Errorf("the Keyring implementation does not support import operations of Info types")
}

if err := migrator.ImportPubKey(keyName, pubkeyArmor); err != nil {
if err = infoImporter.ImportInfo(oldInfo); err != nil {
return err
}

Expand All @@ -135,8 +139,9 @@ func runMigrateCmd(cmd *cobra.Command, args []string) error {
if err := migrator.ImportPrivKey(keyName, armoredPriv, migratePassphrase); err != nil {
return err
}

}
cmd.Print("Migration Complete")
cmd.PrintErrln("Migration complete.")

return err
}
30 changes: 12 additions & 18 deletions client/keys/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,38 @@ import (
"fmt"
"testing"

"github.com/cosmos/cosmos-sdk/client"

"github.com/stretchr/testify/require"

"github.com/otiai10/copy"
"github.com/stretchr/testify/assert"
"github.com/tendermint/tendermint/libs/cli"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/testutil"
)

func Test_runMigrateCmd(t *testing.T) {
cmd := AddKeyCommand()
_ = testutil.ApplyMockIODiscardOutErr(cmd)
cmd.Flags().AddFlagSet(Commands("home").PersistentFlags())

kbHome := t.TempDir()

clientCtx := client.Context{}.WithKeyringDir(kbHome)
ctx := context.WithValue(context.Background(), client.ClientContextKey, &clientCtx)

copy.Copy("testdata", kbHome)
cmd.SetArgs([]string{
"keyname1",
fmt.Sprintf("--%s=%s", cli.OutputFlag, OutputFormatText),
fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest),
})
assert.NoError(t, cmd.ExecuteContext(ctx))
require.NoError(t, copy.Copy("testdata", kbHome))

cmd = MigrateCommand()
cmd := MigrateCommand()
cmd.Flags().AddFlagSet(Commands("home").PersistentFlags())
mockIn := testutil.ApplyMockIODiscardOutErr(cmd)
//mockIn := testutil.ApplyMockIODiscardOutErr(cmd)
mockIn, mockOut := testutil.ApplyMockIO(cmd)

cmd.SetArgs([]string{
fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome),
kbHome,
//fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome),
fmt.Sprintf("--%s=true", flags.FlagDryRun),
fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest),
})

mockIn.Reset("test1234\ntest1234\n")
mockIn.Reset("\n12345678\n\n\n\n\n")
t.Log(mockOut.String())
assert.NoError(t, cmd.ExecuteContext(ctx))
}
Binary file added client/keys/testdata/keys/keys.db/000136.ldb
Binary file not shown.
Binary file added client/keys/testdata/keys/keys.db/000137.ldb
Binary file not shown.
2 changes: 1 addition & 1 deletion client/keys/testdata/keys/keys.db/CURRENT
Original file line number Diff line number Diff line change
@@ -1 +1 @@
MANIFEST-000005
MANIFEST-000167
2 changes: 1 addition & 1 deletion client/keys/testdata/keys/keys.db/CURRENT.bak
Original file line number Diff line number Diff line change
@@ -1 +1 @@
MANIFEST-000003
MANIFEST-000165
Loading

0 comments on commit 7c55f94

Please sign in to comment.