Fix HTLC tx balance calculation on local commitment transactions
authorMatt Corallo <git@bluematt.me>
Fri, 25 Feb 2022 05:14:00 +0000 (05:14 +0000)
committerMatt Corallo <git@bluematt.me>
Tue, 1 Mar 2022 00:43:55 +0000 (00:43 +0000)
commitb1653f0705409087381975013593c86be7e4c5e3
treee6e440fc0a806c36cb73bcd82cf3ca71e68326a2
parente43cfe135a5b68620cd51b9b982362c272b4ef77
Fix HTLC tx balance calculation on local commitment transactions

When handling the broadcast of a local commitment transactions
(with associated CSV delays prior to spendability), we incorrectly
handled the CSV delays on HTLC transactions. This caused us to miss
spendable outputs for HTLCs which were awaiting a CSV delay.

Further, because of this, we could hit an assertion as
`get_claimable_balances` asserted that HTLCs were resolved after
the funding spend was resolved, which was not true if the HTLC did
not have a CSV delay attached (due to the above bug or due to it
being an HTLC claim by our counterparty).

This fixes both bugs, also converting some assertions to
`debug_assert`s to avoid future issues as balance mis-calculation
is not currently an indication of potential funds loss.

Thanks to Cash App for reporting this bug.
lightning/src/chain/channelmonitor.rs
lightning/src/ln/monitor_tests.rs