Skip to content

Commit

Permalink
Merge pull request #7802 from sikkatech/gov_split_vote_weighted_vote
Browse files Browse the repository at this point in the history
ADR 037 Implementation:  Governance Split Votes
  • Loading branch information
sunnya97 committed Feb 12, 2021
2 parents e4b2d75 + a417b51 commit cb725e1
Show file tree
Hide file tree
Showing 37 changed files with 1,684 additions and 281 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/{bank,distrib,gov,slashing,staking}) [\#8363](https://github.com/cosmos/cosmos-sdk/issues/8363) Store keys have been modified to allow for variable-length addresses.
* (x/ibc) [\#8266](https://github.com/cosmos/cosmos-sdk/issues/8266) Add amino JSON for IBC messages in order to support Ledger text signing.
* (x/evidence) [\#8502](https://github.com/cosmos/cosmos-sdk/pull/8502) `HandleEquivocationEvidence` persists the evidence to state.
* (x/gov) [\#7733](https://github.com/cosmos/cosmos-sdk/pull/7733) ADR 037 Implementation: Governance Split Votes

### Improvements

Expand Down
8 changes: 4 additions & 4 deletions docs/architecture/adr-037-gov-split-vote.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

## Status

Proposed
Accepted

## Abstract

Expand Down Expand Up @@ -35,22 +35,22 @@ type Vote struct {
}
```

And for backwards compatibility, we introduce `MsgWeightedVote` while keeping `MsgVote`.
And for backwards compatibility, we introduce `MsgVoteWeighted` while keeping `MsgVote`.
```
type MsgVote struct {
ProposalID int64
Voter sdk.Address
Option Option
}
type MsgWeightedVote struct {
type MsgVoteWeighted struct {
ProposalID int64
Voter sdk.Address
Options []WeightedVoteOption
}
```

The `ValidateBasic` of a `MsgWeightedVote` struct would require that
The `ValidateBasic` of a `MsgVoteWeighted` struct would require that
1. The sum of all the Rates is equal to 1.0
2. No Option is repeated

Expand Down
49 changes: 48 additions & 1 deletion docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@
- [TextProposal](#cosmos.gov.v1beta1.TextProposal)
- [Vote](#cosmos.gov.v1beta1.Vote)
- [VotingParams](#cosmos.gov.v1beta1.VotingParams)
- [WeightedVoteOption](#cosmos.gov.v1beta1.WeightedVoteOption)

- [ProposalStatus](#cosmos.gov.v1beta1.ProposalStatus)
- [VoteOption](#cosmos.gov.v1beta1.VoteOption)
Expand Down Expand Up @@ -336,6 +337,8 @@
- [MsgSubmitProposalResponse](#cosmos.gov.v1beta1.MsgSubmitProposalResponse)
- [MsgVote](#cosmos.gov.v1beta1.MsgVote)
- [MsgVoteResponse](#cosmos.gov.v1beta1.MsgVoteResponse)
- [MsgVoteWeighted](#cosmos.gov.v1beta1.MsgVoteWeighted)
- [MsgVoteWeightedResponse](#cosmos.gov.v1beta1.MsgVoteWeightedResponse)

- [Msg](#cosmos.gov.v1beta1.Msg)

Expand Down Expand Up @@ -4587,7 +4590,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) | | |
| `options` | [WeightedVoteOption](#cosmos.gov.v1beta1.WeightedVoteOption) | repeated | |



Expand All @@ -4608,6 +4611,22 @@ VotingParams defines the params for voting on governance proposals.




<a name="cosmos.gov.v1beta1.WeightedVoteOption"></a>

### WeightedVoteOption
WeightedVoteOption defines a unit of vote for vote split.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `option` | [VoteOption](#cosmos.gov.v1beta1.VoteOption) | | |
| `weight` | [string](#string) | | |





<!-- end messages -->


Expand Down Expand Up @@ -5065,6 +5084,33 @@ MsgVoteResponse defines the Msg/Vote response type.




<a name="cosmos.gov.v1beta1.MsgVoteWeighted"></a>

### MsgVoteWeighted
MsgVote defines a message to cast a vote.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `proposal_id` | [uint64](#uint64) | | |
| `voter` | [string](#string) | | |
| `options` | [WeightedVoteOption](#cosmos.gov.v1beta1.WeightedVoteOption) | repeated | |






<a name="cosmos.gov.v1beta1.MsgVoteWeightedResponse"></a>

### MsgVoteWeightedResponse
MsgVoteWeightedResponse defines the MsgVoteWeighted response type.





<!-- end messages -->

<!-- end enums -->
Expand All @@ -5081,6 +5127,7 @@ Msg defines the bank Msg service.
| ----------- | ------------ | ------------- | ------------| ------- | -------- |
| `SubmitProposal` | [MsgSubmitProposal](#cosmos.gov.v1beta1.MsgSubmitProposal) | [MsgSubmitProposalResponse](#cosmos.gov.v1beta1.MsgSubmitProposalResponse) | SubmitProposal defines a method to create new proposal given a content. | |
| `Vote` | [MsgVote](#cosmos.gov.v1beta1.MsgVote) | [MsgVoteResponse](#cosmos.gov.v1beta1.MsgVoteResponse) | Vote defines a method to add a vote on a specific proposal. | |
| `VoteWeighted` | [MsgVoteWeighted](#cosmos.gov.v1beta1.MsgVoteWeighted) | [MsgVoteWeightedResponse](#cosmos.gov.v1beta1.MsgVoteWeightedResponse) | WeightedVote defines a method to add a weighted vote on a specific proposal. | |
| `Deposit` | [MsgDeposit](#cosmos.gov.v1beta1.MsgDeposit) | [MsgDepositResponse](#cosmos.gov.v1beta1.MsgDepositResponse) | Deposit defines a method to add deposit on a specific proposal. | |

<!-- end services -->
Expand Down
18 changes: 15 additions & 3 deletions proto/cosmos/gov/v1beta1/gov.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ enum VoteOption {
VOTE_OPTION_NO_WITH_VETO = 4 [(gogoproto.enumvalue_customname) = "OptionNoWithVeto"];
}

// WeightedVoteOption defines a unit of vote for vote split.
message WeightedVoteOption {
VoteOption option = 1;
string weight = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"weight\""
];
}

// TextProposal defines a standard text proposal whose changes need to be
// manually updated in case of approval.
message TextProposal {
Expand Down Expand Up @@ -119,9 +129,11 @@ message Vote {
option (gogoproto.goproto_stringer) = false;
option (gogoproto.equal) = false;

uint64 proposal_id = 1 [(gogoproto.moretags) = "yaml:\"proposal_id\""];
string voter = 2;
VoteOption option = 3;
uint64 proposal_id = 1 [(gogoproto.moretags) = "yaml:\"proposal_id\""];
string voter = 2;
reserved 3;
reserved "option";
repeated WeightedVoteOption options = 4 [(gogoproto.nullable) = false];
}

// DepositParams defines the params for deposits on governance proposals.
Expand Down
18 changes: 18 additions & 0 deletions proto/cosmos/gov/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ service Msg {
// Vote defines a method to add a vote on a specific proposal.
rpc Vote(MsgVote) returns (MsgVoteResponse);

// WeightedVote defines a method to add a weighted vote on a specific proposal.
rpc VoteWeighted(MsgVoteWeighted) returns (MsgVoteWeightedResponse);

// Deposit defines a method to add deposit on a specific proposal.
rpc Deposit(MsgDeposit) returns (MsgDepositResponse);
}
Expand Down Expand Up @@ -55,9 +58,24 @@ message MsgVote {
VoteOption option = 3;
}

// MsgVote defines a message to cast a vote.
message MsgVoteWeighted {
option (gogoproto.equal) = false;
option (gogoproto.goproto_stringer) = false;
option (gogoproto.stringer) = false;
option (gogoproto.goproto_getters) = false;

uint64 proposal_id = 1 [(gogoproto.jsontag) = "proposal_id", (gogoproto.moretags) = "yaml:\"proposal_id\""];
string voter = 2;
repeated WeightedVoteOption options = 3 [(gogoproto.nullable) = false];
}

// MsgVoteResponse defines the Msg/Vote response type.
message MsgVoteResponse {}

// MsgVoteWeightedResponse defines the Msg/VoteWeighted response type.
message MsgVoteWeightedResponse {}

// MsgDeposit defines a message to submit a deposit to an existing proposal.
message MsgDeposit {
option (gogoproto.equal) = false;
Expand Down
1 change: 1 addition & 0 deletions simapp/params/weights.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const (
DefaultWeightMsgFundCommunityPool int = 50
DefaultWeightMsgDeposit int = 100
DefaultWeightMsgVote int = 67
DefaultWeightMsgVoteWeighted int = 33
DefaultWeightMsgUnjail int = 100
DefaultWeightMsgCreateValidator int = 100
DefaultWeightMsgEditValidator int = 5
Expand Down
4 changes: 2 additions & 2 deletions x/gov/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func TestProposalPassedEndblocker(t *testing.T) {
deposits := initialModuleAccCoins.Add(proposal.TotalDeposit...).Add(proposalCoins...)
require.True(t, moduleAccCoins.IsEqual(deposits))

err = app.GovKeeper.AddVote(ctx, proposal.ProposalId, addrs[0], types.OptionYes)
err = app.GovKeeper.AddVote(ctx, proposal.ProposalId, addrs[0], types.NewNonSplitVoteOption(types.OptionYes))
require.NoError(t, err)

newHeader := ctx.BlockHeader()
Expand Down Expand Up @@ -348,7 +348,7 @@ func TestEndBlockerProposalHandlerFailed(t *testing.T) {

handleAndCheck(t, gov.NewHandler(app.GovKeeper), ctx, newDepositMsg)

err = app.GovKeeper.AddVote(ctx, proposal.ProposalId, addrs[0], types.OptionYes)
err = app.GovKeeper.AddVote(ctx, proposal.ProposalId, addrs[0], types.NewNonSplitVoteOption(types.OptionYes))
require.NoError(t, err)

newHeader := ctx.BlockHeader()
Expand Down
Loading

0 comments on commit cb725e1

Please sign in to comment.