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.
This commit is contained in:
parent
03810603ee
commit
3db06cf7d5
@ -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()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user