mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-22 14:22:37 +01:00
Merge pull request #8908 from lightningnetwork/traffic-shaper-htlc-amount-fix
routing: don't assume HTLC amount for custom channel
This commit is contained in:
commit
90f997c908
5 changed files with 36 additions and 15 deletions
|
@ -658,6 +658,7 @@ func (f *interceptedForward) ResumeModified(
|
|||
switch htlc := f.packet.htlc.(type) {
|
||||
case *lnwire.UpdateAddHTLC:
|
||||
outgoingAmountMsat.WhenSome(func(amount lnwire.MilliSatoshi) {
|
||||
f.packet.amount = amount
|
||||
htlc.Amount = amount
|
||||
})
|
||||
|
||||
|
|
|
@ -407,7 +407,7 @@ func testForwardInterceptorModifiedHtlc(ht *lntest.HarnessTest) {
|
|||
customRecords[crKey] = crValue
|
||||
|
||||
action := routerrpc.ResolveHoldForwardAction_RESUME_MODIFIED
|
||||
newOutgoingAmountMsat := packet.OutgoingAmountMsat + 4000
|
||||
newOutgoingAmountMsat := packet.OutgoingAmountMsat
|
||||
|
||||
err := bobInterceptor.Send(&routerrpc.ForwardHtlcInterceptResponse{
|
||||
IncomingCircuitKey: packet.IncomingCircuitKey,
|
||||
|
@ -539,7 +539,7 @@ func testForwardInterceptorWireRecords(ht *lntest.HarnessTest) {
|
|||
require.Equal(ht, []byte("test"), val)
|
||||
|
||||
action := routerrpc.ResolveHoldForwardAction_RESUME_MODIFIED
|
||||
newOutgoingAmountMsat := packet.OutgoingAmountMsat + 800
|
||||
newOutgoingAmountMsat := packet.OutgoingAmountMsat
|
||||
|
||||
err := bobInterceptor.Send(&routerrpc.ForwardHtlcInterceptResponse{
|
||||
IncomingCircuitKey: packet.IncomingCircuitKey,
|
||||
|
|
|
@ -138,6 +138,13 @@ func (b *bandwidthManager) getBandwidth(cid lnwire.ShortChannelID,
|
|||
|
||||
auxBandwidth lnwire.MilliSatoshi
|
||||
auxBandwidthDetermined bool
|
||||
|
||||
// htlcAmount is the amount we're going to use to check if we
|
||||
// can add another HTLC to the channel. If the external traffic
|
||||
// shaper is handling the channel, we'll use 0 to just sanity
|
||||
// check the number of HTLCs on the channel, since we don't know
|
||||
// the actual HTLC amount that will be sent.
|
||||
htlcAmount = amount
|
||||
)
|
||||
err = fn.MapOptionZ(b.trafficShaper, func(ts TlvTrafficShaper) error {
|
||||
fundingBlob := link.FundingCustomBlob()
|
||||
|
@ -171,6 +178,15 @@ func (b *bandwidthManager) getBandwidth(cid lnwire.ShortChannelID,
|
|||
|
||||
auxBandwidthDetermined = true
|
||||
|
||||
// We don't know the actual HTLC amount that will be sent using
|
||||
// the custom channel. But we'll still want to make sure we can
|
||||
// add another HTLC, using the MayAddOutgoingHtlc method below.
|
||||
// Passing 0 into that method will use the minimum HTLC value
|
||||
// for the channel, which is okay to just check we don't exceed
|
||||
// the max number of HTLCs on the channel. A proper balance
|
||||
// check is done elsewhere.
|
||||
htlcAmount = 0
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -180,11 +196,11 @@ func (b *bandwidthManager) getBandwidth(cid lnwire.ShortChannelID,
|
|||
return 0
|
||||
}
|
||||
|
||||
// If our link isn't currently in a state where it can add
|
||||
// another outgoing htlc, treat the link as unusable.
|
||||
if err := link.MayAddOutgoingHtlc(amount); err != nil {
|
||||
// If our link isn't currently in a state where it can add another
|
||||
// outgoing htlc, treat the link as unusable.
|
||||
if err := link.MayAddOutgoingHtlc(htlcAmount); err != nil {
|
||||
log.Warnf("ShortChannelID=%v: cannot add outgoing "+
|
||||
"htlc: %v", cid, err)
|
||||
"htlc with amount %v: %v", cid, htlcAmount, err)
|
||||
return 0
|
||||
}
|
||||
|
||||
|
|
|
@ -1007,18 +1007,22 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig,
|
|||
continue
|
||||
}
|
||||
|
||||
firstHopTLVs := lnwire.CustomRecords(
|
||||
r.FirstHopCustomRecords,
|
||||
)
|
||||
firstHopData, err := firstHopTLVs.Serialize()
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
var firstHopBlob fn.Option[tlv.Blob]
|
||||
if r.FirstHopCustomRecords != nil {
|
||||
firstHopTLVs := lnwire.CustomRecords(
|
||||
r.FirstHopCustomRecords,
|
||||
)
|
||||
firstHopData, err := firstHopTLVs.Serialize()
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
firstHopBlob = fn.Some(firstHopData)
|
||||
}
|
||||
|
||||
edge := edgeUnifier.getEdge(
|
||||
netAmountReceived, g.bandwidthHints,
|
||||
partialPath.outboundFee,
|
||||
fn.Some[tlv.Blob](firstHopData),
|
||||
partialPath.outboundFee, firstHopBlob,
|
||||
)
|
||||
|
||||
if edge == nil {
|
||||
|
|
|
@ -234,7 +234,7 @@ func (u *edgeUnifier) getEdgeLocal(netAmtReceived lnwire.MilliSatoshi,
|
|||
amt := netAmtReceived + lnwire.MilliSatoshi(inboundFee)
|
||||
|
||||
// Check valid amount range for the channel.
|
||||
if !edge.amtInRange(amt) {
|
||||
if htlcBlob.IsNone() && !edge.amtInRange(amt) {
|
||||
log.Debugf("Amount %v not in range for edge %v",
|
||||
netAmtReceived, edge.policy.ChannelID)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue