Skip to content

Commit

Permalink
Merge pull request #3347 from golemfactory/fix-payment-synchronization
Browse files Browse the repository at this point in the history
Await agreement locks
  • Loading branch information
nieznanysprawiciel authored Oct 16, 2024
2 parents 990f9de + 31074bf commit 591328e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion core/payment/src/api/debit_notes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,14 @@ async fn accept_debit_note(
};

// Required to serialize complex DB access patterns related to debit note / invoice acceptances.
let _agreement_lock = agreement_lock.lock(debit_note.agreement_id.clone());
let _agreement_lock = agreement_lock.lock(debit_note.agreement_id.clone()).await;

// Query the DebitNote again. We waited under lock, so it could have changed in the meantime.
let debit_note: DebitNote = match dao.get(debit_note_id.clone(), node_id).await {
Ok(Some(debit_note)) => debit_note,
Ok(None) => return response::not_found(),
Err(e) => return response::server_error(&e),
};

if debit_note.total_amount_due != acceptance.total_amount_accepted {
return response::bad_request(&"Invalid amount accepted");
Expand Down
9 changes: 8 additions & 1 deletion core/payment/src/api/invoices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,14 @@ async fn accept_invoice(
};

// Required to serialize complex DB access patterns related to debit note / invoice acceptances.
let _agreement_lock = agreement_lock.lock(invoice.agreement_id.clone());
let _agreement_lock = agreement_lock.lock(invoice.agreement_id.clone()).await;

// Query the Invoice again. We waited under lock, so it could have changed in the meantime.
let invoice = match dao.get(invoice_id.clone(), node_id).await {
Ok(Some(invoice)) => invoice,
Ok(None) => return response::not_found(),
Err(e) => return response::server_error(&e),
};

if invoice.amount != acceptance.total_amount_accepted {
return response::bad_request(&"Invalid amount accepted");
Expand Down

0 comments on commit 591328e

Please sign in to comment.