Skip to content

fix: poll on-chain balances periodically and persist before webhook - #91

Open
dadofsambonzuki wants to merge 1 commit into
lnbits:mainfrom
dadofsambonzuki:fix/onchain-payment-poll
Open

dadofsambonzuki wants to merge 1 commit into
lnbits:mainfrom
dadofsambonzuki:fix/onchain-payment-poll

Conversation

@dadofsambonzuki

Copy link
Copy Markdown

Summary

Recovers on-chain charge payments that currently only get detected via the mempool websocket push feed.

restart_address_tracking() only ran once at extension startup. If websocket tracking broke after that (for example once the number of tracked addresses hit mempool's per-connection limit and track-addresses started being rejected), on-chain payments were never detected until the next process restart. Each new charge then grew the rejected tracking list further, so the failure was permanent.

This PR converts that one-shot pass into a permanent periodic REST balance poll and hardens the settlement/webhook path:

  • tasks.py – restart_address_tracking() now loops on a 120s cadence for the lifetime of the process, isolates per-charge errors, and drops paid and expired addresses from the websocket tracking list each pass so the list stays under mempool's per-connection address cap.
  • helpers.py – check_charge_balance() now persists the settled charge before firing the webhook (mirroring tasks._handle_ws_message), so webhook handlers that re-fetch the charge (e.g. GET /satspay/api/v1/charge/{id}) observe it as paid. The webhook now fires only when a charge becomes paid, instead of on every balance check (which previously pinged the webhook endpoint on every poll of unpaid charges).
  • init.py – registers the poll with create_permanent_unique_task (auto-restarts on failure) and includes it in scheduled_tasks so satspay_stop() cancels it.

Note

This is a stopgap for the public mempool.space feed. #88 (feat: use blockexplorer) supersedes this by moving on-chain tracking to a local block explorer.

On-chain payment detection relied entirely on the mempool websocket push feed. When tracking breaks (e.g. the per-connection tracked-address limit is exceeded) payments were only detected at the next process restart. Run the existing restart_address_tracking() as a permanent periodic task so balances are re-checked by REST as a fallback.

- tasks.py: restart_address_tracking() now loops on a 120s cadence, isolates per-charge errors, and drops paid/expired addresses from websocket tracking so the list stays under mempool's per-connection address cap.
- helpers.py: check_charge_balance() persists the settled charge before firing the webhook so handlers that re-fetch the charge (e.g. GET /satspay/api/v1/charge/{id}) observe it as paid, mirroring tasks._handle_ws_message(). The webhook now fires only when a charge becomes paid instead of on every balance check.
- __init__.py: register the poll with create_permanent_unique_task so it auto-restarts, and include it in scheduled_tasks so satspay_stop() cancels it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant