]> git.bitcoin.ninja Git - rust-lightning/commit
Include an `outbound_payment` flag in `MaybeTimeoutClaimableHTLC`
authorMatt Corallo <git@bluematt.me>
Thu, 28 Sep 2023 23:02:26 +0000 (23:02 +0000)
committerMatt Corallo <git@bluematt.me>
Tue, 14 Nov 2023 21:28:02 +0000 (21:28 +0000)
commitb6a7baac1ca98f27755918a8a23869905f1b7b88
treee07c3cd261f37704a93d28f9d3d76fa53d363955
parent5d187f65b993cc4862f37f6fceaa6cccd6561dc9
Include an `outbound_payment` flag in `MaybeTimeoutClaimableHTLC`

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.
lightning/src/chain/channelmonitor.rs
lightning/src/ln/monitor_tests.rs