From 81fe6e73ed0f6b9148ce483caa223ebbd25bcb06 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Tue, 4 Dec 2018 11:20:38 +0100 Subject: [PATCH] router+graph: return ErrGraphNodesNotFound if no nodes to prune Avoids creating a bucket unneccessarily. --- channeldb/graph.go | 6 +++--- routing/router.go | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/channeldb/graph.go b/channeldb/graph.go index 21680eb4a..7cf7f8987 100644 --- a/channeldb/graph.go +++ b/channeldb/graph.go @@ -795,9 +795,9 @@ func (c *ChannelGraph) PruneGraph(spentOutputs []*wire.OutPoint, // node gains more channels, it will be re-added back to the graph. func (c *ChannelGraph) PruneGraphNodes() error { return c.db.Update(func(tx *bbolt.Tx) error { - nodes, err := tx.CreateBucketIfNotExists(nodeBucket) - if err != nil { - return err + nodes := tx.Bucket(nodeBucket) + if nodes == nil { + return ErrGraphNodesNotFound } edges := tx.Bucket(edgeBucket) if edges == nil { diff --git a/routing/router.go b/routing/router.go index 0e1a9b269..d815592fe 100644 --- a/routing/router.go +++ b/routing/router.go @@ -445,7 +445,8 @@ func (r *ChannelRouter) Start() error { // Finally, before we proceed, we'll prune any unconnected nodes from // the graph in order to ensure we maintain a tight graph of "useful" // nodes. - if err := r.cfg.Graph.PruneGraphNodes(); err != nil { + err = r.cfg.Graph.PruneGraphNodes() + if err != nil && err != channeldb.ErrGraphNodesNotFound { return err }