From 7c0e6939c13593db8243346c73b3c0c09a31699c Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaurym@users.noreply.github.com> Date: Fri, 25 Jun 2021 15:52:44 +0200 Subject: [PATCH] fix: Correctly populate legacy Vote.Option field (#9583) --- CHANGELOG.md | 1 + docs/core/proto-docs.md | 2 +- proto/cosmos/gov/v1beta1/gov.proto | 2 +- x/gov/keeper/grpc_query.go | 1 + x/gov/keeper/grpc_query_test.go | 4 ++-- x/gov/types/gov.pb.go | 4 ++-- 6 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a08488f9..19db5a504 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -162,6 +162,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/bank) [\#9229](https://github.com/cosmos/cosmos-sdk/pull/9229) Now zero coin balances cannot be added to balances & supply stores. If any denom becomes zero corresponding key gets deleted from store. * (types) [\#9511](https://github.com/cosmos/cosmos-sdk/pull/9511) Change `maxBitLen` of `sdk.Int` and `sdk.Dec` to handle max ERC20 value. * (keyring) [\#9562](https://github.com/cosmos/cosmos-sdk/pull/9563) fix keyring kwallet backend when using with empty wallet. +* (keyring) [\#9583](https://github.com/cosmos/cosmos-sdk/pull/9583) Fix correct population of legacy `Vote.Option` field for votes with 1 VoteOption of weight 1. ### Deprecated diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index c4e33fd6d..6b2ddbe1e 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -4987,7 +4987,7 @@ A Vote consists of a proposal ID, the voter, and the vote option. | ----- | ---- | ----- | ----------- | | `proposal_id` | [uint64](#uint64) | | | | `voter` | [string](#string) | | | -| `option` | [VoteOption](#cosmos.gov.v1beta1.VoteOption) | | **Deprecated.** Deprecated: Prefer to use `options` instead. This field is set in queries if an only if `len(options) == 1` and that option has weight 1. In all other cases, this field will default to OptionEmpty. | +| `option` | [VoteOption](#cosmos.gov.v1beta1.VoteOption) | | **Deprecated.** Deprecated: Prefer to use `options` instead. This field is set in queries if and only if `len(options) == 1` and that option has weight 1. In all other cases, this field will default to VOTE_OPTION_UNSPECIFIED. | | `options` | [WeightedVoteOption](#cosmos.gov.v1beta1.WeightedVoteOption) | repeated | | diff --git a/proto/cosmos/gov/v1beta1/gov.proto b/proto/cosmos/gov/v1beta1/gov.proto index b38c14d06..f040772e8 100644 --- a/proto/cosmos/gov/v1beta1/gov.proto +++ b/proto/cosmos/gov/v1beta1/gov.proto @@ -133,7 +133,7 @@ message Vote { string voter = 2; // Deprecated: Prefer to use `options` instead. This field is set in queries // if and only if `len(options) == 1` and that option has weight 1. In all - // other cases, this field will default to OptionEmpty. + // other cases, this field will default to VOTE_OPTION_UNSPECIFIED. VoteOption option = 3 [deprecated = true]; repeated WeightedVoteOption options = 4 [(gogoproto.nullable) = false]; } diff --git a/x/gov/keeper/grpc_query.go b/x/gov/keeper/grpc_query.go index ceb563b0c..5caf220f7 100644 --- a/x/gov/keeper/grpc_query.go +++ b/x/gov/keeper/grpc_query.go @@ -142,6 +142,7 @@ func (q Keeper) Votes(c context.Context, req *types.QueryVotesRequest) (*types.Q if err := q.cdc.Unmarshal(value, &vote); err != nil { return err } + populateLegacyOption(&vote) votes = append(votes, vote) return nil diff --git a/x/gov/keeper/grpc_query_test.go b/x/gov/keeper/grpc_query_test.go index 49505d1f6..0e7d6f251 100644 --- a/x/gov/keeper/grpc_query_test.go +++ b/x/gov/keeper/grpc_query_test.go @@ -395,8 +395,8 @@ func (suite *KeeperTestSuite) TestGRPCQueryVotes() { app.GovKeeper.SetProposal(ctx, proposal) votes = []types.Vote{ - {ProposalId: proposal.ProposalId, Voter: addrs[0].String(), Options: types.NewNonSplitVoteOption(types.OptionAbstain)}, - {ProposalId: proposal.ProposalId, Voter: addrs[1].String(), Options: types.NewNonSplitVoteOption(types.OptionYes)}, + {ProposalId: proposal.ProposalId, Voter: addrs[0].String(), Option: types.OptionAbstain, Options: types.NewNonSplitVoteOption(types.OptionAbstain)}, + {ProposalId: proposal.ProposalId, Voter: addrs[1].String(), Option: types.OptionYes, Options: types.NewNonSplitVoteOption(types.OptionYes)}, } accAddr1, err1 := sdk.AccAddressFromBech32(votes[0].Voter) accAddr2, err2 := sdk.AccAddressFromBech32(votes[1].Voter) diff --git a/x/gov/types/gov.pb.go b/x/gov/types/gov.pb.go index 013c0fa73..b13f51469 100644 --- a/x/gov/types/gov.pb.go +++ b/x/gov/types/gov.pb.go @@ -329,8 +329,8 @@ type Vote struct { ProposalId uint64 `protobuf:"varint,1,opt,name=proposal_id,json=proposalId,proto3" json:"proposal_id,omitempty" yaml:"proposal_id"` Voter string `protobuf:"bytes,2,opt,name=voter,proto3" json:"voter,omitempty"` // Deprecated: Prefer to use `options` instead. This field is set in queries - // if an only if `len(options) == 1` and that option has weight 1. In all - // other cases, this field will default to OptionEmpty. + // if and only if `len(options) == 1` and that option has weight 1. In all + // other cases, this field will default to VOTE_OPTION_UNSPECIFIED. Option VoteOption `protobuf:"varint,3,opt,name=option,proto3,enum=cosmos.gov.v1beta1.VoteOption" json:"option,omitempty"` // Deprecated: Do not use. Options []WeightedVoteOption `protobuf:"bytes,4,rep,name=options,proto3" json:"options"` }