mirror of
https://github.com/Routstr/routstr-core.git
synced 2026-08-09 02:54:37 +00:00
The previous in-memory deduction (key.balance -= cost) was a read-modify- write on stale state, allowing two concurrent create_child_key() calls to both pass the balance check and both succeed, effectively charging the parent only once for two child keys. Replace with an atomic UPDATE ... WHERE balance - reserved_balance >= cost and check rowcount, matching the pattern already used in pay_for_request. Also adds a concurrent integration test that reproduces the race and confirms the fix holds. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>