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.
This commit is contained in:
Johan T. Halseth 2018-12-04 11:20:38 +01:00
parent 5d8d99b7bc
commit 351f4aab79
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

@ -1067,25 +1067,30 @@ func (c *ChannelGraph) DeleteChannelEdge(chanPoint *wire.OutPoint) error {
return c.db.Update(func(tx *bbolt.Tx) error { return c.db.Update(func(tx *bbolt.Tx) error {
// First grab the edges bucket which houses the information // First grab the edges bucket which houses the information
// we'd like to delete // we'd like to delete
edges, err := tx.CreateBucketIfNotExists(edgeBucket) edges := tx.Bucket(edgeBucket)
if err != nil { if edges == nil {
return err return ErrEdgeNotFound
} }
// Next grab the two edge indexes which will also need to be updated.
edgeIndex, err := edges.CreateBucketIfNotExists(edgeIndexBucket) // Next grab the two edge indexes which will also need to be
if err != nil { // updated.
return err edgeIndex := edges.Bucket(edgeIndexBucket)
if edgeIndex == nil {
return ErrEdgeNotFound
} }
chanIndex, err := edges.CreateBucketIfNotExists(channelPointBucket)
if err != nil { chanIndex := edges.Bucket(channelPointBucket)
return err if chanIndex == nil {
return ErrEdgeNotFound
} }
nodes, err := tx.CreateBucketIfNotExists(nodeBucket) nodes, err := tx.CreateBucketIfNotExists(nodeBucket)
if err != nil { if err != nil {
return err return err
} }
return delChannelByEdge(edges, edgeIndex, chanIndex, nodes, chanPoint) return delChannelByEdge(
edges, edgeIndex, chanIndex, nodes, chanPoint,
)
}) })
} }