diff --git a/.changeset/peering-settlement-attempts.md b/.changeset/peering-settlement-attempts.md new file mode 100644 index 000000000..4b698982c --- /dev/null +++ b/.changeset/peering-settlement-attempts.md @@ -0,0 +1,12 @@ +--- +"nostream": patch +--- + +fix(peering): count failed invoice settlements and alert once + +A paid peering invoice whose settlement rolls back is now retried with a +persisted attempt counter and last error. After +`peering.settlementFailureThreshold` failures (default 5), one +`peering.payment.failed` notification is enqueued for the operator, and the +invoice stays in the retry set. Duplicate callbacks and underpayments are not +counted. diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 302dd322e..b7523e37c 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -304,6 +304,7 @@ The settings below are listed in alphabetical order by name. Please keep this ta | peering.scopes[].since | Inclusive lower bound of the feed's time range as a unix timestamp in seconds. Omit for no lower bound. Mutually exclusive with `windowSeconds`. | | peering.scopes[].until | Inclusive upper bound of the feed's time range as a unix timestamp in seconds. Omit for a feed that stays current. Mutually exclusive with `windowSeconds`. | | peering.scopes[].windowSeconds | Rolling window in seconds: the feed covers the most recent `windowSeconds` of events. Mutually exclusive with `since` and `until`. | +| peering.settlementFailureThreshold | Failed settlement attempts before one operator alert is enqueued for a completed-but-unconfirmed paid peering invoice. The invoice is still retried. Defaults to 5. | | peering.terms[].amount | Fee amount charged per peering period, denominated in `unit`. | | peering.terms[].period | Peering period in seconds. | | peering.terms[].unit | Fee unit (for example `msats`). An empty `terms` list means settlement-free peering. | diff --git a/docs/PEERING.md b/docs/PEERING.md index 9d1715c08..fd7ddaeeb 100644 --- a/docs/PEERING.md +++ b/docs/PEERING.md @@ -266,7 +266,16 @@ The invoice travels over the authenticated relay connection: An expired invoice is retired and reissued on request after a short cooldown. Before denying access, the relay rechecks a pending invoice with the processor, -so a missed webhook heals on its own. A peer can always authenticate and ask for +so a missed webhook heals on its own. + +A completed peering invoice whose settlement transaction rolled back stays +retryable. Every failed settlement increments `settlement_attempts` and stores +`last_settlement_error` on the invoice; the maintenance worker keeps retrying. +After `peering.settlementFailureThreshold` failures (default 5), the relay +enqueues one `peering.payment.failed` operator notification and keeps retrying. +Duplicate callbacks and underpayments are not counted as settlement failures. +Only completed invoices that are still unconfirmed are counted; a pending row +checked through the processor recheck path stays on the pending page. A peer can always authenticate and ask for its invoice, even while lapsed, but cannot read the feed. Billing state is stored in `peering_payments`, one row per peer and direction diff --git a/migrations/20261127_120000_add_invoice_settlement_attempts.js b/migrations/20261127_120000_add_invoice_settlement_attempts.js new file mode 100644 index 000000000..8a78921a5 --- /dev/null +++ b/migrations/20261127_120000_add_invoice_settlement_attempts.js @@ -0,0 +1,17 @@ +exports.up = async function (knex) { + await knex.schema.alterTable('invoices', (table) => { + table.integer('settlement_attempts').notNullable().defaultTo(0) + table.text('last_settlement_error').nullable() + table.timestamp('last_settlement_attempt_at', { useTz: true }).nullable() + table.timestamp('settlement_alerted_at', { useTz: true }).nullable() + }) +} + +exports.down = async function (knex) { + await knex.schema.alterTable('invoices', (table) => { + table.dropColumn('settlement_alerted_at') + table.dropColumn('last_settlement_attempt_at') + table.dropColumn('last_settlement_error') + table.dropColumn('settlement_attempts') + }) +} diff --git a/resources/admin/assets/notifications.js b/resources/admin/assets/notifications.js index bf0ed61ab..13c8d1ddc 100644 --- a/resources/admin/assets/notifications.js +++ b/resources/admin/assets/notifications.js @@ -61,6 +61,7 @@ 'peering.invoice.created': true, 'peering.invoice.paid': true, 'peering.invoice.failed': true, + 'peering.payment.failed': true, 'peering.access.lapsed': true, 'settings.changed': true, 'relay.restarted': false, diff --git a/resources/admin/dashboard.html b/resources/admin/dashboard.html index 50950decb..3f89febe6 100644 --- a/resources/admin/dashboard.html +++ b/resources/admin/dashboard.html @@ -468,6 +468,12 @@