Skip to content

Commit

Permalink
refactor(group): Distinguish Voting period and Execution period for g…
Browse files Browse the repository at this point in the history
…roup policies (#11198)

## Description

Closes: #11092

## TODOs

I'm thinking to do the 2 todos in a separate PR, or else this PR is too big. WDYT?

- [ ] #11246 This involves adding a new index ProposalsByVotingPeriodEnd, so might be better to do in another PR
- [ ] #11245  Also should be done in a separate PR (as it needs the above index)

### Main change 1: Group policy proto defs have `voting_period` and `min_execution_period`

For group policies:

```diff
- // Within this times votes and exec messages can be submitted.
- // timeout is the duration from submission of a proposal to the end of voting period
- google.protobuf.Duration timeout = 2 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false];

+  // voting_period is the duration from submission of a proposal to the end of voting period
+  // Within this times votes can be submitted with MsgVote.
+  google.protobuf.Duration voting_period = 2 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false];

+  // min_execution_period is the minimum duration after the proposal submission
+  // where members can start sending MsgExec. This means that the window for
+  // sending a MsgExec transaction is:
+  // `[ submission + min_execution_period ; submission + voting_period + max_execution_period]`
+  // where max_execution_period is a app-specific config, defined in the keeper.
+  // If not set, min_execution_period will default to 0.
+  google.protobuf.Duration min_execution_period = 3 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false];
```

### Main Change 2: We don't update proposal's FinalTallyResult result on MsgVote/MsgSubmitProposal

Unless the msg has TryExec set to true, in which case the FinalTallyResult is updated ONLY if the tally is final.

### Main Change 3: Add a keeper-level `MaxExecutionPeriod`

MsgExecs will be rejected if they are sent after `voting_period_end + MaxExecutionPeriod`



---

### 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](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] 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](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) 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)
  • Loading branch information
amaury1093 authored Mar 2, 2022
1 parent 26c9a2d commit da36c46
Show file tree
Hide file tree
Showing 27 changed files with 1,933 additions and 739 deletions.
7 changes: 3 additions & 4 deletions api/cosmos/app/v1alpha1/module.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions api/cosmos/base/snapshots/v1beta1/snapshot.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1,267 changes: 933 additions & 334 deletions api/cosmos/group/v1beta1/types.pulsar.go

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions api/cosmos/orm/module/v1alpha1/module.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions api/cosmos/orm/v1alpha1/orm.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions api/cosmos/orm/v1alpha1/schema.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 30 additions & 11 deletions proto/cosmos/group/v1beta1/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ message ThresholdDecisionPolicy {
// threshold is the minimum weighted sum of yes votes that must be met or exceeded for a proposal to succeed.
string threshold = 1;

// timeout is the duration from submission of a proposal to the end of voting period
// Within this times votes and exec messages can be submitted.
google.protobuf.Duration timeout = 2 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false];
// windows defines the different windows for voting and execution.
DecisionPolicyWindows windows = 2;
}

// PercentageDecisionPolicy implements the DecisionPolicy interface
Expand All @@ -53,9 +52,28 @@ message PercentageDecisionPolicy {
// percentage is the minimum percentage the weighted sum of yes votes must meet for a proposal to succeed.
string percentage = 1;

// timeout is the duration from submission of a proposal to the end of voting period
// Within these times votes and exec messages can be submitted.
google.protobuf.Duration timeout = 2 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false];
// windows defines the different windows for voting and execution.
DecisionPolicyWindows windows = 2;
}

// DecisionPolicyWindows defines the different windows for voting and execution.
message DecisionPolicyWindows {
// voting_period is the duration from submission of a proposal to the end of voting period
// Within this times votes can be submitted with MsgVote.
google.protobuf.Duration voting_period = 1 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false];

// min_execution_period is the minimum duration after the proposal submission
// where members can start sending MsgExec. This means that the window for
// sending a MsgExec transaction is:
// `[ submission + min_execution_period ; submission + voting_period + max_execution_period]`
// where max_execution_period is a app-specific config, defined in the keeper.
// If not set, min_execution_period will default to 0.
//
// Please make sure to set a `min_execution_period` that is smaller than
// `voting_period + max_execution_period`, or else the above execution window
// is empty, meaning that all proposals created with this decision policy
// won't be able to be executed.
google.protobuf.Duration min_execution_period = 2 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false];
}

// VoteOption enumerates the valid vote options for a given proposal.
Expand Down Expand Up @@ -184,11 +202,12 @@ message Proposal {
// has ended.
TallyResult final_tally_result = 10 [(gogoproto.nullable) = false];

// timeout is the timestamp before which both voting and execution must be
// done. If this timestamp is passed, then the proposal cannot be executed
// anymore and should be considered pending delete. This timestamp is checked
// against the block header's timestamp.
google.protobuf.Timestamp timeout = 11 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
// voting_period_end is the timestamp before which voting must be done.
// Unless a successfull MsgExec is called before (to execute a proposal whose
// tally is successful before the voting period ends), tallying will be done
// at this point, and the `final_tally_result`, as well
// as `status` and `result` fields will be accordingly updated.
google.protobuf.Timestamp voting_period_end = 11 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];

// executor_result is the final result based on the votes and election rule. Initial value is NotRun.
ProposalExecutorResult executor_result = 12;
Expand Down
2 changes: 1 addition & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func NewSimApp(

app.AuthzKeeper = authzkeeper.NewKeeper(keys[authzkeeper.StoreKey], appCodec, app.msgSvcRouter, app.AccountKeeper)

groupConfig := groupkeeper.DefaultConfig()
groupConfig := group.DefaultConfig()
/*
Example of setting group params:
groupConfig.MaxMetadataLen = 1000
Expand Down
10 changes: 6 additions & 4 deletions snapshots/types/snapshot.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions types/tx/service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit da36c46

Please sign in to comment.