From 2c3041d8bc16ee44b39f8733e2704e79a386a09a Mon Sep 17 00:00:00 2001 From: Andras Banki-Horvath Date: Thu, 19 Dec 2019 22:19:18 +0100 Subject: [PATCH] autopilot: fix memChannelGraph channel edge addition This PR fixes an issue that happens when adding a new channel edge between two nodes in a memChannelGraph. Originally a channel edge held a node value which made the graph different when iterating from the two endpoints of an edge. This is simply fixed by holding pointers instead. --- autopilot/graph.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/autopilot/graph.go b/autopilot/graph.go index f02d0a8e..03d33f92 100644 --- a/autopilot/graph.go +++ b/autopilot/graph.go @@ -307,7 +307,7 @@ func (d *databaseChannelGraph) addRandNode() (*btcec.PublicKey, error) { // memChannelGraph is an implementation of the autopilot.ChannelGraph backed by // an in-memory graph. type memChannelGraph struct { - graph map[NodeID]memNode + graph map[NodeID]*memNode } // A compile time assertion to ensure memChannelGraph meets the @@ -318,7 +318,7 @@ var _ ChannelGraph = (*memChannelGraph)(nil) // implementation. func newMemChannelGraph() *memChannelGraph { return &memChannelGraph{ - graph: make(map[NodeID]memNode), + graph: make(map[NodeID]*memNode), } } @@ -360,14 +360,14 @@ func (m *memChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey, capacity btcutil.Amount) (*ChannelEdge, *ChannelEdge, error) { var ( - vertex1, vertex2 memNode + vertex1, vertex2 *memNode ok bool ) if node1 != nil { vertex1, ok = m.graph[NewNodeID(node1)] if !ok { - vertex1 = memNode{ + vertex1 = &memNode{ pub: node1, addrs: []net.Addr{ &net.TCPAddr{ @@ -381,7 +381,7 @@ func (m *memChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey, if err != nil { return nil, nil, err } - vertex1 = memNode{ + vertex1 = &memNode{ pub: newPub, addrs: []net.Addr{ &net.TCPAddr{ @@ -394,7 +394,7 @@ func (m *memChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey, if node2 != nil { vertex2, ok = m.graph[NewNodeID(node2)] if !ok { - vertex2 = memNode{ + vertex2 = &memNode{ pub: node2, addrs: []net.Addr{ &net.TCPAddr{ @@ -408,7 +408,7 @@ func (m *memChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey, if err != nil { return nil, nil, err } - vertex2 = memNode{ + vertex2 = &memNode{ pub: newPub, addrs: []net.Addr{ &net.TCPAddr{ @@ -446,7 +446,7 @@ func (m *memChannelGraph) addRandNode() (*btcec.PublicKey, error) { if err != nil { return nil, err } - vertex := memNode{ + vertex := &memNode{ pub: newPub, addrs: []net.Addr{ &net.TCPAddr{