Skip to content

Commit

Permalink
block pending melt quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Sep 24, 2024
1 parent 8430409 commit 08eac15
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 4 additions & 4 deletions cashu/mint/db/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions cashu/mint/ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 08eac15

Please sign in to comment.