Skip to content

peering: retry serialization failures (40001) in invoice settlement #1154

Open

Description

@Ferryx349

Follow-up from the re-review of #1088.

Problem

Peering settlement runs inside a serializable transaction
(src/database/transaction.ts), but neither the callback path nor the worker
retry path handles PostgreSQL 40001 (serialization_failure).

  1. confirmInvoice (src/services/payments-service.ts) begins a serializable transaction that updates the invoice and the peering row.
  2. A concurrent writer can abort it with SQLSTATE 40001.
  3. Nothing retries the transaction. The error propagates, so the callback reports failure even though the payment is valid.
  4. Access is eventually recovered: findUnconfirmedPeeringInvoices (src/repositories/invoice-repository.ts) finds the completed invoice with confirmed_at = null, and the maintenance worker retries it on a later pass.

Recovery keeps the peer from being stranded, but the immediate check fails and settlement latency depends on the next maintenance pass.

Expected

A bounded retry on serialization conflicts, without retrying deterministic failures (missing peer row, missing term snapshot, underpayment).

Activity

  1. self-assigned this
    on Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingpeering

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions