mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-11-10 14:17:56 +01:00
routing: return error for getBandwidth and log it
This commit is contained in:
@@ -85,25 +85,18 @@ func newBandwidthManager(graph Graph, sourceNode route.Vertex,
|
|||||||
// queried is one of our local channels, so any failure to retrieve the link
|
// queried is one of our local channels, so any failure to retrieve the link
|
||||||
// is interpreted as the link being offline.
|
// is interpreted as the link being offline.
|
||||||
func (b *bandwidthManager) getBandwidth(cid lnwire.ShortChannelID,
|
func (b *bandwidthManager) getBandwidth(cid lnwire.ShortChannelID,
|
||||||
amount lnwire.MilliSatoshi) lnwire.MilliSatoshi {
|
amount lnwire.MilliSatoshi) (lnwire.MilliSatoshi, error) {
|
||||||
|
|
||||||
link, err := b.getLink(cid)
|
link, err := b.getLink(cid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If the link isn't online, then we'll report that it has
|
return 0, fmt.Errorf("error querying switch for link: %w", err)
|
||||||
// zero bandwidth.
|
|
||||||
log.Warnf("ShortChannelID=%v: link not found when "+
|
|
||||||
"determining bandwidth for local channel=%v, "+
|
|
||||||
"reporting 0 bandwidth", cid, err)
|
|
||||||
|
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the link is found within the switch, but it isn't yet eligible
|
// If the link is found within the switch, but it isn't yet eligible
|
||||||
// to forward any HTLCs, then we'll treat it as if it isn't online in
|
// to forward any HTLCs, then we'll treat it as if it isn't online in
|
||||||
// the first place.
|
// the first place.
|
||||||
if !link.EligibleToForward() {
|
if !link.EligibleToForward() {
|
||||||
log.Warnf("ShortChannelID=%v: not eligible to forward", cid)
|
return 0, fmt.Errorf("link not eligible to forward")
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// bandwidthResult is an inline type that we'll use to pass the
|
// bandwidthResult is an inline type that we'll use to pass the
|
||||||
@@ -168,10 +161,8 @@ func (b *bandwidthManager) getBandwidth(cid lnwire.ShortChannelID,
|
|||||||
},
|
},
|
||||||
).Unpack()
|
).Unpack()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("ShortChannelID=%v: failed to get bandwidth from "+
|
return 0, fmt.Errorf("failed to consult external traffic "+
|
||||||
"external traffic shaper: %v", cid, err)
|
"shaper: %w", err)
|
||||||
|
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
htlcAmount := result.htlcAmount.UnwrapOr(amount)
|
htlcAmount := result.htlcAmount.UnwrapOr(amount)
|
||||||
@@ -179,9 +170,8 @@ func (b *bandwidthManager) getBandwidth(cid lnwire.ShortChannelID,
|
|||||||
// If our link isn't currently in a state where it can add another
|
// If our link isn't currently in a state where it can add another
|
||||||
// outgoing htlc, treat the link as unusable.
|
// outgoing htlc, treat the link as unusable.
|
||||||
if err := link.MayAddOutgoingHtlc(htlcAmount); err != nil {
|
if err := link.MayAddOutgoingHtlc(htlcAmount); err != nil {
|
||||||
log.Warnf("ShortChannelID=%v: cannot add outgoing "+
|
return 0, fmt.Errorf("cannot add outgoing htlc to channel %v "+
|
||||||
"htlc with amount %v: %v", cid, htlcAmount, err)
|
"with amount %v: %w", cid, htlcAmount, err)
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the external traffic shaper determined the bandwidth, we'll return
|
// If the external traffic shaper determined the bandwidth, we'll return
|
||||||
@@ -189,7 +179,7 @@ func (b *bandwidthManager) getBandwidth(cid lnwire.ShortChannelID,
|
|||||||
// available on that channel).
|
// available on that channel).
|
||||||
reportedBandwidth := result.bandwidth.UnwrapOr(linkBandwidth)
|
reportedBandwidth := result.bandwidth.UnwrapOr(linkBandwidth)
|
||||||
|
|
||||||
return reportedBandwidth
|
return reportedBandwidth, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// availableChanBandwidth returns the total available bandwidth for a channel
|
// availableChanBandwidth returns the total available bandwidth for a channel
|
||||||
@@ -204,7 +194,15 @@ func (b *bandwidthManager) availableChanBandwidth(channelID uint64,
|
|||||||
return 0, false
|
return 0, false
|
||||||
}
|
}
|
||||||
|
|
||||||
return b.getBandwidth(shortID, amount), true
|
bandwidth, err := b.getBandwidth(shortID, amount)
|
||||||
|
if err != nil {
|
||||||
|
log.Warnf("failed to get bandwidth for channel %v: %v",
|
||||||
|
shortID, err)
|
||||||
|
|
||||||
|
return 0, true
|
||||||
|
}
|
||||||
|
|
||||||
|
return bandwidth, true
|
||||||
}
|
}
|
||||||
|
|
||||||
// firstHopCustomBlob returns the custom blob for the first hop of the payment,
|
// firstHopCustomBlob returns the custom blob for the first hop of the payment,
|
||||||
|
|||||||
@@ -551,8 +551,7 @@ func getOutgoingBalance(node route.Vertex, outgoingChans map[uint64]struct{},
|
|||||||
log.Warnf("ShortChannelID=%v: not found in the local "+
|
log.Warnf("ShortChannelID=%v: not found in the local "+
|
||||||
"channels map of the bandwidth manager, "+
|
"channels map of the bandwidth manager, "+
|
||||||
"using channel capacity=%v as bandwidth for "+
|
"using channel capacity=%v as bandwidth for "+
|
||||||
"this channel", shortID, bandwidth,
|
"this channel", shortID, bandwidth)
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if bandwidth > max {
|
if bandwidth > max {
|
||||||
|
|||||||
Reference in New Issue
Block a user