Skip to content

Commit b0f4d23

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 74b40b2 commit b0f4d23

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tapchannel/aux_traffic_shaper.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ func (s *AuxTrafficShaper) PaymentBandwidth(fundingBlob, htlcBlob,
141141
return 0, nil
142142
}
143143

144+
fundingChan, err := cmsg.DecodeOpenChannel(fundingBlobBytes)
145+
if err != nil {
146+
return 0, fmt.Errorf("error decoding funding blob: %w", err)
147+
}
148+
144149
commitment, err := cmsg.DecodeCommitment(commitmentBytes)
145150
if err != nil {
146151
return 0, fmt.Errorf("error decoding commitment blob: %w", err)
@@ -151,6 +156,23 @@ func (s *AuxTrafficShaper) PaymentBandwidth(fundingBlob, htlcBlob,
151156
return 0, fmt.Errorf("error decoding HTLC blob: %w", err)
152157
}
153158

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

0 commit comments

Comments
 (0)