From 8a7085f8b4d31d3d91cee0a8ad38a3dbb43310c9 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 7 Dec 2017 19:03:22 -0800 Subject: [PATCH] htlcswitch: ensure we don't dispatch local HTLC's to link that aren't eligible to forward MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit fixes an existing bug wherein we would incorrectly attempt to forward and HTLC to a link that wasn’t yet eligible for forwarding. This would occur when we’ve added a link to the switch, but haven’t yet received a FundingLocked message for the channel. As a result, the channel won’t have the next revocation point available. A logic error prior to this commit would skip tallying the largest bandwidth rather than skipping examining the link all together. Fixes #464. --- htlcswitch/switch.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/htlcswitch/switch.go b/htlcswitch/switch.go index 5bc3d3cbe..b375dd381 100644 --- a/htlcswitch/switch.go +++ b/htlcswitch/switch.go @@ -365,9 +365,14 @@ func (s *Switch) handleLocalDispatch(payment *pendingPayment, packet *htlcPacket largestBandwidth lnwire.MilliSatoshi ) for _, link := range links { + // We'll skip any links that aren't yet eligible for + // forwarding. + if !link.EligibleToForward() { + continue + } + bandwidth := link.Bandwidth() - if link.EligibleToForward() && - bandwidth > largestBandwidth { + if bandwidth > largestBandwidth { largestBandwidth = bandwidth } @@ -490,8 +495,13 @@ func (s *Switch) handlePacketForward(packet *htlcPacket) error { // bandwidth. var destination ChannelLink for _, link := range interfaceLinks { - if link.EligibleToForward() && - link.Bandwidth() >= htlc.Amount { + // We'll skip any links that aren't yet eligible for + // forwarding. + if !link.EligibleToForward() { + continue + } + + if link.Bandwidth() >= htlc.Amount { destination = link break