Merge pull request #824 from crodas/fix/sqlite-race-condition

Fix SQLite race condition
This commit is contained in:
thesimplekid
2025-06-19 08:48:31 +01:00
committed by GitHub
2 changed files with 5 additions and 1 deletions

View File

@@ -84,10 +84,12 @@ pub trait QuotesDatabase {
/// Get [`mint::MeltQuote`]
async fn get_melt_quote(&self, quote_id: &Uuid) -> Result<Option<mint::MeltQuote>, Self::Err>;
/// Update [`mint::MeltQuote`] state
///
/// It is expected for this function to fail if the state is already set to the new state
async fn update_melt_quote_state(
&self,
quote_id: &Uuid,
state: MeltQuoteState,
new_state: MeltQuoteState,
) -> Result<(MeltQuoteState, mint::MeltQuote), Self::Err>;
/// Get all [`mint::MeltQuote`]s
async fn get_melt_quotes(&self) -> Result<Vec<mint::MeltQuote>, Self::Err>;

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)