Skip to content

Function to modify key codec#4112

Merged
melekes merged 15 commits intotendermint:masterfrom
ChainSafe:austin/exposeaminocdc
Nov 13, 2019
Merged

Function to modify key codec#4112
melekes merged 15 commits intotendermint:masterfrom
ChainSafe:austin/exposeaminocdc

Conversation

@austinabell
Copy link
Contributor

@austinabell austinabell commented Nov 5, 2019

Hey, not sure if this is disallowed for any reason specifically, but it would be very beneficial to define additional types to decode tendermint key implementations from bytes, since it uses a static codec. If this is okay, let me know and I will add documentation.

Context: For Ethermint to switch to using Cosmos' keybase, decoding the keys requires this codec to be updated

  • Referenced an issue explaining the need for the change
  • Updated all relevant documentation in docs
  • Updated all code comments where relevant
  • Wrote tests
  • Updated CHANGELOG_PENDING.md

@melekes
Copy link
Contributor

melekes commented Nov 7, 2019

this needs a CHANGELOG_PENDING.md entry

- [crypto] Add `RegisterKeyType` to amino to allow external key types registration (@austinabell)

@melekes
Copy link
Contributor

melekes commented Nov 7, 2019

Refs #2358

@austinabell
Copy link
Contributor Author

Just to document, I did experiment with creating a mapping from string to objects to be able to keep track of the key types added to be able to be used in the RegisterAmino(..) call, but because of how go is compiled, cosmos would just use the base types. This may be a useful feature for someone just building on top of Tendermint and not going through Cosmos, but to not add confusion or unnecessary complexity, I left it out.

@codecov-io
Copy link

codecov-io commented Nov 7, 2019

Codecov Report

Merging #4112 into master will increase coverage by 0.16%.
The diff coverage is 60%.

@@            Coverage Diff             @@
##           master    #4112      +/-   ##
==========================================
+ Coverage   66.67%   66.84%   +0.16%     
==========================================
  Files         247      247              
  Lines       21220    21225       +5     
==========================================
+ Hits        14149    14187      +38     
+ Misses       6018     5988      -30     
+ Partials     1053     1050       -3
Impacted Files Coverage Δ
crypto/encoding/amino/amino.go 93.75% <60%> (+4.86%) ⬆️
blockchain/v2/reactor.go 50.87% <0%> (-12.29%) ⬇️
blockchain/v2/routine.go 81.81% <0%> (-6.07%) ⬇️
privval/signer_server.go 95.65% <0%> (-4.35%) ⬇️
consensus/ticker.go 91.66% <0%> (-4.17%) ⬇️
consensus/replay.go 72.54% <0%> (+0.78%) ⬆️
consensus/reactor.go 79.42% <0%> (+1.04%) ⬆️
consensus/state.go 78.83% <0%> (+1.16%) ⬆️
p2p/pex/pex_reactor.go 83.86% <0%> (+1.72%) ⬆️
blockchain/v0/reactor.go 80.66% <0%> (+1.88%) ⬆️
... and 3 more

@austinabell
Copy link
Contributor Author

Sorry that took a little longer than expected, test setup was a little finicky and the print tests required me to make sure the codec was reset after the test. Alternatively I could have changed the expected print output but I didn't want to change any existing tests

pubAminoName = "registerTest/Pub"
)

func TestRegisterKeyType(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this is great!

@melekes melekes self-assigned this Nov 11, 2019
Copy link
Contributor

@melekes melekes left a comment

Choose a reason for hiding this comment

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

👍

@melekes melekes merged commit 7cd55a7 into tendermint:master Nov 13, 2019
@ebuchman
Copy link
Contributor

Does this actually work in a real case? I thought the codecs are declared privately on a per package basis so it would be hard to get this effect to thread through ?

@austinabell
Copy link
Contributor Author

austinabell commented Nov 19, 2019

Does this actually work in a real case? I thought the codecs are declared privately on a per package basis so it would be hard to get this effect to thread through ?

Does for what I needed it for in Ethermint, can't say for other uses. If defined in the main() function of the cli and daemon binary as such:

	tmamino.RegisterKeyType(emintcrypto.PubKeySecp256k1{}, emintcrypto.PubKeyAminoName)
	tmamino.RegisterKeyType(emintcrypto.PrivKeySecp256k1{}, emintcrypto.PrivKeyAminoName)

It is able to be overriden for when a public/private key is decoded through the ..FromBytes functions using that codec.

I have noticed other interactions haven't threaded through based on how dependencies of dependencies are compiled in go which made other things more annoying, but this PR allowed the Ethermint key type to be decoded from the Cosmos keybase.

Edit: let me be more specific in my testing as I remember it. You can modify the codec but if you reinstantiate it within an application, other references to it outside of the application will still reference the previous version. Hopefully this helps

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.

4 participants