fix(payments): never reuse a subaddress or count older payments toward an invoice

Subaddress indices wrapped after 300 invoices per merchant, and the
reconciler counted every transfer ever received on the subaddress. A later
invoice could therefore show as paid by an earlier invoice's payment.

Indices now only increase, and the reconciler counts only transfers whose
timestamp is no more than two hours before the invoice was created. The slack
covers Monero's block timestamp rules, so a genuine payment mined after
creation always counts.
This commit is contained in:
2026-11-18 15:37:34 -05:00
parent b44181d8d9
commit bdacfd278f
4 changed files with 149 additions and 12 deletions
+4 -2
View File
@@ -12,6 +12,7 @@ from sqlalchemy.orm import Session
from .btcpay_webhooks import dispatch_btcpay_webhooks
from .config import INVOICE_RECONCILE_INTERVAL_SECONDS, LATE_PAYMENT_LOOKBACK_HOURS
from .db import SessionLocal
from .invoice_transfers import transfers_for_invoice
from .models import Invoice, InvoiceTransfer, SystemStatus, User
from .monero_service import MoneroWalletService, TransferDetail
from .webhooks import dispatch_webhooks
@@ -127,8 +128,9 @@ def _reconcile_invoices(service: MoneroWalletService) -> None:
if not acquired:
continue
try:
transfers = _get_transfers_with_retry(
service, user, invoice.address,
transfers = transfers_for_invoice(
_get_transfers_with_retry(service, user, invoice.address),
invoice.created_at,
)
total_atomic = 0