Skip to content

Commit 84a310c

Browse files
committed
tapchannel: add dust checks for allocations
1 parent 4f7d4c5 commit 84a310c

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tapchannel/commitment.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,24 @@ func CreateAllocations(chanState *channeldb.OpenChannel, ourBalance,
707707
allocType = CommitAllocationHtlcIncoming
708708
}
709709

710+
dustLimit := chanState.LocalChanCfg.DustLimit
711+
if !isOurCommit {
712+
dustLimit = chanState.RemoteChanCfg.DustLimit
713+
}
714+
715+
// If HTLC is dust, do not create allocation for it.
716+
isDust := lnwallet.HtlcIsDust(
717+
chanState.ChanType, isIncoming, isOurCommit,
718+
filteredView.FeePerKw, htlc.Amount.ToSatoshis(),
719+
dustLimit,
720+
)
721+
if isDust {
722+
// We need to error out, as a dust HTLC carrying assets
723+
// should not be expected.
724+
return fmt.Errorf("error creating asset HTLC " +
725+
"allocation, HTLC is dust")
726+
}
727+
710728
allocations = append(allocations, &Allocation{
711729
Type: allocType,
712730
Amount: rfqmsg.Sum(htlc.AssetBalances),
@@ -773,6 +791,21 @@ func CreateAllocations(chanState *channeldb.OpenChannel, ourBalance,
773791
"sibling: %w", err)
774792
}
775793

794+
dustLimit := chanState.LocalChanCfg.DustLimit
795+
if !isOurCommit {
796+
dustLimit = chanState.RemoteChanCfg.DustLimit
797+
}
798+
799+
// If HTLC is dust, do not create allocation for it.
800+
isDust := lnwallet.HtlcIsDust(
801+
chanState.ChanType, isIncoming, isOurCommit,
802+
filteredView.FeePerKw, htlc.Amount.ToSatoshis(),
803+
dustLimit,
804+
)
805+
if isDust {
806+
return nil
807+
}
808+
776809
allocations = append(allocations, &Allocation{
777810
Type: AllocationTypeNoAssets,
778811
BtcAmount: htlc.Amount.ToSatoshis(),

0 commit comments

Comments
 (0)