Skip to content

Commit

Permalink
change quorumCheckTimestamps to simpler quorumChecksDone counter
Browse files Browse the repository at this point in the history
  • Loading branch information
giunatale committed Jul 20, 2023
1 parent 0724a1a commit f7a24c6
Show file tree
Hide file tree
Showing 8 changed files with 314 additions and 440 deletions.
473 changes: 189 additions & 284 deletions api/cosmos/gov/v1/gov.pulsar.go

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions proto/cosmos/gov/v1/gov.proto
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,8 @@ message QuorumCheckQueueEntry {
// proposal is initially added to the queue.
uint64 quorum_check_count = 2;

// quorum_check_timestamps is a list of times when quorum checks have been done.
// any entry in this list corresponds to a time when quorum was checked and
// not reached, since proposal would be removed from queue otherwise.
repeated google.protobuf.Timestamp quorum_check_timestamps = 3 [(gogoproto.stdtime) = true];
// quorum_checks_done is the number of quorum checks that have been done.
uint64 quorum_checks_done = 3;
}

// DepositParams defines the params for deposits on governance proposals.
Expand Down
7 changes: 3 additions & 4 deletions x/gov/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func EndBlocker(ctx sdk.Context, keeper *keeper.Keeper) error {
if quorum {
logMsg = "proposal passed quorum before timeout, vote period was not extended"
tagValue = types.AttributeValueProposalQuorumMet
if len(quorumCheckEntry.QuorumCheckTimestamps) > 0 {
if quorumCheckEntry.QuorumChecksDone > 0 {
// proposal passed quorum after timeout, extend voting period.
// canonically, we consider the first quorum check to be "right after" the quorum timeout has elapsed,
// so if quorum is reached at the first check, we don't extend the voting period.
Expand All @@ -129,7 +129,7 @@ func EndBlocker(ctx sdk.Context, keeper *keeper.Keeper) error {
}
}
}
} else if uint64(len(quorumCheckEntry.QuorumCheckTimestamps)) < quorumCheckEntry.QuorumCheckCount && proposal.VotingEndTime.After(ctx.BlockTime()) {
} else if quorumCheckEntry.QuorumChecksDone < quorumCheckEntry.QuorumCheckCount && proposal.VotingEndTime.After(ctx.BlockTime()) {
// proposal did not pass quorum and is still active, add back to queue with updated time key and counter.
// compute time interval between quorum checks
quorumCheckPeriod := proposal.VotingEndTime.Sub(*quorumCheckEntry.QuorumTimeoutTime)
Expand All @@ -146,8 +146,7 @@ func EndBlocker(ctx sdk.Context, keeper *keeper.Keeper) error {
// next quorum check time is after the voting period ends, so adjust it to be equal to the voting period end time
nextQuorumCheckTime = *proposal.VotingEndTime
}
lastQuorumCheckTime := key.K1()
quorumCheckEntry.QuorumCheckTimestamps = append(quorumCheckEntry.QuorumCheckTimestamps, &lastQuorumCheckTime)
quorumCheckEntry.QuorumChecksDone++
err = keeper.QuorumCheckQueue.Set(ctx, collections.Join(nextQuorumCheckTime, proposal.Id), quorumCheckEntry)
if err != nil {
return false, err
Expand Down
10 changes: 4 additions & 6 deletions x/gov/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ func InitGenesis(ctx sdk.Context, ak types.AccountKeeper, bk types.BankKeeper, k
if err != nil {
panic(err)
}
if data.Params.QuorumCheckCount > 0 &&
!proposal.Expedited &&
proposal.Status == v1.StatusVotingPeriod {
if data.Params.QuorumCheckCount > 0 && !proposal.Expedited && proposal.Status == v1.StatusVotingPeriod {
quorumTimeoutTime := proposal.VotingStartTime.Add(*data.Params.QuorumTimeout)
quorumCheckEntry := v1.NewQuorumCheckQueueEntry(quorumTimeoutTime, data.Params.QuorumCheckCount)
quorum := false
Expand All @@ -85,9 +83,9 @@ func InitGenesis(ctx sdk.Context, ak types.AccountKeeper, bk types.BankKeeper, k
}
if !quorum {
// since we don't export the state of the quorum check queue, we can't know how many checks were actually
// done. However, in order to trigger a vote time extension, it is enough to have at least one item
// in quorumCheckEntry.QuorumCheckTimestamps, which we canonically set to be the quorumTimeoutTime
quorumCheckEntry.QuorumCheckTimestamps = append(quorumCheckEntry.QuorumCheckTimestamps, &quorumTimeoutTime)
// done. However, in order to trigger a vote time extension, it is enough to have QuorumChecksDone > 0 to
// trigger a vote time extension, so we set it to 1
quorumCheckEntry.QuorumChecksDone = 1
}
}
if !quorum {
Expand Down
1 change: 1 addition & 0 deletions x/gov/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func TestInitGenesis(t *testing.T) {
assert := assert.New(t)
require := require.New(t)
params, err := s.GovKeeper.Params.Get(ctx)
require.NoError(err)
it, err := s.GovKeeper.Proposals.Iterate(ctx, nil)
require.NoError(err)
proposals, err := it.Values()
Expand Down
2 changes: 1 addition & 1 deletion x/gov/keeper/proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (suite *KeeperTestSuite) TestActivateVotingPeriod() {
suite.Require().NoError(err)
suite.Require().EqualValues(quorumTimeoutTime, *quorumCheckEntry.QuorumTimeoutTime)
suite.Require().EqualValues(params.QuorumCheckCount, quorumCheckEntry.QuorumCheckCount)
suite.Require().Empty(quorumCheckEntry.QuorumCheckTimestamps)
suite.Require().Zero(quorumCheckEntry.QuorumChecksDone)
} else {
suite.Require().False(hasQuorumCheck)
}
Expand Down
Loading

0 comments on commit f7a24c6

Please sign in to comment.