Skip to content

Drop rate-limited static invoice requests - #1101

Open
tnull wants to merge 2 commits into
lightningdevkit:mainfrom
tnull:2026-09-fix-static-invoice-rate-limits
Open

tnull wants to merge 2 commits into
lightningdevkit:mainfrom
tnull:2026-09-fix-static-invoice-rate-limits

Conversation

@tnull

@tnull tnull commented Sep 16, 2026 •

Copy link
Copy Markdown
Collaborator

Drop static invoice requests when the rate limit is reached instead of retrying them and delaying later events. Keep retrying storage errors and only acknowledge invoices after saving them.

Fixes an issue reported by @ajaysehwal.

@tnull
tnull requested a review from joostjager September 16, 2026 10:33
@ldk-reviews-bot

ldk-reviews-bot commented Sep 16, 2026 •

Copy link
Copy Markdown

👋 Thanks for assigning @joostjager as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@tnull
tnull force-pushed the 2026-09-fix-static-invoice-rate-limits branch from d393f3e to ce0d9cf Compare September 16, 2026 10:50

@ajaysehwal ajaysehwal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tnull , one gap in thorough test suite: there’s no test covering a sender that gets rate-limited once and then successfully retries after the bucket refills.

Not required for correctness — the existing tests already show that the rate-limited request is dropped cleanly without affecting other requests. But a small test using a short refill interval or deterministic bucket advancement would make the intended contract explicit: the request is dropped, and the sender is free to retry later rather than being blocked permanently.

Purely a documentation-via-test nice-to-have.

Comment thread src/payment/asynchronous/static_invoice_store.rs
@tnull
tnull force-pushed the 2026-09-fix-static-invoice-rate-limits branch from ce0d9cf to 264852e Compare September 16, 2026 12:01

@ajaysehwal ajaysehwal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread src/event.rs
self.channel_manager.static_invoice_persisted(invoice_persisted_path);
},
Err(e) => {
Err(StaticInvoiceStoreError::RateLimited) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we want to skip the rate limiter once we are retrying persistence, so that we don't exit the retry loop because new requests came in?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a fixup for this.

}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn static_invoice_read_error_is_replayed() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite a bit of test code. Can't AI come up with something more compact with still reasonable coverage?

tnull added 2 commits October 16, 2026 14:56
Drop static invoice requests when the rate limit is reached instead
of retrying them and delaying later events. Keep retrying storage
errors and only acknowledge invoices after saving them.

Fixes an issue reported by Ajay Sehwal.

Co-Authored-By: HAL 9000
Storage retries consumed another rate-limit token on every attempt.
Repeated failures could exhaust the bucket and silently drop an event
that had already been admitted.

Preserve admission across storage failures so requests can recover
without losing their place in the event queue. Successful operations
still consume quota, and regression tests cover retry recovery as well
as silent rejection and later admission after refill.

Co-Authored-By: HAL 9000
@tnull
tnull force-pushed the 2026-09-fix-static-invoice-rate-limits branch from 264852e to 0033e6b Compare October 16, 2026 13:14
@tnull
tnull requested a review from joostjager October 16, 2026 13:16
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.

4 participants