Fix SQLite race condition

Bug: https://github.com/crodas/cdk/actions/runs/15732950296/job/44339804072#step:5:1853

Reason: When melting in parallel, many update the melt status and attempt to
add proofs and they fail when adding the proof and the rollback code kicks in.
The loser process removes all the proofs, and the winner process has no proof
later on.

Fix: Modify `update_melt_quote_state` requirements and implementation to allow
only one winner.

This will be solved by design with a transaction writer trait
This commit is contained in:
Cesar Rodas
2025-06-18 16:20:24 -03:00
parent 37f9d9122b
commit a681c6e054
2 changed files with 5 additions and 1 deletions

View File

@@ -696,9 +696,11 @@ ON CONFLICT(request_lookup_id) DO UPDATE SET
melt_quote
WHERE
id=:id
AND state != :state
"#,
)
.bind(":id", quote_id.as_hyphenated().to_string())
.bind(":state", state.to_string())
.fetch_one(&transaction)
.await?
.map(sqlite_row_to_melt_quote)