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

Use any as validator pubkey #7597

Merged
merged 58 commits into from
Oct 23, 2020
Merged

Use any as validator pubkey #7597

merged 58 commits into from
Oct 23, 2020

Conversation

robert-zaremba
Copy link
Collaborator

@robert-zaremba robert-zaremba commented Oct 19, 2020

Description

Validator ConsensusPubKey type migration from string (bech32) to Any

closes: #7447 (partially)


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

CHANGELOG.md Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Oct 19, 2020

Codecov Report

Merging #7597 into master will decrease coverage by 0.05%.
The diff coverage is 46.28%.

@@            Coverage Diff             @@
##           master    #7597      +/-   ##
==========================================
- Coverage   54.21%   54.15%   -0.06%     
==========================================
  Files         611      611              
  Lines       38464    38556      +92     
==========================================
+ Hits        20852    20881      +29     
- Misses      15503    15543      +40     
- Partials     2109     2132      +23     

@robert-zaremba robert-zaremba marked this pull request as ready for review October 20, 2020 00:38
@robert-zaremba robert-zaremba mentioned this pull request Oct 20, 2020
9 tasks
Copy link
Contributor

@blushi blushi left a comment

Choose a reason for hiding this comment

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

Some tests are still failing, one in particular (TestRandomizedGenState in x/staking/simulation/genesis_test.go) is because you need to implement UnpackInterfaces on staking GenesisState (since it has a list of validators in it with Any values).

Also, it seems like there's an issue in func (v Validator) MinEqual(other Validator) bool in x/staking/types/validator.go, when comparing the ConsensusPubkeys, I'd say you need to GetCachedValue() on the ConsensusPubkeys first and then use Equals function from cryptotypes.PubKey to compare them.

CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
simapp/export.go Show resolved Hide resolved
Copy link
Contributor

@amaury1093 amaury1093 left a comment

Choose a reason for hiding this comment

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

Didn't go through everything yet, here are some first comments

proto/cosmos/staking/v1beta1/staking.proto Show resolved Hide resolved
simapp/test_helpers.go Show resolved Hide resolved
x/staking/types/historical_info.go Outdated Show resolved Hide resolved
x/staking/types/historical_info.go Outdated Show resolved Hide resolved
@clevinson clevinson self-assigned this Oct 23, 2020
Copy link
Contributor

@clevinson clevinson left a comment

Choose a reason for hiding this comment

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

Few small stylistic things, and one question about an error handling. Pre-approving as I don't consider any of them blockers.

Massive lift @robert-zaremba! Thanks for pushing this through 🎉

And big kudos to team effort from @amaurymartiny & @blushi for helping with test debugging throughout :)

simapp/app.go Outdated Show resolved Hide resolved
simapp/encoding.go Outdated Show resolved Hide resolved
simapp/params/proto.go Show resolved Hide resolved
x/staking/genesis.go Show resolved Hide resolved
@amaury1093 amaury1093 changed the title Robert/validator pubkey Use any as validator pubkey Oct 23, 2020
Copy link
Contributor

@amaury1093 amaury1093 left a comment

Choose a reason for hiding this comment

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

Overall lgtm 👍, small nits only

(I also changed the title to something more explicit)

simapp/test_helpers.go Show resolved Hide resolved
x/staking/types/validator_test.go Outdated Show resolved Hide resolved
x/staking/simulation/genesis_test.go Outdated Show resolved Hide resolved
x/staking/types/validator_test.go Outdated Show resolved Hide resolved
simapp/test_helpers.go Outdated Show resolved Hide resolved
x/staking/simulation/genesis_test.go Outdated Show resolved Hide resolved
x/staking/types/validator_test.go Outdated Show resolved Hide resolved
@robert-zaremba robert-zaremba added the A:automerge Automatically merge PR once all prerequisites pass. label Oct 23, 2020
@mergify mergify bot merged commit 6bc8ff2 into master Oct 23, 2020
@mergify mergify bot deleted the robert/validator-pubkey branch October 23, 2020 12:07
@@ -410,7 +410,9 @@ func TestTallyJailedValidator(t *testing.T) {

_ = staking.EndBlocker(ctx, app.StakingKeeper)

app.StakingKeeper.Jail(ctx, sdk.ConsAddress(val2.GetConsPubKey().Address()))
consKey, err := val2.TmConsPubKey()
Copy link
Member

@tac0turtle tac0turtle Oct 23, 2020

Choose a reason for hiding this comment

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

why does this need to be a tendermint key? It seems this PR intertwined Tendermint keys even deeper into the sdk..

@@ -12,7 +12,11 @@ import (
func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, stakingKeeper types.StakingKeeper, data *types.GenesisState) {
stakingKeeper.IterateValidators(ctx,
func(index int64, validator stakingtypes.ValidatorI) bool {
keeper.AddPubkey(ctx, validator.GetConsPubKey())
consPk, err := validator.TmConsPubKey()
Copy link
Member

Choose a reason for hiding this comment

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

this doesnt need to be a tendermint key. I believe the only places that need to be tendermint keys is where it is going to Tendermint. Within the sdk you can use sdk's keys

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Why? this is a consensus key, and it's coming from Tendermint. I'm not very familiar with the tendermint side. I assume that when we get a tendermint key then we should use it consistently as a tendermint key except when we serialize it in SDK objects.

@marbar3778 could you confirm?

Copy link
Member

@tac0turtle tac0turtle Oct 23, 2020

Choose a reason for hiding this comment

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

Tendermint doesn't care how its handled. The reason you would want to handle it with your own key is to disentangle Tendermint from the inner workings of the sdk. You can use tendermint ed25519 keys here but then what is the point of having your own?

Will this PR be backported to stargate?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To be able to serialize it in SDK structures / messages.

clevinson added a commit that referenced this pull request Oct 29, 2020
* protobuf pubkey type update

* wip2

* wip3

* solving types.NewValidator issues

* remove bech32 from validator type assignment

* update Validator interface

* Changelog update

* wip4

* update genutil

* fix simapp & x/ibc/testing tests

* update staking

* changelog update

* fix import cycle in tests

* fix amino panic on TestValidatorMarshalUnmarshalJSON

* fix TestValidatorMarshalUnmarshalJSON consensus_pubkey check

* Add UnpackInterfaces to HistoricalInfo

* fix TestHistoricalInfo

* update todos

* fix: Expecting ed25519.PubKey to implement proto.Message

* fix linter issues

* Fix migrate test

* Update CHANGELOG.md

Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com>

* review comments

* cosmetic changes

* add UnpackInterfaces got GenesisRandomized test

* Validator.Equal reuses Validator.MinEqual

* fix test

* use Validator.Equal in tests

* Fix staking simulation TestRandomizedGenState

* Remove TODO

* use HistoricalInfo.Equal

* use proto.Equal

* rename Validator.GetConsPubKey to TmConsPubKey

* prefer require.Equal over reflect.DeepEqual

* SetHistoricalInfo using a pointer

* Fix TestQueryDelegation test

* Fix TestQueryValidators test

* Fix TestSimulateMsgUnjail test

* experiement with LegacyAmino instances

* Register codecs in all simapp tests

* Fix cli_test compilation problems

* fix typo sdk -> std

* fix typo

* fix TestPlanStringer

* Rename to MakeEncodingConfig

* Remove RegisterCodecsTests

* Use gRPC in GetCmdQueryValidators

* Empty status

* fix info log check

* linter fixes

* rename simapparams to simappparams

* Update simapp/test_helpers.go

Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com>

* comments updates

* use valAddr1 instead of sdk.ValAddress(pk1.Address().Bytes())

Co-authored-by: Cory Levinson <cjlevinson@gmail.com>
Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com>
Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com>
larry0x pushed a commit to larry0x/cosmos-sdk that referenced this pull request May 22, 2023
* protobuf pubkey type update

* wip2

* wip3

* solving types.NewValidator issues

* remove bech32 from validator type assignment

* update Validator interface

* Changelog update

* wip4

* update genutil

* fix simapp & x/ibc/testing tests

* update staking

* changelog update

* fix import cycle in tests

* fix amino panic on TestValidatorMarshalUnmarshalJSON

* fix TestValidatorMarshalUnmarshalJSON consensus_pubkey check

* Add UnpackInterfaces to HistoricalInfo

* fix TestHistoricalInfo

* update todos

* fix: Expecting ed25519.PubKey to implement proto.Message

* fix linter issues

* Fix migrate test

* Update CHANGELOG.md

Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com>

* review comments

* cosmetic changes

* add UnpackInterfaces got GenesisRandomized test

* Validator.Equal reuses Validator.MinEqual

* fix test

* use Validator.Equal in tests

* Fix staking simulation TestRandomizedGenState

* Remove TODO

* use HistoricalInfo.Equal

* use proto.Equal

* rename Validator.GetConsPubKey to TmConsPubKey

* prefer require.Equal over reflect.DeepEqual

* SetHistoricalInfo using a pointer

* Fix TestQueryDelegation test

* Fix TestQueryValidators test

* Fix TestSimulateMsgUnjail test

* experiement with LegacyAmino instances

* Register codecs in all simapp tests

* Fix cli_test compilation problems

* fix typo sdk -> std

* fix typo

* fix TestPlanStringer

* Rename to MakeEncodingConfig

* Remove RegisterCodecsTests

* Use gRPC in GetCmdQueryValidators

* Empty status

* fix info log check

* linter fixes

* rename simapparams to simappparams

* Update simapp/test_helpers.go

Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com>

* comments updates

* use valAddr1 instead of sdk.ValAddress(pk1.Address().Bytes())

Co-authored-by: Cory Levinson <cjlevinson@gmail.com>
Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com>
Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com>
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove bech32 PubKey support
5 participants