Repository navigation
Conversation
|
👋 Thanks for assigning @joostjager as a reviewer! |
d393f3e to
ce0d9cf
Compare
ajaysehwal
left a comment
There was a problem hiding this comment.
@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.
ce0d9cf to
264852e
Compare
| self.channel_manager.static_invoice_persisted(invoice_persisted_path); | ||
| }, | ||
| Err(e) => { | ||
| Err(StaticInvoiceStoreError::RateLimited) => { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Added a fixup for this.
264852e to
0033e6b
Compare
| } | ||
| } | ||
|
|
||
| fn refund_on_io_error( |
There was a problem hiding this comment.
I find this a bit of a strange function. The "on_io_error" sounds like it checks something, but when this is called, we are already handling an io error?
Also the wrapping seems to be independent.
Isn't it better to just inline this?
There was a problem hiding this comment.
Didn't inline, but should be improved.
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. Requests that fail due to storage errors return their rate-limit token, so replayed events are not dropped before storage recovers. Fixes an issue reported by Ajay Sehwal. Co-Authored-By: HAL 9000
0033e6b to
cbb52cf
Compare
| // Drop silently: logging each rejected request, even at trace level, | ||
| // can cause excessive log output and I/O under sustained load. | ||
| }, | ||
| Err(StaticInvoiceStoreError::Io(e)) => { |
There was a problem hiding this comment.
A decode failure (InvalidData) also lands here, so a corrupted record gets replayed forever and holds up every later event, though this isn't new with this PR. Since it won't recover, should we log it and drop the request instead, and only replay real storage errors?
| }, | ||
| Err(e) => { | ||
| Err(StaticInvoiceStoreError::RateLimited) => { | ||
| // Drop silently: logging each rejected request, even at trace level, |
There was a problem hiding this comment.
Claude had one thing on this still:
An async recipient comes online and requests offer paths for ~10 cached offer slots, which produces ~10 PersistStaticInvoice events for one recipient_id in one batch. The first 5 are persisted; the rest hit RateLimited and are dropped with no ack. Those slots are not stored until the client's retry timer fires, so payers asking for those slots get no invoice in the meantime. Before this PR the same events were replayed and succeeded about 100ms later.
There was a problem hiding this comment.
That mostly means we should align the rate limit to allow for this, no?
There was a problem hiding this comment.
Maybe it's a bit of a weird coupling, but it seems the pragmatic fix for now
| } | ||
| }, | ||
| ) | ||
| .or_else(|e| if e.kind() == lightning::io::ErrorKind::NotFound { Ok(None) } else { Err(e) }) |
There was a problem hiding this comment.
A persisted invoice that fails to decode still blocks the event queue: the decode error (L123) becomes InvalidData, passes through here as a regular error, surfaces as StaticInvoiceStoreError::Io, and StaticInvoiceRequested returns ReplayEvent for it. With the refund, every replay is admitted, so the event is retried indefinitely and nothing queued behind it (e.g. PaymentClaimable) gets handled until the key is removed by hand.
Since a decode failure won't fix itself on retry, could we treat it as permanent, i.e. log it and return Ok(None) (or remove the entry)? Happy for this to be a follow-up, as it predates this PR.
| // Drop silently: logging each rejected request, even at trace level, | ||
| // can cause excessive log output and I/O under sustained load. | ||
| }, | ||
| Err(StaticInvoiceStoreError::Io(e)) => { |
There was a problem hiding this comment.
For StaticInvoiceRequested, replaying on a storage read error means a slow or temporarily failing store holds up every event behind it, including time-critical ones like HTLC claims. Nothing is lost by dropping the request instead, as the payer can retry. Would it make sense to log and drop on read errors here, and keep ReplayEvent only for PersistStaticInvoice (L2527), where we can't lose the write?
| pub(crate) async fn handle_static_invoice_requested( | ||
| &self, recipient_id: &[u8], invoice_slot: u16, | ||
| ) -> Result<Option<(StaticInvoice, BlindedMessagePath)>, StaticInvoiceStoreError> { | ||
| if !self.request_rate_limiter.lock().expect("lock").allow(recipient_id) { |
There was a problem hiding this comment.
Since the request limiter is keyed only by recipient_id (5 tokens, refilled every 100ms), all payers of a recipient share one bucket. Anyone sending more than ~10 requests/s for a public offer keeps it empty, and with this change honest payers' requests for that recipient are then silently dropped.
Not new to this PR, but worth considering whether the limit should also be scoped per requester/reply path, or at least documenting that it is shared across payers.
| self.channel_manager.static_invoice_persisted(invoice_persisted_path); | ||
| }, | ||
| Err(e) => { | ||
| Err(StaticInvoiceStoreError::RateLimited) => { |
There was a problem hiding this comment.
Agree with not logging every rejected request, but right now rate limiting is completely invisible: an operator debugging failed async payments sees nothing at any log level. Could we log once when a recipient's bucket first runs empty (or keep a simple counter), so the condition is observable without per-request logging? Same for the arm at L2563.
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.