assignReward decrements MaintenancePool.balance before poolWithdraw() and never restores it when the withdrawal fails
维护者通常 1 天内回复
评估
这个 Issue 还没有评估数据。
描述
Problem
In MaintenancePoolService.assignReward(), the #274 atomic check-and-decrement runs before the on-chain payout:
const updateResult = await this.poolRepo
.createQueryBuilder()
.update(MaintenancePool)
.set({ balance: () => `balance - :amount` })
.where('id = :id AND balance >= :amount', { id, amount: Number(amount) })
...
.execute();
if (updateResult.affected === 0) throw new BadRequestException(...);
const payment = await this.escrowService.poolWithdraw(pool.escrowId, amount, recipientAddress, recipientId);
return payment;
poolWithdraw() has several ways to throw after the balance has already been reduced:
assertLocked(escrow)assertValidAmount(amount)assertRecipientsMatchUsers(...): arecipientAddressthat doesn't matchrecipientId's wallet- a Soroban simulate, send or poll failure inside
invokeOnLockedEscrow - the final
paymentRepo.save
None of these paths gives the reserved amount back, so every failed reward permanently shrinks the pool's DB balance, even though no USDC left the contract. Over time MaintenancePool.balance drifts below the real on-chain balance. Rewards then start failing with "exceeds pool balance" while funds are still in escrow, and there's no admin path to reconcile.
Suggested fix
- Wrap the payout in try/catch. On failure, restore the reservation with
increment({ id }, 'balance', Number(amount))and rethrow. - Only do that when the on-chain call is known not to have gone through.
invokeOnLockedEscrow's state distinguishes "never submitted" from "submitted, outcome unknown". - Move the cheap validation (recipient/user match, amount) before the decrement so bad input never touches the balance.
- Add tests with
poolWithdrawrejecting that assert the pool balance is unchanged.
Related: #51, #274 (introduced the reserve-first ordering), #163.
- 主要语言
- TypeScript
- 星标
- 2
- 派生
- 90
- 平均合并
- 31 分钟
- 30 天内合并 PR
- 20
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
MergeFi/backend 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
bug security
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
bug testing
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
bug security
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
相似的 Issue
-
Codex使用可 コード
难度 2/5 1-3 小时 新手友好度 72/100
ryuki-moro/Nicomaru#218 ·
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
sveltejs/svelte-eslint-parser#1008 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
silverbucket/inbox-rs#351 ·
维护者通常 1 天内回复
-
[Bug]: The H2 series' and the H3C's fan 3 is labelled "Chamber Fan", Bambu calls it the exhaust fan未关闭area:ui
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
bug front P2
难度 2/5 1-3 小时 新手友好度 86/100
invoicerr-app/invoicerr#964 ·
维护者通常 1 天内回复