Skip to content

Commit ac55403

Browse files
committed
tapchannel: validate channel assets for bandwidth
This is the third part of the fix: We need to make sure that we don't pick an asset channel that has the wrong type of assets when telling lnd what channel it can use.
1 parent 6c3a397 commit ac55403

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

tapchannel/aux_traffic_shaper.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,23 @@ func (s *AuxTrafficShaper) PaymentBandwidth(htlcBlob,
149149
return 0, fmt.Errorf("error decoding HTLC blob: %w", err)
150150
}
151151

152+
// Before we do any further checks, we actually need to make sure that
153+
// the HTLC is compatible with this channel. Because of `lnd`'s
154+
// non-strict forwarding, if there are multiple asset channels, the
155+
// wrong one could be chosen if we signal there's bandwidth. So we need
156+
// to tell `lnd` it can't use this channel if the assets aren't
157+
// compatible.
158+
htlcAssetIDs := fn.NewSet[asset.ID](fn.Map(
159+
htlc.Balances(), func(b *rfqmsg.AssetBalance) asset.ID {
160+
return b.AssetID.Val
161+
})...,
162+
)
163+
if !commitment.HasAllAssetIDs(htlcAssetIDs) {
164+
log.Tracef("HTLC asset IDs %v not compatible with asset IDs "+
165+
"of channel, returning 0 bandwidth", htlcAssetIDs)
166+
return 0, nil
167+
}
168+
152169
// With the help of the latest HtlcView, let's calculate a more precise
153170
// local balance. This is useful in order to not forward HTLCs that may
154171
// never be settled. Other HTLCs that may also call into this method are

0 commit comments

Comments
 (0)