Skip to content

Commit

Permalink
tapchannel: add dust checks for allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeTsagk committed Sep 19, 2024
1 parent 8ec703b commit ece0f83
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tapchannel/commitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,11 @@ func CreateAllocations(chanState *channeldb.OpenChannel, ourBalance,
leaseExpiry = chanState.ThawHeight
}

dustLimit := chanState.LocalChanCfg.DustLimit
if !isOurCommit {
dustLimit = chanState.RemoteChanCfg.DustLimit
}

// The "local" and "remote" notations are always from the perspective of
// the local node. So if we want to find out the asset balance of the
// _initiator_ of the channel, we just need to take into account the
Expand Down Expand Up @@ -707,6 +712,19 @@ func CreateAllocations(chanState *channeldb.OpenChannel, ourBalance,
allocType = CommitAllocationHtlcIncoming
}

// If HTLC is dust, do not create allocation for it.
isDust := lnwallet.HtlcIsDust(
chanState.ChanType, isIncoming, isOurCommit,
filteredView.FeePerKw, htlc.Amount.ToSatoshis(),
dustLimit,
)
if isDust {
// We need to error out, as a dust HTLC carrying assets
// should not be expected.
return fmt.Errorf("error creating asset HTLC " +
"allocation, HTLC is dust")
}

allocations = append(allocations, &Allocation{
Type: allocType,
Amount: rfqmsg.Sum(htlc.AssetBalances),
Expand Down Expand Up @@ -773,6 +791,16 @@ func CreateAllocations(chanState *channeldb.OpenChannel, ourBalance,
"sibling: %w", err)
}

// If HTLC is dust, do not create allocation for it.
isDust := lnwallet.HtlcIsDust(
chanState.ChanType, isIncoming, isOurCommit,
filteredView.FeePerKw, htlc.Amount.ToSatoshis(),
dustLimit,
)
if isDust {
return nil
}

allocations = append(allocations, &Allocation{
Type: AllocationTypeNoAssets,
BtcAmount: htlc.Amount.ToSatoshis(),
Expand Down

0 comments on commit ece0f83

Please sign in to comment.