From 3db06cf7d5722df7b38139bae25bb73e8f11b76b Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 11 Jun 2018 23:06:08 -0700 Subject: [PATCH] htlcswitch: in removeLink properly remove items from the interfaceIndex In this commit, we fix a bug in the way we handle removing items from the interfaceIndex. Before this commit, we would delete all items items with the target public key that of the peer that owns the link being removed. However, this is incorrect as the peer may have other links sill active. In this commit, we fix this by first only deleting the link from the peer's index, and then checking to see if the index is empty after this deletion. Only if so do we delete the index for the peer all together. --- htlcswitch/switch.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/htlcswitch/switch.go b/htlcswitch/switch.go index d99d0182..b953e807 100644 --- a/htlcswitch/switch.go +++ b/htlcswitch/switch.go @@ -1840,9 +1840,18 @@ func (s *Switch) removeLink(chanID lnwire.ChannelID) error { delete(s.linkIndex, link.ChanID()) delete(s.forwardingIndex, link.ShortChanID()) - // Remove the channel from channel index. + // If the link has been added to the peer index, then we'll move to + // delete the entry within the index. peerPub := link.Peer().PubKey() - delete(s.interfaceIndex, peerPub) + if peerIndex, ok := s.interfaceIndex[peerPub]; ok { + delete(peerIndex, link.ChanID()) + + // If after deletion, there are no longer any links, then we'll + // remove the interface map all together. + if len(peerIndex) == 0 { + delete(s.interfaceIndex, peerPub) + } + } link.Stop()