Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Await agreement locks #3347

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading