From 7038842f0319d553e20171ee4c19ef01539fa109 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 2 Oct 2017 22:06:02 -0700 Subject: [PATCH] htlcswitch: in local outgoing payment attempt print a nicer error if no bandwidth MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- htlcswitch/switch.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/htlcswitch/switch.go b/htlcswitch/switch.go index 8bd45c6a..6d7948da 100644 --- a/htlcswitch/switch.go +++ b/htlcswitch/switch.go @@ -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