Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prune stale x/foundation proposals at voting period end #730

Merged
merged 4 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/staking) [\#726](https://github.com/line/lbm-sdk/pull/726) check allowedList size in StakeAuthorization.Accept()
* (x/staking) [\#728](https://github.com/line/lbm-sdk/pull/728) fix typo in unbondingToUnbonded() panic
* (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 @@ -189,15 +189,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