From 03810603ee1926ec23d8c4984a213dedfa03ed34 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 11 Jun 2018 23:02:07 -0700 Subject: [PATCH] htlcswitch: modify interfaceIndex to no longer key 2nd lvl by ChannelLink In this commit, we modify the interfaceIndex to no longer key the second level of the index by the ChannelLink. Instead, we'll use the chan ID as it's a stable identifier, unlike a reference to an interface. --- htlcswitch/switch.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/htlcswitch/switch.go b/htlcswitch/switch.go index dcb6714da..d99d0182d 100644 --- a/htlcswitch/switch.go +++ b/htlcswitch/switch.go @@ -202,8 +202,8 @@ type Switch struct { forwardingIndex map[lnwire.ShortChannelID]ChannelLink // interfaceIndex maps the compressed public key of a peer to all the - // channels that the switch maintains iwht that peer. - interfaceIndex map[[33]byte]map[ChannelLink]struct{} + // channels that the switch maintains with that peer. + interfaceIndex map[[33]byte]map[lnwire.ChannelID]ChannelLink // htlcPlex is the channel which all connected links use to coordinate // the setup/teardown of Sphinx (onion routing) payment circuits. @@ -253,7 +253,7 @@ func New(cfg Config) (*Switch, error) { linkIndex: make(map[lnwire.ChannelID]ChannelLink), mailOrchestrator: newMailOrchestrator(), forwardingIndex: make(map[lnwire.ShortChannelID]ChannelLink), - interfaceIndex: make(map[[33]byte]map[ChannelLink]struct{}), + interfaceIndex: make(map[[33]byte]map[lnwire.ChannelID]ChannelLink), pendingLinkIndex: make(map[lnwire.ChannelID]ChannelLink), pendingPayments: make(map[uint64]*pendingPayment), htlcPlex: make(chan *plexPacket), @@ -1774,9 +1774,9 @@ func (s *Switch) addLiveLink(link ChannelLink) { // quickly look up all the channels for a particular node. peerPub := link.Peer().PubKey() if _, ok := s.interfaceIndex[peerPub]; !ok { - s.interfaceIndex[peerPub] = make(map[ChannelLink]struct{}) + s.interfaceIndex[peerPub] = make(map[lnwire.ChannelID]ChannelLink) } - s.interfaceIndex[peerPub][link] = struct{}{} + s.interfaceIndex[peerPub][link.ChanID()] = link } // GetLink is used to initiate the handling of the get link command. The @@ -1918,7 +1918,7 @@ func (s *Switch) getLinks(destination [33]byte) ([]ChannelLink, error) { } channelLinks := make([]ChannelLink, 0, len(links)) - for link := range links { + for _, link := range links { channelLinks = append(channelLinks, link) }