Skip to content

Commit 3075ac4

Browse files
authored
Read the latest mint quote status in a transaction to avoid race conditions (#1166)
* Read the latest mint quote status in a transaction to avoid race conditions Fixes #1162 * Reload quote for all cases * Exit on paid invoices only for bolt11
1 parent cae8768 commit 3075ac4

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

crates/cdk/src/mint/ln.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ impl Mint {
4545

4646
let mut tx = self.localstore.begin_transaction().await?;
4747

48+
// reload the quote, as it state may have changed
49+
*quote = tx
50+
.get_mint_quote(&quote.id)
51+
.await?
52+
.ok_or(Error::UnknownQuote)?;
53+
54+
let current_state = quote.state();
55+
56+
if quote.payment_method == PaymentMethod::Bolt11
57+
&& (current_state == MintQuoteState::Issued || current_state == MintQuoteState::Paid)
58+
{
59+
return Ok(());
60+
}
61+
4862
for payment in ln_status {
4963
if !quote.payment_ids().contains(&&payment.payment_id)
5064
&& payment.payment_amount > Amount::ZERO

0 commit comments

Comments
 (0)