[Regression on closed #273] assignReward's double-payout guard is keyed on (pool, recipient) instead of (pool, issue) — the same issue can still be paid twice
Maintainers usually reply within 1 day
@MrOmale is already working on this.
Since Oct 21, 2026.
Assessment
This issue has not been assessed yet.
Description
Problem
#273 ("no guard against being called twice for the same issueId") was closed with this check in MaintenancePoolService.assignReward():
// Guard against double/triple payout for the same issue (#273).
const existingPayment = await this.paymentRepo.findOne({
where: { recipientId: recipientId ?? null },
});
const existingPoolPayment = await this.paymentRepo
.createQueryBuilder('payment')
.innerJoin('payment.escrow', 'escrow')
.where('escrow.maintenancePoolId = :poolId', { poolId: id })
.andWhere('payment.recipientId = :recipientId', { recipientId: recipientId ?? null })
.getOne();
if (existingPoolPayment) {
throw new ConflictException(`Issue ${issueId} has already received a reward from pool ${id}`);
}
issueId doesn't appear in either query, and Payment has no issue column at all. The guard checks who was paid from this pool, not which issue was rewarded:
- The same issue can still be paid twice. Call
assignReward(pool, issue#1, …, recipientA)and thenassignReward(pool, issue#1, …, recipientB), and both succeed. This is the double payout #273 asked to prevent. - Anonymous payouts are never guarded. When
recipientIdis omitted, the query becomespayment.recipientId = NULL, which is never true in SQL. So repeated rewards for the same issue with norecipientIdalways pass. - Legitimate rewards are rejected. A maintainer who fixes two different maintenance issues gets a 409 on the second one, with a misleading message saying that issue was already rewarded.
existingPaymentis dead code. It's an unscoped query across every payment in the system, whose result is never read, and it costs an extra DB round trip per call.
Suggested fix
- Record the rewarded issue on the payment, for example a nullable
Payment.maintenanceIssueId(FK toissues), plus a unique index on(escrowId, maintenanceIssueId). - Guard on
(pool escrow, issueId), and let the unique index close the concurrent-call race. - Remove the unused
existingPaymentquery. - Add tests: the same issue with two recipients gets a 409, and two issues for the same recipient both succeed.
Related: #273, #274, #276.
- Dominant language
- TypeScript
- Stars
- 2
- Forks
- 90
- Avg merge
- 31m
- Merged PRs (30d)
- 20
Getting set up
- Ships a Dockerfile or Docker Compose file
- No pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from MergeFi/backend
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
bug security
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
bug testing
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
bug security
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
zapcooking/frontend#946 ·
Maintainers usually reply within 1 day
-
enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
WiliamRosa/cosmos-semantic-platform#40 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
liberation-data/drivine#733 · 1 comment ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
makecindy/cindy#10062 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day