]> 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)
committerDuncan Dean <git@dunxen.dev>
Tue, 13 Aug 2024 11:26:56 +0000 (13:26 +0200)
commit6a34baa270fe4fa846754b0f99a97562a9f53397
treefad0dfa4a31201815417b6e1390046253a2b8b64
parentbc1c026712d8ce2d78e729ed98ae9bbea267ed6c
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