fix: make fund locking atomic#127
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the fund locking mechanism to prevent race conditions and ensure idempotency under concurrent execution. Specifically, it modifies lock_output to verify that exactly one row was updated, returning an error if the output is no longer unspent. It also updates FundLocker::lock to initiate an immediate transaction earlier in the function, ensuring that idempotency checks and UTXO selection occur within the same transaction. Finally, concurrent unit tests are added to verify these behaviors. There are no review comments, so I have no feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
SWvheerden
left a comment
There was a problem hiding this comment.
I dont like this approach, ideally you should allow multiple lookups without locking all, and you can more grafully handleing the locking
Summary
Closes #125.
This fixes the UTXO locking race by moving the idempotency lookup, UTXO selection, pending transaction creation, and output locking into one
BEGIN IMMEDIATESQLite transaction. That keeps the critical section enforced by the wallet database instead of a process-global mutex.It also makes
lock_output()fail if the selected output is no longerUNSPENT, so a stale selection cannot silently produce a pending transaction without actually locking the output.Bounty
This PR is submitted for the open #125 bounty: Tier S, 15,000 XTM, first merged PR wins, payment after merge. Payout details can be provided through the maintainer-approved flow if this PR is selected.
Tests
Using stable Rust 1.96.0 because current Tari dependencies require rustc >= 1.93.0:
cargo fmt --all -- --checkcargo test -p minotari transactions::fund_locker -- --nocapturecargo test -p minotari db::outputs -- --nocapturecargo check -p minotaricargo test -p minotari --lib --binscargo test -p minotari --doccargo clippy -p minotari --all-targets -- -D warnings