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

Replace tmcrypto.PubKey by our own cryptotypes.PubKey #7419

Merged
merged 37 commits into from
Nov 9, 2020

Conversation

blushi
Copy link
Contributor

@blushi blushi commented Sep 30, 2020

Description

ref: #7357

This PR aims to untangle the usage of TM's tmcrypto.PubKey in the SDK's codebase, and use the SDK's own cryptotypes.PubKey instead.

(note: whether or not cryptotypes.PubKey should itself extend tmcrypto.PubKey is another orthogonal discussion, and can be tracked in #7357)

Occurrences where we use TM's crypto.PubKey:

  • on master: 220 occurrences in 85 files
  • on this branch: 10 occurrences in 6 files

It also removes the IntoTmPubKey interfaces, and uses instead two centralized functions FromTmProtoPublicKey and ToTmProtoPublicKey whenever we need to interface with TM/ABCI (as per Marko's idea).


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

@blushi blushi mentioned this pull request Sep 30, 2020
11 tasks
@amaury1093 amaury1093 mentioned this pull request Oct 20, 2020
9 tasks
@lgtm-com
Copy link

lgtm-com bot commented Nov 4, 2020

This pull request introduces 1 alert when merging 51a353f into 71166c8 - view on LGTM.com

new alerts:

  • 1 for Useless assignment to local variable

@amaury1093 amaury1093 added Type: Code Hygiene General cleanup and restructuring of code to provide clarity, flexibility, and modularity. C:Encoding and removed Type: Code Hygiene General cleanup and restructuring of code to provide clarity, flexibility, and modularity. labels Nov 6, 2020
This was referenced Nov 6, 2020
Copy link
Member

@tac0turtle tac0turtle left a comment

Choose a reason for hiding this comment

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

left some questions, love this PR!!!

Copy link
Member

@tac0turtle tac0turtle left a comment

Choose a reason for hiding this comment

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

love this PR!!

crypto/codec/tm.go Show resolved Hide resolved
crypto/codec/tm.go Outdated Show resolved Hide resolved
}

return encoding.PubKeyFromProto(tmProtoPk)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why don't we use here the tendermint/crypto/ed25519? Public key is bytes we don't need to go through encoding here. We can just cast bytes to the right type using select.

Copy link
Contributor

Choose a reason for hiding this comment

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

TM supports secp256k1 too now. I could add a switch .(type) here, and do what you suggest. However, I feel it's a bit cleaner to have a central function to do conversion between sdk pubkey <-> tm pubkey (aka FromTmPublicKey). And other conversions (here between tm pubkey <-> tm proto public key) use tm's own functions.

}

// BasePrivKey defines a private key
type BasePrivKey interface {
Copy link
Collaborator

Choose a reason for hiding this comment

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

BasePrivKey sounds strange. How about doing other way around and renaming:

  • PrivKey -> ProtoPrivKey
  • BasePrivKey -> PrivKey

Copy link
Contributor

Choose a reason for hiding this comment

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

I renamed BasePrivKey to LedgerPrivKey. See comments in 0048063 if they make sense to you.

Copy link
Collaborator

Choose a reason for hiding this comment

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

NOTE: this will be removed or changed when PrivKeyLedgerSecp256k1 will get converted to proto

x/staking/types/historical_info_test.go Show resolved Hide resolved
x/staking/teststaking/tm.go Outdated Show resolved Hide resolved
x/staking/types/commission_test.go Show resolved Hide resolved
x/staking/types/validator.go Show resolved Hide resolved
Copy link
Contributor

@alessio alessio left a comment

Choose a reason for hiding this comment

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

ACK. Please merge.

@robert-zaremba
Copy link
Collaborator

Awesome. I also need it. This PR turned out to be a dependency to few other tasks. Thanks for doing it. 👍

@alessio alessio added the A:automerge Automatically merge PR once all prerequisites pass. label Nov 9, 2020
@mergify mergify bot merged commit 90e9370 into master Nov 9, 2020
@mergify mergify bot deleted the marie/7357-sdk-pubkey branch November 9, 2020 16:01
larry0x pushed a commit to larry0x/cosmos-sdk that referenced this pull request May 22, 2023
* WIP on removing tm pub/privkey

* Fix part of crypto tests

* Add PrivKeyLedgerSecp256K1 proto type

* Use BasePrivKey for ledger priv key type

* Refacto continued

* First round

* x/staking

* Continue porting

* x/* done

* Make build pass

* More conversion

* Remove IntoTmPubKey

* Fix test

* Remove crypto.PubKey in some other places

* Revert ledger changes

* Fix comment

* Remove useless function

* Add To/FromTmPublicKey

* Add migrate tests

* Fix test

* Fix another test

* Rename tm conversion functions

* Less code

* Rename BasePrivKey to LedgerPrivKey

* Add changelog

* Rename functions

Co-authored-by: Amaury Martiny <[email protected]>
Co-authored-by: Alessio Treglia <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:automerge Automatically merge PR once all prerequisites pass. Type: Code Hygiene General cleanup and restructuring of code to provide clarity, flexibility, and modularity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants