From 164250d1cd78ff9129a8adbb78e7b4c78907fc3e Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Thu, 10 Jan 2019 16:34:02 -0800 Subject: [PATCH] htlcswitch/switch: check EligibleToForward in HasActiveLink This commit modifies the behavior of the HasActiveLink method within the switch to only return true if the link is in the link index and is eligible to forward HTLCs. The prior version returns true whenever the link is found in the link index, which may return true for pending channels that are not actually active. --- htlcswitch/switch.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/htlcswitch/switch.go b/htlcswitch/switch.go index ce2bfc58..597468aa 100644 --- a/htlcswitch/switch.go +++ b/htlcswitch/switch.go @@ -1990,13 +1990,16 @@ func (s *Switch) getLinkByShortID(chanID lnwire.ShortChannelID) (ChannelLink, er } // HasActiveLink returns true if the given channel ID has a link in the link -// index. +// index AND the link is eligible to forward. func (s *Switch) HasActiveLink(chanID lnwire.ChannelID) bool { s.indexMtx.RLock() defer s.indexMtx.RUnlock() - _, ok := s.linkIndex[chanID] - return ok + if link, ok := s.linkIndex[chanID]; ok { + return link.EligibleToForward() + } + + return false } // RemoveLink purges the switch of any link associated with chanID. If a pending