htlcswitch: in local outgoing payment attempt print a nicer error if no bandwidth
This commit modifies the error we return to the end user in the case of an insufficient link capacity error when handling a local payment dispatch. Previously we would return a lnwire.CodeTemporaryChannelFailure, however, this isn’t necessary as this is a local payment attempt and we don’t give up any sensitive information by returning the best available bandwidth, and what we need to complete the payment.
This commit is contained in:
parent
7eb0e56406
commit
7038842f03
@ -343,9 +343,17 @@ func (s *Switch) handleLocalDispatch(payment *pendingPayment, packet *htlcPacket
|
||||
|
||||
// Try to find destination channel link with appropriate
|
||||
// bandwidth.
|
||||
var destination ChannelLink
|
||||
var (
|
||||
destination ChannelLink
|
||||
largestBandwidth lnwire.MilliSatoshi
|
||||
)
|
||||
for _, link := range links {
|
||||
if link.Bandwidth() >= htlc.Amount {
|
||||
bandwidth := link.Bandwidth()
|
||||
if bandwidth > largestBandwidth {
|
||||
largestBandwidth = bandwidth
|
||||
}
|
||||
|
||||
if bandwidth >= htlc.Amount {
|
||||
destination = link
|
||||
break
|
||||
}
|
||||
@ -355,9 +363,11 @@ func (s *Switch) handleLocalDispatch(payment *pendingPayment, packet *htlcPacket
|
||||
// over has insufficient capacity, then we'll cancel the HTLC
|
||||
// as the payment cannot succeed.
|
||||
if destination == nil {
|
||||
log.Errorf("unable to find appropriate channel link "+
|
||||
"insufficient capacity, need %v", htlc.Amount)
|
||||
return errors.New(lnwire.CodeTemporaryChannelFailure)
|
||||
err := fmt.Errorf("insufficient capacity in available "+
|
||||
"outgoing links: need %v, max available is %v",
|
||||
htlc.Amount, largestBandwidth)
|
||||
log.Error(err)
|
||||
return err
|
||||
}
|
||||
|
||||
// Send the packet to the destination channel link which
|
||||
|
Loading…
Reference in New Issue
Block a user