From 79807022a53982ed40897844ec01d8097706c1b7 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Fri, 14 Apr 2017 13:14:54 -0700 Subject: [PATCH] routing: update graph traversal to use latest API --- routing/pathfind.go | 6 ++++-- routing/router.go | 8 ++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/routing/pathfind.go b/routing/pathfind.go index c72a665c..5ccc2911 100644 --- a/routing/pathfind.go +++ b/routing/pathfind.go @@ -5,6 +5,7 @@ import ( "container/heap" + "github.com/boltdb/bolt" "github.com/lightningnetwork/lnd/channeldb" "github.com/roasbeef/btcd/btcec" "github.com/roasbeef/btcd/chaincfg/chainhash" @@ -277,7 +278,7 @@ func findPath(graph *channeldb.ChannelGraph, sourceNode *channeldb.LightningNode // map for the node set with a distance of "infinity". We also mark // add the node to our set of unvisited nodes. distance := make(map[vertex]nodeWithDist) - if err := graph.ForEachNode(func(node *channeldb.LightningNode) error { + if err := graph.ForEachNode(nil, func(_ *bolt.Tx, node *channeldb.LightningNode) error { // TODO(roasbeef): with larger graph can just use disk seeks // with a visited map distance[newVertex(node.PubKey)] = nodeWithDist{ @@ -323,7 +324,8 @@ func findPath(graph *channeldb.ChannelGraph, sourceNode *channeldb.LightningNode // examine all the outgoing edge (channels) from this node to // further our graph traversal. pivot := newVertex(bestNode.PubKey) - err := bestNode.ForEachChannel(nil, func(edgeInfo *channeldb.ChannelEdgeInfo, + err := bestNode.ForEachChannel(nil, func(tx *bolt.Tx, + edgeInfo *channeldb.ChannelEdgeInfo, edge *channeldb.ChannelEdgePolicy) error { v := newVertex(edge.Node.PubKey) diff --git a/routing/router.go b/routing/router.go index d409458e..1aa9d58b 100644 --- a/routing/router.go +++ b/routing/router.go @@ -7,6 +7,7 @@ import ( "sync" "sync/atomic" + "github.com/boltdb/bolt" "github.com/davecgh/go-spew/spew" "github.com/lightningnetwork/lnd/chainntnfs" "github.com/lightningnetwork/lnd/channeldb" @@ -1057,7 +1058,9 @@ func (r *ChannelRouter) GetChannelByID(chanID lnwire.ShortChannelID) ( // // NOTE: This method is part of the ChannelGraphSource interface. func (r *ChannelRouter) ForEachNode(cb func(*channeldb.LightningNode) error) error { - return r.cfg.Graph.ForEachNode(cb) + return r.cfg.Graph.ForEachNode(nil, func(_ *bolt.Tx, n *channeldb.LightningNode) error { + return cb(n) + }) } // ForAllOutgoingChannels is used to iterate over all outgiong channel owned by @@ -1066,8 +1069,9 @@ func (r *ChannelRouter) ForEachNode(cb func(*channeldb.LightningNode) error) err // NOTE: This method is part of the ChannelGraphSource interface. func (r *ChannelRouter) ForAllOutgoingChannels(cb func(c *channeldb.ChannelEdgePolicy) error) error { - return r.selfNode.ForEachChannel(nil, func(_ *channeldb.ChannelEdgeInfo, + return r.selfNode.ForEachChannel(nil, func(_ *bolt.Tx, _ *channeldb.ChannelEdgeInfo, c *channeldb.ChannelEdgePolicy) error { + return cb(c) }) }