Skip to content

Commit b13ab12

Browse files
authored
fix: prune stale x/foundation proposals at voting period end (#730)
* Update pruning logic * Update CHANGELOG.md
1 parent d48d8a7 commit b13ab12

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
110110
* (x/staking) [\#728](https://github.com/line/lbm-sdk/pull/728) fix typo in unbondingToUnbonded() panic
111111
* (crypto) [\#731](https://github.com/line/lbm-sdk/pull/731) remove VRFProve function
112112
* (x/foundation) [\#732](https://github.com/line/lbm-sdk/pull/732) add verification on accounts into x/foundation Grants cli
113+
* (x/foundation) [\#730](https://github.com/line/lbm-sdk/pull/730) prune stale x/foundation proposals at voting period end
113114

114115
### Breaking Changes
115116
* (proto) [\#564](https://github.com/line/lbm-sdk/pull/564) change gRPC path to original cosmos path

x/foundation/keeper/abci_test.go

+15-10
Original file line numberDiff line numberDiff line change
@@ -66,27 +66,32 @@ func (s *KeeperTestSuite) TestEndBlocker() {
6666
keeper.EndBlocker(ctx, s.keeper)
6767

6868
for name, tc := range map[string]struct {
69-
id uint64
70-
status foundation.ProposalStatus
69+
id uint64
70+
removed bool
71+
status foundation.ProposalStatus
7172
}{
7273
"active proposal": {
73-
s.activeProposal,
74-
foundation.PROPOSAL_STATUS_ACCEPTED,
74+
id: s.activeProposal,
75+
status: foundation.PROPOSAL_STATUS_ACCEPTED,
7576
},
7677
"voted proposal": {
77-
s.votedProposal,
78-
foundation.PROPOSAL_STATUS_REJECTED,
78+
id: s.votedProposal,
79+
status: foundation.PROPOSAL_STATUS_REJECTED,
7980
},
8081
"withdrawn proposal": {
81-
s.withdrawnProposal,
82-
foundation.PROPOSAL_STATUS_WITHDRAWN,
82+
id: s.withdrawnProposal,
83+
removed: true,
8384
},
8485
"invalid proposal": {
85-
s.invalidProposal,
86-
foundation.PROPOSAL_STATUS_ACCEPTED,
86+
id: s.invalidProposal,
87+
status: foundation.PROPOSAL_STATUS_ACCEPTED,
8788
},
8889
} {
8990
proposal, err := s.keeper.GetProposal(ctx, tc.id)
91+
if tc.removed {
92+
s.Require().Error(err, name)
93+
continue
94+
}
9095
s.Require().NoError(err, name)
9196
s.Require().NotNil(proposal, name)
9297
s.Require().Equal(tc.status, proposal.Status, name)

x/foundation/keeper/proposal.go

+14-4
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,25 @@ func (k Keeper) iterateProposalsByVPEnd(ctx sdk.Context, endTime time.Time, fn f
173173
}
174174

175175
func (k Keeper) UpdateTallyOfVPEndProposals(ctx sdk.Context) {
176+
var proposals []foundation.Proposal
176177
k.iterateProposalsByVPEnd(ctx, ctx.BlockTime(), func(proposal foundation.Proposal) (stop bool) {
178+
proposals = append(proposals, proposal)
179+
return false
180+
})
181+
182+
for _, proposal := range proposals {
183+
proposal := proposal
184+
185+
if proposal.Status == foundation.PROPOSAL_STATUS_ABORTED || proposal.Status == foundation.PROPOSAL_STATUS_WITHDRAWN {
186+
k.pruneProposal(ctx, proposal)
187+
continue
188+
}
189+
177190
if err := k.doTallyAndUpdate(ctx, &proposal); err != nil {
178191
panic(err)
179192
}
180-
181193
k.setProposal(ctx, proposal)
182-
183-
return false
184-
})
194+
}
185195
}
186196

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

0 commit comments

Comments
 (0)