#44 release() and splitRelease() never check for pre-existing Payment rows, so calling them after releasePartial causes a double payout of the full escrow amount FIXED - #87
Conversation
release() and splitRelease() never check for pre-existing Payment rows, so calling them after releasePartial causes a double payout of the full escrow amount FIXED
|
@Kappa16 is attempting to deploy a commit to the chonilius' projects Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
|
fix ci |
Author
|
OK |
Author
|
@chonilius DONE |
Author
|
@chonilius PLS maintainers, after reviewing this contribution. If possible, please consider issuing payment through GrantFox, or otherwise consider me for a contributor payment. This support would be greatly appreciated and would help keep me motivated to continue contributing to the project. Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CLOSE #44
Findings
The root cause was in
src/escrow/escrow.service.ts:release()checked only whether the escrow wasLOCKED.splitRelease()also checked only whether the escrow wasLOCKED.releasePartial()createsPaymentrecords but intentionally keeps the escrowLOCKEDuntil the full amount is distributed.The second call could release the full escrow amount again, producing an overpayment.
The original code also had a read-then-write race condition: concurrent release requests could both read the same payment history before either request inserted a new
Payment.Fix Features
Payment-history protection for
release()release()now rejects when the escrow already has one or morePaymentrows.Payment-history protection for
splitRelease()splitRelease()now applies the same protection and rejects instead of paying the full escrow again.Protection for
releasePartial()after full releaseA full release changes the escrow status to
RELEASED.releasePartial()rejects non-LOCKEDescrows, preventing partial release after a full or split release.Shared transaction lock
All release-family operations now use a shared locking helper:
It:
pessimistic_write.TOCTOU protection
The same locking mechanism is used consistently by:
release()splitRelease()releasePartial()This prevents concurrent requests from using the same stale payment-history snapshot.
No duplicate chain invocation
If a prior payment exists, the request is rejected before calling:
Regression coverage
Tests now cover:
The issue is resolved using the documented behavior that full and split releases are rejected whenever an escrow has existing payment history.