Skip to content

Commit 8906450

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 9430a70 commit 8906450

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

tapchannel/aux_traffic_shaper.go

+18-1
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,23 @@ func (s *AuxTrafficShaper) PaymentBandwidth(htlcBlob,
148148
return 0, fmt.Errorf("error decoding HTLC blob: %w", err)
149149
}
150150

151+
// Before we do any further checks, we actually need to make sure that
152+
// the HTLC is compatible with this channel. Because of `lnd`'s
153+
// non-strict forwarding, if there are multiple asset channels, the
154+
// wrong one could be chosen if we signal there's bandwidth. So we need
155+
// to tell `lnd` it can't use this channel if the assets aren't
156+
// compatible.
157+
htlcAssetIDs := fn.NewSet[asset.ID](fn.Map(
158+
htlc.Balances(), func(b *rfqmsg.AssetBalance) asset.ID {
159+
return b.AssetID.Val
160+
})...,
161+
)
162+
if !commitment.HasAllAssetIDs(htlcAssetIDs) {
163+
log.Tracef("HTLC asset IDs %v not compatible with asset IDs "+
164+
"of channel, returning 0 bandwidth", htlcAssetIDs)
165+
return 0, nil
166+
}
167+
151168
// With the help of the latest HtlcView, let's calculate a more precise
152169
// local balance. This is useful in order to not forward HTLCs that may
153170
// never be settled. Other HTLCs that may also call into this method are
@@ -244,7 +261,7 @@ func paymentBandwidthAssetUnits(htlcAssetAmount, computedLocal uint64,
244261
default:
245262
// We shouldn't reach this case, we add it only for the function
246263
// to always return something and the compiler to be happy.
247-
return 0, nil
264+
return 0, fmt.Errorf("unreachable code")
248265
}
249266
}
250267

0 commit comments

Comments
 (0)