diff --git a/cashu/mint/db/write.py b/cashu/mint/db/write.py index 13d8445d..42a602e0 100644 --- a/cashu/mint/db/write.py +++ b/cashu/mint/db/write.py @@ -181,16 +181,16 @@ async def _set_melt_quote_pending(self, quote: MeltQuote) -> MeltQuote: quote_copy = quote.copy() async with self.db.get_connection( lock_table="melt_quotes", - lock_select_statement=f"checking_id='{quote.checking_id}'", + lock_select_statement=f"quote='{quote.quote}'", ) as conn: # get melt quote from db and check if it is already pending quote_db = await self.crud.get_melt_quote( - checking_id=quote.checking_id, db=self.db, conn=conn + quote_id=quote.quote, db=self.db, conn=conn ) if not quote_db: raise TransactionError("Melt quote not found.") - # if quote_db.pending: - # raise TransactionError("Melt quote already pending.") + if quote_db.pending: + raise TransactionError("Melt quote already pending.") # set the quote as pending quote_copy.state = MeltQuoteState.pending await self.crud.update_melt_quote(quote=quote_copy, db=self.db, conn=conn) diff --git a/cashu/mint/ledger.py b/cashu/mint/ledger.py index df01cf21..a48bfc7d 100644 --- a/cashu/mint/ledger.py +++ b/cashu/mint/ledger.py @@ -626,7 +626,6 @@ async def melt_quote( mint_quote = await self.crud.get_mint_quote(request=request, db=self.db) if mint_quote: payment_quote = self.create_internal_melt_quote(mint_quote, melt_quote) - else: # not internal # verify that the backend supports mpp if the quote request has an amount @@ -894,7 +893,6 @@ async def melt( proofs, quote_id=melt_quote.quote ) previous_state = melt_quote.state - # Warning: _set_melt_quote_pending does NOT protect against race conditions (it does not throw an error) melt_quote = await self.db_write._set_melt_quote_pending(melt_quote) try: # if the melt corresponds to an internal mint, mark both as paid