From 351f4aab798aa0398a05740e747d02071bcbe810 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Tue, 4 Dec 2018 11:20:38 +0100 Subject: [PATCH] channeldb/graph: don't create buckets in DeleteChannelEdge Instead return ErrEdgeNotFound if buckets don't exist. This would be returned anyway, when the chanIndex is checked for the channel point in question. --- channeldb/graph.go | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/channeldb/graph.go b/channeldb/graph.go index 6a7d496a..ce98cd76 100644 --- a/channeldb/graph.go +++ b/channeldb/graph.go @@ -1067,25 +1067,30 @@ func (c *ChannelGraph) DeleteChannelEdge(chanPoint *wire.OutPoint) error { return c.db.Update(func(tx *bbolt.Tx) error { // First grab the edges bucket which houses the information // we'd like to delete - edges, err := tx.CreateBucketIfNotExists(edgeBucket) - if err != nil { - return err + edges := tx.Bucket(edgeBucket) + if edges == nil { + return ErrEdgeNotFound } - // Next grab the two edge indexes which will also need to be updated. - edgeIndex, err := edges.CreateBucketIfNotExists(edgeIndexBucket) - if err != nil { - return err + + // Next grab the two edge indexes which will also need to be + // updated. + edgeIndex := edges.Bucket(edgeIndexBucket) + if edgeIndex == nil { + return ErrEdgeNotFound } - chanIndex, err := edges.CreateBucketIfNotExists(channelPointBucket) - if err != nil { - return err + + chanIndex := edges.Bucket(channelPointBucket) + if chanIndex == nil { + return ErrEdgeNotFound } nodes, err := tx.CreateBucketIfNotExists(nodeBucket) if err != nil { return err } - return delChannelByEdge(edges, edgeIndex, chanIndex, nodes, chanPoint) + return delChannelByEdge( + edges, edgeIndex, chanIndex, nodes, chanPoint, + ) }) }