diff --git a/channeldb/migrations.go b/channeldb/migrations.go index 810e14d9..e98bf238 100644 --- a/channeldb/migrations.go +++ b/channeldb/migrations.go @@ -4,7 +4,6 @@ import ( "bytes" "crypto/sha256" "encoding/binary" - "errors" "fmt" "github.com/coreos/bbolt" @@ -474,20 +473,24 @@ func migratePruneEdgeUpdateIndex(tx *bolt.Tx) error { if edges == nil { return nil } - edgeUpdateIndex := edges.Bucket(edgeUpdateIndexBucket) - if edgeUpdateIndex == nil { - return nil + edgeUpdateIndex, err := edges.CreateBucketIfNotExists( + edgeUpdateIndexBucket, + ) + if err != nil { + return fmt.Errorf("unable to create/fetch edge update " + + "index bucket") } // Retrieve some buckets that will be needed later on. These should // already exist given the assumption that the buckets above do as well. - edgeIndex := edges.Bucket(edgeIndexBucket) + edgeIndex, err := edges.CreateBucketIfNotExists(edgeIndexBucket) if edgeIndex == nil { - return errors.New("edge index should exist but does not") + return fmt.Errorf("unable to create/fetch edge index " + + "bucket") } - nodes := tx.Bucket(nodeBucket) - if nodes == nil { - return errors.New("node bucket should exist but does not") + nodes, err := tx.CreateBucketIfNotExists(nodeBucket) + if err != nil { + return fmt.Errorf("unable to make node bucket") } log.Info("Migrating database to properly prune edge update index") @@ -496,7 +499,7 @@ func migratePruneEdgeUpdateIndex(tx *bolt.Tx) error { // update index. To do so, we'll gather all of the existing policies // within the graph to re-populate them later on. var edgeKeys [][]byte - err := edges.ForEach(func(edgeKey, edgePolicyBytes []byte) error { + err = edges.ForEach(func(edgeKey, edgePolicyBytes []byte) error { // All valid entries are indexed by a public key (33 bytes) // followed by a channel ID (8 bytes), so we'll skip any entries // with keys that do not match this.