NWC funding source: Reduce polling#4008
Conversation
ea4ae6e to
ab831e9
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #4008 +/- ##
==========================================
+ Coverage 56.50% 64.26% +7.76%
==========================================
Files 123 128 +5
Lines 16914 18921 +2007
==========================================
+ Hits 9557 12160 +2603
+ Misses 7357 6761 -596 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
1404c72 to
48ddd36
Compare
| "#p": [self.account_public_key_hex], | ||
| "#e": [event["id"]], | ||
| "since": event["created_at"], | ||
| "authors": [self.service_pubkey_hex], |
There was a problem hiding this comment.
this should be added back to filter out spam and replayed events
| sub_id = cast(str, msg[1]) | ||
| event = cast(dict, msg[2]) | ||
| # Ensure the event is valid (do not trust relays) | ||
| if not verify_event(event) or event.get("pubkey") != self.service_pubkey_hex: |
There was a problem hiding this comment.
this should be added back to protect against malicious relays
| was_pending = self._remove_pending_invoice(checking_id) | ||
| if was_pending: | ||
| logger.debug("Pending invoice " + checking_id + " settled via " + source) | ||
| self.paid_invoices_queue.put_nowait(checking_id) |
There was a problem hiding this comment.
i think this should go inside the if, to avoid firing multiple paid events on lnbits if notifications are duplicated
| "#p": [self.account_public_key_hex], | ||
| "since": int(time.time()), | ||
| } | ||
| self.notification_subscription_ids.add(sub_id) |
There was a problem hiding this comment.
these need to be added to self.subscriptions so that they are properly cleared by _close_subscription_by_subid
| except Exception as e: | ||
| logger.error("Error handling pending invoice: " + str(e)) | ||
| invoice["lookup_attempts"] = int(invoice.get("lookup_attempts", 0)) + 1 | ||
| self._schedule_next_lookup(invoice, now) |
There was a problem hiding this comment.
I think there should be a sleep here.
The original issue imo was caused by instances with many pending invoices, while the lookup round is rate-limited, all the pending invoices are checked at once.
See this commit riccardobl@dd5bbd1
d797f00 to
568b37c
Compare
Register long-lived notification subscriptions in .subscriptions so _close_subscription_by_subid and CLOSED relay messages can clear them correctly; mark them as notification_sub entries to exclude them from request timeout handling.
3f6c724 to
b9d5ede
Compare
c5493cf to
973e1b0
Compare
973e1b0 to
3cf26be
Compare
|
Linking to lnbits/nostrclient#70 for prosperity. |
Improve NWC funding source by relying more on
list_transactions, caching and NWC notifications, and less onlookup_invoicepolling.This changes the NWC wallet backend so pending incoming invoices are cached and reconciled through
list_transactions, and marked as paid from notifications. If notifications are missing or delayed, it falls back to scheduled lookups with a backoff schedule instead of polling aggressively.