diff options
| author | Adam Soltys <[email protected]> | 2026-07-31 23:22:41 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-07-31 23:22:41 -0700 |
| commit | 733929010b0ec96a580c65b69345a854e0112611 (patch) | |
| tree | 00f89a62a92816826f46ca5dc1c7ca0c7eb1a215 /lib/utils.ts | |
| parent | 974c9cae7e11ffafdc571af0f9c47d896a901131 (diff) | |
| download | coinos-server-733929010b0ec96a580c65b69345a854e0112611.tar.gz coinos-server-733929010b0ec96a580c65b69345a854e0112611.zip | |
take: claim single-use authorizations atomically (COINOS-3)
take() enforced single-use by reading authorization.claimed, checking it,
then writing it back — with yielding awaits in between and no lock. N
concurrent POST /take for one authorization all passed the gate, so each
debited the authorizer and funded the pool. Verified on regtest: 10
concurrent takes redeemed one 10,000 sat single-use authorization 5
times (50,000 debited from the authorizer, 50,000 credited to the
caller). With the SET NX claim, exactly one wins.
Funding also runs inside a try that releases the claim on failure and
only marks the record claimed once the money has landed — otherwise a
funding that throws (insufficient balance, server limit) burns the
authorization: claim key set, fund never funded, every later take
skipping the funding block.
Reported-by: Muhammed Shekho (@SYR-ROOT) <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]>
Diffstat (limited to 'lib/utils.ts')
0 files changed, 0 insertions, 0 deletions
