Skip to content

fix: exponential backoff for preimage polling to avoid relay rate limiting#52

Open
dadofsambonzuki wants to merge 1 commit into
lnbits:mainfrom
dadofsambonzuki:fix-poll-rate-limiting
Open

fix: exponential backoff for preimage polling to avoid relay rate limiting#52
dadofsambonzuki wants to merge 1 commit into
lnbits:mainfrom
dadofsambonzuki:fix-poll-rate-limiting

Conversation

@dadofsambonzuki

Copy link
Copy Markdown

Problem

The preimage polling loop in _process_invoice checks check_transaction_status every 50ms (await asyncio.sleep(0.05)). When the LNbits instance uses an NWC wallet as its funding source, each poll triggers one or more WebSocket calls to the external relay, easily exceeding the relay's rate limit (~20 req/s). Once the relay activates its "pubkey flood" rate limiter, all traffic from the LNbits IP is blocked, including NWC client connections -- which then fail with "all promises were rejected" on the Alby side.

Fix

  • Increased initial polling interval from 50ms to 500ms
  • Added exponential backoff up to 5s max
  • Added a maximum attempt cap (120 attempts, approx 2 minutes) with a warning log instead of polling forever

Impact

Peak event rate drops from ~20 req/s to ~1 req/s, well within normal relay limits. The rate-limit cascade is avoided entirely.

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