Skip to content
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

Include an outbound_payment flag in MaybeTimeoutClaimableHTLC #2618

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

TheBlueMatt
Copy link
Collaborator

@TheBlueMatt TheBlueMatt commented Sep 28, 2023

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.

@codecov-commenter
Copy link

codecov-commenter commented Sep 29, 2023

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

Files Patch % Lines
lightning/src/chain/channelmonitor.rs 66.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.

@TheBlueMatt TheBlueMatt added this to the 0.0.117 milestone Sep 29, 2023
@TheBlueMatt
Copy link
Collaborator Author

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

@TheBlueMatt
Copy link
Collaborator Author

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

@TheBlueMatt TheBlueMatt modified the milestones: 0.0.117, 0.0.118 Sep 29, 2023
@TheBlueMatt
Copy link
Collaborator Author

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
Copy link
Collaborator Author

Should also address #2738 here.

@TheBlueMatt TheBlueMatt modified the milestones: 0.0.119, 0.0.120 Nov 27, 2023
@TheBlueMatt TheBlueMatt modified the milestones: 0.0.120 , 0.0.121 Jan 8, 2024
@TheBlueMatt TheBlueMatt modified the milestones: 0.0.122, 0.0.123 Mar 18, 2024
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.

None yet

2 participants