-
Notifications
You must be signed in to change notification settings - Fork 44
fix: prevent redundant LND queries for confirmed dev fee payments #586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. WalkthroughAdds an in-memory Changes
Sequence Diagram(s)sequenceDiagram
participant Scheduler
participant DB
participant LND
Scheduler->>DB: Query candidate orders (stale/real-hash)
loop per order
alt order_id in confirmed_dev_fee_orders
Scheduler-->>Scheduler: Skip LN check
else
Scheduler->>LND: check_dev_fee_payment_status(order_id)
alt LND reports Succeeded
LND-->>Scheduler: Succeeded
Scheduler->>DB: verify/update order as paid
Scheduler-->>Scheduler: confirmed_dev_fee_orders.add(order_id)
else
LND-->>Scheduler: Not yet/Failed
Scheduler->>DB: handle pending/stale logic
end
end
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/scheduler.rs`:
- Around line 558-563: The comment and the following let binding are
misformatted for rustfmt; update the declaration of confirmed_dev_fee_orders so
it is formatted as a single rustfmt-friendly line (e.g., put the full type and
initializer on one line or align the type/initializer per rustfmt conventions)
and then run cargo fmt. Locate the variable confirmed_dev_fee_orders and its
HashSet type (std::collections::HashSet<uuid::Uuid>) and adjust spacing/line
breaks (or add a local use for std::collections::HashSet and shorten the
declaration) so rustfmt no longer reports differences, then re-run CI.
🧹 Nitpick comments (2)
src/scheduler.rs (2)
722-744: Recovery path doesn't add toconfirmed_dev_fee_orders, causing one extra LND round-trip.When an order is recovered here (has a payment hash but
dev_fee_paid=false), it gets marked as paid but isn't inserted into the set. On the next cycle it will match the real-hash query (Line 659) and trigger an LNDTrackPaymentV2call before finally being added to the set. Consider inserting the order ID here too.Proposed fix
Ok(_) => { info!( "✅ Recovered order {} - marked as paid with existing hash", order_id ); + confirmed_dev_fee_orders.insert(order_id); // Verify recovery
562-563:confirmed_dev_fee_ordersgrows without bound over the daemon lifetime.Every confirmed order is inserted but never removed. For a long-running daemon this is an unbounded (albeit slow) memory growth. If the daemon processes a high volume of orders over weeks/months, consider periodically clearing the set or switching to an LRU cache with a reasonable capacity.
9ee126c to
cd13bb9
Compare
The stale real-hash cleanup runs every scheduler cycle and queries all orders with dev_fee_paid=true and a real payment hash. For orders where the payment already succeeded, check_dev_fee_payment_status() would query LND, confirm success, and log the confirmation — but nothing changed in the order to exclude it from the next cycle's query. This caused: 1. Redundant LND TrackPaymentV2 queries every 60s for every paid order 2. Repeated '✅ Order ... dev fee payment confirmed' log messages 3. Unnecessary DB updates (setting dev_fee_paid=true when already true) Fix: Track confirmed order IDs in an in-memory HashSet so each order is only checked once per daemon lifetime. On daemon restart, the set is empty and all orders get re-checked once (preserving crash recovery behavior). Orders confirmed via the normal payment flow are also added to the set. Closes #585
cd13bb9 to
b4954f9
Compare
Summary
Prevents the stale real-hash cleanup from repeatedly querying LND and logging confirmation messages for orders that have already been verified as paid.
Closes #585
Problem
The stale real-hash cleanup in
job_process_dev_fee_payment()runs every 60s and queries all orders withdev_fee_paid = 1and a real payment hash. For already-paid orders,check_dev_fee_payment_status()would:TrackPaymentV2→ Succeededdev_fee_paid = true(already true — no-op)✅ Order ... dev fee payment confirmed via LN status checkNothing changed in the order to exclude it from the next cycle, causing infinite repetition.
Solution
Track confirmed order IDs in an in-memory
HashSet<Uuid>. Each order is checked at most once per daemon lifetime:Changes
src/scheduler.rs: Addconfirmed_dev_fee_orders: HashSet<Uuid>to track verified ordersSucceeded(both cleanup and normal flow)Summary by CodeRabbit