routing: avoid internal bolt db deadlock by reusing transaction in findPath

This commit fixes a bug that could lead to a deadlock inside bolt db
itself. In a recent commit we allowed a db transaction to be passed
directly into findPath, however, the initial call to graph.ForEachNode
instead passed a _nil_ transaction causing the method itself to create
a _new_ transaction, leading to a deadlock.

We fix this issue by instead re-using the transaction pointer.
This commit is contained in:
Olaoluwa Osuntokun 2017-10-16 18:48:21 -07:00
parent 0692d2d408
commit ae6bde2d77
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

@ -392,7 +392,7 @@ func findPath(tx *bolt.Tx, graph *channeldb.ChannelGraph,
// 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(nil, func(_ *bolt.Tx, node *channeldb.LightningNode) error {
if err := graph.ForEachNode(tx, 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{
@ -423,7 +423,6 @@ func findPath(tx *bolt.Tx, graph *channeldb.ChannelGraph,
// We'll use this map as a series of "previous" hop pointers. So to get
// to `vertex` we'll take the edge that it's mapped to within `prev`.
prev := make(map[vertex]edgeWithPrev)
for nodeHeap.Len() != 0 {
// Fetch the node within the smallest distance from our source
// from the heap.