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 keys migrate command #8703

Merged
merged 3 commits into from
Feb 25, 2021
Merged

Fix keys migrate command #8703

merged 3 commits into from
Feb 25, 2021

Conversation

amaury1093
Copy link
Contributor

@amaury1093 amaury1093 commented Feb 25, 2021

Description

ref: #8639

I have no idea what the keys migrate was doing, but imo it was bugged for multiple reasons:

  • imo we should have two --home flags: one for the location of the old keyring, and one for the location of the new keyring. I added a --old-home flag to it.
    • In practise for Gaia, we would have --old-home ~/.gaiacli --home ~/.gaiad
    • If both are same, then it's an in-place migration
  • the previous version migrated a TypeLocal to a TypeLocal (that's correct), a TypeOffline to a TypeOffline (correct too), but migrated Type{Ledger,Multi} both to TypeOffline (why???). Anyways, now the migration migrates to the correct keyring type.

Tests

I followed Sahith's test steps with a ledger key, and could migrate & sign with a tx with the new keyring

We should test:


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer
  • Review Codecov Report in the comment section below once CI passes

@@ -111,6 +111,10 @@ type Importer interface {

// ImportPubKey imports ASCII armored public keys.
ImportPubKey(uid string, armor string, keyType KeyType) error
Copy link
Contributor Author

@amaury1093 amaury1093 Feb 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ImportPubKeyis only used in tests now. I propose to remove it in a subsequent PR (to not introduce breaking change). For reasons, see #8703 (comment).

@@ -327,6 +331,15 @@ func (ks keystore) ImportPubKey(uid string, armor string, keyType KeyType) error
return nil
}

// MigrateInfo implements Importer.MigrateInfo.
func (ks keystore) MigrateInfo(oldInfo Info) error {
Copy link
Contributor Author

@amaury1093 amaury1093 Feb 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only for Type{Multi,Ledger,Offline}.

Before

The old migration logic was inside ImportPubKey: we read data from the old Info, decode it (depending on the type), extract pubkey, and create and write a new Info in the new keyring.

In the process, we completely lose the Info: we were migrating old TypeMulti and old TypeLedger into new TypeOffline. #8639 (comment)

After

We don't decode Info anymore (to extract pubkey etc). Since the infos didn't change, we just copy/paste the old Info into the new keyring. It's imo much simpler.

@jgimeno
Copy link
Contributor

jgimeno commented Feb 25, 2021

Let me try

@jgimeno
Copy link
Contributor

jgimeno commented Feb 25, 2021

It works now! Thanks @AmauryM, shall we merge back to original?

@alessio alessio merged commit a95da25 into sahith/fix-key-multi Feb 25, 2021
@alessio alessio deleted the am/fix-key-multi branch February 25, 2021 17:26
@alessio
Copy link
Contributor

alessio commented Feb 25, 2021

Thank you so very much @AmauryM !

alessio pushed a commit that referenced this pull request Mar 1, 2021
Fix `keys migrate` command (#8703)

crypto/keyring: reinstate the InfoImporter interface

InfoImporter is implemented by those Keyring implementations
that support import of Info objects.

Co-authored-by: Alessio Treglia <[email protected]>
Co-authored-by: Jonathan Gimeno <[email protected]>
Co-authored-by: Amaury <[email protected]>
alessio pushed a commit that referenced this pull request Mar 1, 2021
Fix `keys migrate` command (#8703)

crypto/keyring: reinstate the InfoImporter interface

InfoImporter is implemented by those Keyring implementations
that support import of Info objects.

Co-authored-by: Alessio Treglia <[email protected]>
Co-authored-by: Jonathan Gimeno <[email protected]>
Co-authored-by: Amaury <[email protected]>
alessio pushed a commit that referenced this pull request Mar 2, 2021
* crypto/keyring: fix offline keys migration (#8639)

Fix `keys migrate` command (#8703)

crypto/keyring: reinstate the InfoImporter interface

InfoImporter is implemented by those Keyring implementations
that support import of Info objects.

Co-authored-by: Alessio Treglia <[email protected]>
Co-authored-by: Jonathan Gimeno <[email protected]>
Co-authored-by: Amaury <[email protected]>

* refresh golangci-lint

* Rename InfoImporter -> LegacyInfoImporter (#8739)

Avoid namespace clash with the InfoImporter interface
that already exists in the v0.41 release series.

* Revert "refresh golangci-lint"

This reverts commit 38e1349.

Co-authored-by: SaReN <[email protected]>
Co-authored-by: Jonathan Gimeno <[email protected]>
Co-authored-by: Amaury <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants