Skip to content

Commit 074096d

Browse files
committed
tapchannel: skip creating allocations for dust balances
This commit addresses an edge case where one party only has a BTC balance (but no asset balance). In that case the balance is allowed to be below the dust limit. But because those sats will be added to the fee and can't be materialized on-chain, we also can't create an allocation for the balance. Otherwise we'll have a mismatch between the number of allocations and the number of expected on-chain outputs of the transaction. This isn't an issue when there is an asset balance, as in that case we enforce that the BTC balance is above the dust limit.
1 parent 766d074 commit 074096d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

tapchannel/commitment.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,10 @@ func addCommitmentOutputs(chanType channeldb.ChannelType, localChanCfg,
969969

970970
// We've asserted that we have a non-dust BTC balance if we have an
971971
// asset balance before, so we can just check the asset balance here.
972-
if ourAssetBalance > 0 || ourBalance > 0 {
972+
// In case there is no asset balance, and the BTC value is dust, it will
973+
// not be materialized on-chain, and we shouldn't create an allocation
974+
// for it.
975+
if ourAssetBalance > 0 || ourBalance > localChanCfg.DustLimit {
973976
toLocalScript, err := lnwallet.CommitScriptToSelf(
974977
chanType, initiator, keys.ToLocalKey,
975978
keys.RevocationKey, uint32(localChanCfg.CsvDelay),
@@ -1033,7 +1036,10 @@ func addCommitmentOutputs(chanType channeldb.ChannelType, localChanCfg,
10331036
addAllocation(allocation)
10341037
}
10351038

1036-
if theirAssetBalance > 0 || theirBalance > 0 {
1039+
// We only create an allocation if there is going to be an on-chain
1040+
// output. If this is dust (which is only allowed if there are no assets
1041+
// on the output), it will not be materialized on-chain.
1042+
if theirAssetBalance > 0 || theirBalance > localChanCfg.DustLimit {
10371043
toRemoteScript, _, err := lnwallet.CommitScriptToRemote(
10381044
chanType, initiator, keys.ToRemoteKey, leaseExpiry,
10391045
lfn.None[txscript.TapLeaf](),

0 commit comments

Comments
 (0)