rust-lightning icon indicating copy to clipboard operation
rust-lightning copied to clipboard

Include an `outbound_payment` flag in `MaybeTimeoutClaimableHTLC`

Open TheBlueMatt opened this issue 2 years ago • 5 comments

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 avatar Sep 28 '23 23:09 TheBlueMatt

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.

:exclamation: 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 :warning:

:exclamation: 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     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-commenter avatar Sep 29 '23 01:09 codecov-commenter

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

TheBlueMatt avatar Sep 29 '23 01:09 TheBlueMatt

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

TheBlueMatt avatar Sep 29 '23 18:09 TheBlueMatt

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

TheBlueMatt avatar Sep 29 '23 18:09 TheBlueMatt

Should also address https://github.com/lightningdevkit/rust-lightning/issues/2738 here.

TheBlueMatt avatar Nov 16 '23 23:11 TheBlueMatt

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

dunxen avatar Jul 24 '24 16:07 dunxen

Superseded by #3212.

dunxen avatar Aug 01 '24 10:08 dunxen