Skip to content

Commit

Permalink
fix: prune stale x/foundation proposals at voting period end (#730)
Browse files Browse the repository at this point in the history
* Update pruning logic

* Update CHANGELOG.md
  • Loading branch information
0Tech authored Oct 19, 2022
1 parent d48d8a7 commit b13ab12
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/staking) [\#728](https://github.com/line/lbm-sdk/pull/728) fix typo in unbondingToUnbonded() panic
* (crypto) [\#731](https://github.com/line/lbm-sdk/pull/731) remove VRFProve function
* (x/foundation) [\#732](https://github.com/line/lbm-sdk/pull/732) add verification on accounts into x/foundation Grants cli
* (x/foundation) [\#730](https://github.com/line/lbm-sdk/pull/730) prune stale x/foundation proposals at voting period end

### Breaking Changes
* (proto) [\#564](https://github.com/line/lbm-sdk/pull/564) change gRPC path to original cosmos path
Expand Down
25 changes: 15 additions & 10 deletions x/foundation/keeper/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,32 @@ func (s *KeeperTestSuite) TestEndBlocker() {
keeper.EndBlocker(ctx, s.keeper)

for name, tc := range map[string]struct {
id uint64
status foundation.ProposalStatus
id uint64
removed bool
status foundation.ProposalStatus
}{
"active proposal": {
s.activeProposal,
foundation.PROPOSAL_STATUS_ACCEPTED,
id: s.activeProposal,
status: foundation.PROPOSAL_STATUS_ACCEPTED,
},
"voted proposal": {
s.votedProposal,
foundation.PROPOSAL_STATUS_REJECTED,
id: s.votedProposal,
status: foundation.PROPOSAL_STATUS_REJECTED,
},
"withdrawn proposal": {
s.withdrawnProposal,
foundation.PROPOSAL_STATUS_WITHDRAWN,
id: s.withdrawnProposal,
removed: true,
},
"invalid proposal": {
s.invalidProposal,
foundation.PROPOSAL_STATUS_ACCEPTED,
id: s.invalidProposal,
status: foundation.PROPOSAL_STATUS_ACCEPTED,
},
} {
proposal, err := s.keeper.GetProposal(ctx, tc.id)
if tc.removed {
s.Require().Error(err, name)
continue
}
s.Require().NoError(err, name)
s.Require().NotNil(proposal, name)
s.Require().Equal(tc.status, proposal.Status, name)
Expand Down
18 changes: 14 additions & 4 deletions x/foundation/keeper/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,25 @@ func (k Keeper) iterateProposalsByVPEnd(ctx sdk.Context, endTime time.Time, fn f
}

func (k Keeper) UpdateTallyOfVPEndProposals(ctx sdk.Context) {
var proposals []foundation.Proposal
k.iterateProposalsByVPEnd(ctx, ctx.BlockTime(), func(proposal foundation.Proposal) (stop bool) {
proposals = append(proposals, proposal)
return false
})

for _, proposal := range proposals {
proposal := proposal

if proposal.Status == foundation.PROPOSAL_STATUS_ABORTED || proposal.Status == foundation.PROPOSAL_STATUS_WITHDRAWN {
k.pruneProposal(ctx, proposal)
continue
}

if err := k.doTallyAndUpdate(ctx, &proposal); err != nil {
panic(err)
}

k.setProposal(ctx, proposal)

return false
})
}
}

func (k Keeper) GetProposal(ctx sdk.Context, id uint64) (*foundation.Proposal, error) {
Expand Down

0 comments on commit b13ab12

Please sign in to comment.