📌 Description
SettlementRepository in src/repositories/settlementRepository.ts tracks nextId, reserved, and consumed liquidity in memory. Node's single-threaded event loop makes true races unlikely, but interleaved async handlers (e.g. two execute/cancel calls for the same id issued back-to-back) are not covered by settlementRepository.test.ts, and a bug here could double-release or double-consume reserved liquidity.
🧩 Requirements and context
- Add tests that fire
execute/cancel for the same settlement id from two concurrent promise chains and assert only one succeeds, the other gets a defined error (already-executed/already-cancelled).
- Assert reserved liquidity is released exactly once regardless of call ordering.
- Document the repository's concurrency assumptions (single in-process instance, no external locking) in a code comment.
🛠️ Suggested execution
- Extend
src/repositories/settlementRepository.test.ts with interleaved-call scenarios using Promise.all.
- If a real double-consume/double-release bug surfaces, fix it in
settlementRepository.ts and add a targeted regression test.
- Cross-check
src/services/settlementService.ts for any additional guard it relies on the repository to provide.
✅ Acceptance criteria
🔒 Security notes
Prevents a liquidity-accounting bug (double release) that could let more be withdrawn than was ever reserved.
📋 Guidelines
- Minimum 95% test coverage
- Clear documentation
- Timeframe: 96 hours
📌 Description
SettlementRepositoryinsrc/repositories/settlementRepository.tstracksnextId, reserved, and consumed liquidity in memory. Node's single-threaded event loop makes true races unlikely, but interleaved async handlers (e.g. twoexecute/cancelcalls for the same id issued back-to-back) are not covered bysettlementRepository.test.ts, and a bug here could double-release or double-consume reserved liquidity.🧩 Requirements and context
execute/cancelfor the same settlement id from two concurrent promise chains and assert only one succeeds, the other gets a defined error (already-executed/already-cancelled).🛠️ Suggested execution
src/repositories/settlementRepository.test.tswith interleaved-call scenarios usingPromise.all.settlementRepository.tsand add a targeted regression test.src/services/settlementService.tsfor any additional guard it relies on the repository to provide.✅ Acceptance criteria
🔒 Security notes
Prevents a liquidity-accounting bug (double release) that could let more be withdrawn than was ever reserved.
📋 Guidelines