Skip to content

Include an outbound_payment flag in MaybeTimeoutClaimableHTLC - #2618

Closed
TheBlueMatt wants to merge 9 commits into
lightningdevkit:mainfrom
TheBlueMatt:2023-09-sensible-balances
Closed

Include an outbound_payment flag in MaybeTimeoutClaimableHTLC#2618
TheBlueMatt wants to merge 9 commits into
lightningdevkit:mainfrom
TheBlueMatt:2023-09-sensible-balances

Conversation

@TheBlueMatt

@TheBlueMattTheBlueMatt commented Sep 28, 2023

Copy link
Copy Markdown
Collaborator

When the user is fetching their current balances after forwarding a payment (before it clears), they'll see a
MaybePreimageClaimableHTLC and a MaybeTimeoutClaimableHTLC but if they sum up their balance using
Balance::claimable_amount_satoshis neither will be included.

Obviously, exactly one of the two balances should be included - one of the two resolutions should happen in our favor. This causes our visible balance to fluctuate up and down by the full value of any HTLCs we're in the middle of forwarding, which is incredibly confusing to see. If we want to stop the fluctuations, we need to pick one of the two balances to include. The obvious candidate is MaybeTimeoutClaimableHTLC as it is the lower of the two, and represents our balance without the fee we'd receive from the forward.

Sadly, if we always include it, we'll end up also including any HTLCs which we've sent but which haven't yet been claimed by their recipient, which is the wrong behavior.

Luckily, we have access to the Option<HTLCSource> while walking HTLCs, which allows us to add an outbound_payment flag to MaybeTimeoutClaimableHTLC. This allows us to only include forwarded payments in claimable_amount_satoshis.

Sadly, even with this in place our balance still fluctuates by the
changes in the commitment transaction fees we have to pay during
forwarding, but addressing that is left for later.

@TheBlueMatt
TheBlueMattforce-pushed the 2023-09-sensible-balances branch from 6921d46 to c78aa46CompareSeptember 28, 2023 23:09
@codecov-commenter

codecov-commenter commented Sep 29, 2023

Copy link
Copy Markdown

Codecov Report

Attention: 8 lines in your changes are missing coverage. Please review.

Comparison is base (5d187f6) 88.69% compared to head (c78aa46) 89.01%.
Report is 3 commits behind head on main.

❗ Current head c78aa46 differs from pull request most recent head 3bc8048. Consider uploading reports for the commit 3bc8048 to get more accurate results

FilesPatch %Lines
lightning/src/chain/channelmonitor.rs66.66%7 Missing and 1 partial ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@ Coverage Diff @@## main #2618 +/- ##
==========================================
+ Coverage 88.69% 89.01% +0.31% 
==========================================
Files 113 112 -1 Lines 89475 86299 -3176 Branches 89475 86299 -3176 ==========================================
- Hits 79359 76817 -2542 + Misses 7867 7252 -615 + Partials 2249 2230 -19 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@TheBlueMattTheBlueMatt added this to the 0.0.117 milestone Sep 29, 2023
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Tagging this as 0.0.117 as we need to do something here, though that could also be reverting #2476.

@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Okay this really isnt sufficient, I worked on more details but its an increasingly huge patchset. Slipping to 118 and reverting 2476.

@TheBlueMattTheBlueMatt modified the milestones: 0.0.117, 0.0.118Sep 29, 2023
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Pushed some wip stuff that i think is needed to fully switch over here.

When the user is fetching their current balances after forwarding a
payment (before it clears), they'll see a
`MaybePreimageClaimableHTLC` and a `MaybeTimeoutClaimableHTLC` but
if they sum up their balance using
`Balance::claimable_amount_satoshis` neither will be included.
Obviously, exactly one of the two balances should be included - one
of the two resolutions should happen in our favor. This causes our
visible balance to fluctuate up and down by the full value of any
HTLCs we're in the middle of forwarding, which is incredibly
confusing to see. If we want to stop the fluctuations, we need to
pick one of the two balances to include. The obvious candidate is
`MaybeTimeoutClaimableHTLC` as it is the lower of the two, and
represents our balance without the fee we'd receive from the
forward.
Sadly, if we always include it, we'll end up also including any
HTLCs which we've sent but which haven't yet been claimed by their
recipient, which is the wrong behavior.
Luckily, we have access to the `Option<HTLCSource>` while walking
HTLCs, which allows us to add an `outbound_payment` flag to
`MaybeTimeoutClaimableHTLC`. This allows us to only include
forwarded payments in `claimable_amount_satoshis`.
Sadly, even with this in place our balance still fluctuates by the
changes in the commitment transaction fees we have to pay during
forwarding, but addressing that is left for later.
There's no reason to `use` a module within that module to refer to
that module...
These don't really belong in `channel` as they're now used in other
parts of the codebase.
`Balance::ClaimableOnChannelClose` excludes the commitment
transaction fee, which makes it hard to use for current balance
calculation. Here we add it, setting the value to zero for inbound
channels (i.e. ones for which we don't pay the fee).
…ClaimableOnChannelClose`
If we're gonna push users towards using `Balance` to determine
their current balances, we really need to provide more information,
including msat balances.
Here we add rounded-out msat balances to the pre-close balance
information
@TheBlueMatt
TheBlueMattforce-pushed the 2023-09-sensible-balances branch from eb18aac to 3bc8048CompareNovember 14, 2023 22:53
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Should also address #2738 here.

@dunxen

Copy link
Copy Markdown
Contributor

Hey @TheBlueMatt, could you allow edits by maintainers for this PR so I can take this over? :)

@dunxen

Copy link
Copy Markdown
Contributor

Superseded by #3212.

@dunxendunxen closed this Aug 1, 2024
Sign up for freeto 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.

3 participants

@TheBlueMatt@codecov-commenter@dunxen