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 six hours before the invoice was created. The slack
covers Wownero's block timestamp rules, so a genuine payment mined after
creation always counts.
This commit is contained in:
2026-11-18 15:38:01 -05:00
parent 4fdac75ba3
commit cafa8039de
4 changed files with 148 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
@@ -128,8 +129,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