lightningnetwork / lnd

Lightning Network Daemon ⚡️
MIT License
7.58k stars 2.06k forks source link

[bug]: lnwallet: `LocalBalanceDust`/`RemoteBalanceDust` false negatives -- omitting commitment fees #8772

Open dstadulis opened 2 months ago

dstadulis commented 2 months ago

Background

LocalBalanceDust and RemoteBalanceDust functions are intended to determine whether the local or remote party's balance will be dust after creating a co-op close transaction. However, these functions erroneously omit the commitment fees associated with co-op close transactions, leading to the functions producing false negatives.

https://github.com/lightningnetwork/lnd/blob/4f06f587914fa3392e8ba57ab56985102c7293c7/lnwallet/channel.go#L8620-L8658

Steps to reproduce

  1. Create a co-op close transaction with a commitment fee, of a marginal amount, which would result in the outputs being dust if used in the calculation but not dust if omitted from the calculation.
  2. Call LocalBalanceDust or RemoteBalanceDust
  3. Observe that the functions return false even when the balance would be dust if commitment fees were accounted for.

Expected behaviour

The LocalBalanceDust and RemoteBalanceDust functions should accurately determine whether the local or remote party's balance will be dust after creating a co-op close transaction, including consideration of commitment fees.