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

refactor: Bring back deprecated proto fields to v1beta1 #9534

Merged
merged 23 commits into from
Jun 23, 2021

Conversation

amaury1093
Copy link
Contributor

@amaury1093 amaury1093 commented Jun 17, 2021

Description

Closes: #9446


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

@github-actions github-actions bot added the C:x/genutil genutil module issues label Jun 17, 2021
@codecov
Copy link

codecov bot commented Jun 17, 2021

Codecov Report

Merging #9534 (0ce625e) into master (1c77766) will increase coverage by 0.03%.
The diff coverage is 80.95%.

❗ Current head 0ce625e differs from pull request most recent head d279dc0. Consider uploading reports for the commit d279dc0 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #9534      +/-   ##
==========================================
+ Coverage   60.61%   60.65%   +0.03%     
==========================================
  Files         589      588       -1     
  Lines       37260    37226      -34     
==========================================
- Hits        22587    22579       -8     
+ Misses      12730    12703      -27     
- Partials     1943     1944       +1     
Impacted Files Coverage Δ
x/gov/legacy/v040/migrate.go 66.96% <0.00%> (ø)
x/gov/legacy/v043/json.go 100.00% <ø> (ø)
x/gov/types/vote.go 26.92% <0.00%> (ø)
x/gov/keeper/vote.go 87.69% <77.77%> (-1.60%) ⬇️
x/gov/legacy/v043/store.go 86.20% <100.00%> (+0.49%) ⬆️
x/upgrade/types/plan.go 94.44% <100.00%> (+1.58%) ⬆️
simapp/simd/cmd/root.go 61.71% <0.00%> (-5.18%) ⬇️
server/config/toml.go 18.18% <0.00%> (+4.84%) ⬆️

@aaronc
Copy link
Member

aaronc commented Jun 17, 2021

Let's remember to update buf.yaml too while we're at it and remove the FIELD_NO_DELETE exception

@github-actions github-actions bot added the T: CI label Jun 18, 2021
@amaury1093 amaury1093 marked this pull request as ready for review June 18, 2021 07:54
@amaury1093
Copy link
Contributor Author

amaury1093 commented Jun 18, 2021

R4R, @aaronc @robert-zaremba lmk if I forgot something.

Edit: I also added the deprecated proto options as per our SDK call.

Copy link
Member

@aaronc aaronc left a comment

Choose a reason for hiding this comment

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

I'd like a better fallback for Vote.Option on querying but otherwise LGTM

@@ -13,7 +13,7 @@ import (
// NewVote creates a new Vote instance
//nolint:interfacer
func NewVote(proposalID uint64, voter sdk.AccAddress, options WeightedVoteOptions) Vote {
return Vote{proposalID, voter.String(), options}
return Vote{ProposalId: proposalID, Voter: voter.String(), Options: options}
Copy link
Member

Choose a reason for hiding this comment

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

If len(options) == 1 and the weight is 1, let's also set Option to have a graceful fallback

Copy link
Contributor Author

@amaury1093 amaury1093 Jun 21, 2021

Choose a reason for hiding this comment

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

I don't think that's desired here.

This function is called when setting state. A user can call MsgWeightedVote explicity with len(options) == 1 and weight == 1, in state I think we should simply always skip the deprecated field.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added graceful fallback only for queries in d1d03fd

Copy link
Collaborator

@robert-zaremba robert-zaremba left a comment

Choose a reason for hiding this comment

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

In Keeper.AddVote, shall we check that Vote.Option and Vote.Options are exclusive (on can't set both parameters)?

reserved 2;
reserved "time";
// If this field is not empty, an error will be thrown.
google.protobuf.Timestamp time = 2 [deprecated = true, (gogoproto.stdtime) = true, (gogoproto.nullable) = false];
Copy link
Collaborator

Choose a reason for hiding this comment

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

in fact, this field is problematic. User simply can't use it. We need to be clear in the changelog about it - because in other circumstance this should require a proto version update in my opinion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I agree, I updated the existing changelog entry, do you think it's enough? A mention in the release notes would be useful too.

Comment on lines 83 to 86
// vote.Option is a deprecated field, we don't set it in state
if vote.Option != types.OptionEmpty { //nolint staticcheck // Deprecated field
panic(fmt.Errorf("expected empty vote.Option, got %s", vote.Option)) //nolint staticcheck // Deprecated field
}
Copy link
Contributor Author

@amaury1093 amaury1093 Jun 21, 2021

Choose a reason for hiding this comment

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

@robert-zaremba

In Keeper.AddVote, shall we check that Vote.Option and Vote.Options are exclusive (on can't set both parameters)?

AddVote takes options as argument, I don't think there's anything to change.

I added this piece of code in keeper.SetVote, so that in state, we always only store the weighted option, does that seem okay to you?

// VoteOption.
if len(vote.Options) == 1 && vote.Options[0].Weight.Equal(sdk.MustNewDecFromStr("1.0")) {
vote.Option = vote.Options[0].Option //nolint
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we remove the entries in Options?

vote.Options = nil

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, should we do the same transformation (setting vote.Option in GetVotes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, should we do the same transformation (setting vote.Option in GetVotes?

Yes, fixed.

should we remove the entries in Options? vote.Options = nil

I'm not sure. We should for sure populate Vote.Option to keep backwards-compatibility, but I would also populate Vote.Options too, so that clients know what to use instead of the deprecated field.

Copy link
Collaborator

Choose a reason for hiding this comment

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

OK, Vote.Option is marked as deprecated, so Vote.Options should be used in principal.

Copy link
Collaborator

@robert-zaremba robert-zaremba left a comment

Choose a reason for hiding this comment

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

utACK

x/gov/keeper/vote.go Outdated Show resolved Hide resolved
Copy link
Contributor

@likhita-809 likhita-809 left a comment

Choose a reason for hiding this comment

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

lgtm, just a small nit

proto/cosmos/gov/v1beta1/gov.proto Outdated Show resolved Hide resolved
amaury1093 and others added 2 commits June 23, 2021 10:33
Co-authored-by: likhita-809 <78951027+likhita-809@users.noreply.github.com>
@amaury1093 amaury1093 added the A:automerge Automatically merge PR once all prerequisites pass. label Jun 23, 2021
@mergify mergify bot merged commit 29c7a46 into master Jun 23, 2021
@mergify mergify bot deleted the am/gov-upgrade-fallback branch June 23, 2021 13:03
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. C:x/genutil genutil module issues C:x/gov C:x/upgrade T: CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Address v1beta1 proto breaking changes
5 participants