-
Notifications
You must be signed in to change notification settings - Fork 438
feat: track in-flight amount for pending payments #4366
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
base: main
Are you sure you want to change the base?
Conversation
|
👋 I see @joostjager was un-assigned. |
4c7a57d to
0c440b6
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4366 +/- ##
==========================================
- Coverage 86.54% 86.08% -0.47%
==========================================
Files 158 156 -2
Lines 103166 103536 +370
Branches 103166 103536 +370
==========================================
- Hits 89287 89126 -161
- Misses 11456 11898 +442
- Partials 2423 2512 +89
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
🔔 1st Reminder Hey @wpaulino! This PR has been waiting for your review. |
|
🔔 2nd Reminder Hey @wpaulino! This PR has been waiting for your review. |
wpaulino
left a 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.
Please include the description of the changes in the commit message as well
lightning/src/ln/channelmanager.rs
Outdated
| /// Amount (in msat) currently locked in HTLCs. | ||
| /// | ||
| /// `total_msat - inflight_msat` gives the amount waiting to be retried | ||
| /// Reserve both from spendable balance. |
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.
This line is not very clear to me, can you rephrase it?
|
|
||
| let payment_amt = 100_000; | ||
| let (payment_preimage, _payment_hash, _, payment_id) = | ||
| route_payment(&nodes[0], &[&nodes[1], &nodes[2]], payment_amt); |
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.
Let's route another payment but still only claim one so we can assert the in-flight amount of the remaining payment
|
👋 The first review has been submitted! Do you think this PR is ready for a second reviewer? If so, click here to assign a second reviewer. |
|
✅ Added second reviewer: @joostjager |
TheBlueMatt
left a 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.
I'm not convinced this API is quite sufficient for what we need. We really want a single, consistent view of users' current balance. The problem with fetching information from two separate sources (here ChannelMonitor(s) + ChannelManager) is that we end up racing retries across them - calling them both in succession may double- or under-count pending payments. I'm not quite sure with the right answer is, maybe we need to list HTLCs in pending payments and have some utility that removes duplicated entries, or maybe we need to include total payment amounts in the ChannelMonitor balance list and have some logic to compare the pending payments list to remove payments that have partially MPP-timed-out.
|
We'll have to explore it a bit, but I think the second option is compelling - we already have payment info in the monitors (I hope enough) so communicating that back may suffice. The only case we'd maybe want to worry about is whether we over-state the in-flight amount for payments where we've given up retrying but there are stuck MPP parts. In that case we'll need the pending payment info like you exposed here, but may need more information about the retry state. |
Got it, will look into this and follow up |
048827d to
ca6d216
Compare
Tracks actual in-flight amounts for pending payments to enable accurate balance calculations in wallets - Added payment_id to Balance::MaybeTimeoutClaimableHTLC so monitors can report which payment each HTLC belongs to - Added is_retryable to RecentPaymentDetails::Pending to distinguish active retries from stuck HTLCs - Added reconcile_inflight_payments() using ChannelMonitor as authoritative source for amounts to prevent double-counting - Added aggregate_outbound_htlcs_by_payment() to ChannelMonitor for aggregating HTLCs by payment This solves the race condition when fetching from ChannelMonitor and ChannelManager separately during retries
ca6d216 to
0934df6
Compare
|
I went with the second option, added payment info to the monitors, using them as the source of truth for in-flight amounts. Added For the stuck MPP parts concern, I added Added |
| /// returns msats. | ||
| /// | ||
| /// [`reconcile_inflight_payments`]: crate::ln::channelmanager::reconcile_inflight_payments | ||
| pub fn aggregate_outbound_htlcs_by_payment(balances: &[Balance]) -> HashMap<PaymentId, u64> { |
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.
This is a weird public API?
| @@ -0,0 +1,27 @@ | |||
| ## API Updates | |||
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.
No, please keep pending changelog entries condensed. Max a line or two wrapped at 80 chars. There should almost certainly only be one or two entries, each one or two sentences for a PR like this.
| /// ``` | ||
| pub fn reconcile_inflight_payments( | ||
| balances: &[Balance], recent_payments: &[RecentPaymentDetails], | ||
| ) -> HashMap<PaymentId, (u64, bool)> { |
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.
Do you feel like this is the right API? I really want to answer the question "what is my balance" not "what is the amount being sent for pending payments".
fix #3374
adds
inflight_msattoRecentPaymentDetails::Pendingto expose the amount currently locked in HTLCs. this allows wallets to avoid balance flicker during payment retries by distinguishing between inflight funds and funds waiting to retry