Skip to content

Commit 09c7f4f

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 4d4bf55 commit 09c7f4f

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

tapchannel/aux_traffic_shaper.go

Lines changed: 18 additions & 1 deletion
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
@@ -246,7 +263,7 @@ func paymentBandwidthAssetUnits(htlcAssetAmount, computedLocal uint64,
246263
default:
247264
// We shouldn't reach this case, we add it only for the function
248265
// to always return something and the compiler to be happy.
249-
return 0, nil
266+
return 0, fmt.Errorf("unreachable code")
250267
}
251268
}
252269

0 commit comments

Comments
 (0)