mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-06 17:47:01 +02:00
channeldb: convert to uniformly use new kvdb abstractions
In this commit, we migrate all the code in `channeldb` to only reference the new `kvdb` package rather than `bbolt` directly. In many instances, we need to add two version to fetch a bucket as both read and write when needed. As an example, we add a new `fetchChanBucketRw` function. This function is identical to `fetchChanBucket`, but it will be used to fetch the main channel bucket for all _write_ transactions. We need a new method as you can pass a write transaction where a read is accepted, but not the other way around due to the stronger typing of the new `kvdb` package.
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/coreos/bbolt"
|
||||
"github.com/lightningnetwork/lnd/channeldb/kvdb"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -19,7 +19,7 @@ const (
|
||||
// migration is a function which takes a prior outdated version of the database
|
||||
// instances and mutates the key/bucket structure to arrive at a more
|
||||
// up-to-date version of the database.
|
||||
type migration func(tx *bbolt.Tx) error
|
||||
type migration func(tx kvdb.RwTx) error
|
||||
|
||||
var (
|
||||
// Big endian is the preferred byte order, due to cursor scans over
|
||||
@@ -31,7 +31,7 @@ var (
|
||||
// information related to nodes, routing data, open/closed channels, fee
|
||||
// schedules, and reputation data.
|
||||
type DB struct {
|
||||
*bbolt.DB
|
||||
kvdb.Backend
|
||||
dbPath string
|
||||
graph *ChannelGraph
|
||||
now func() time.Time
|
||||
@@ -55,20 +55,15 @@ func Open(dbPath string, modifiers ...OptionModifier) (*DB, error) {
|
||||
|
||||
// Specify bbolt freelist options to reduce heap pressure in case the
|
||||
// freelist grows to be very large.
|
||||
options := &bbolt.Options{
|
||||
NoFreelistSync: opts.NoFreelistSync,
|
||||
FreelistType: bbolt.FreelistMapType,
|
||||
}
|
||||
|
||||
bdb, err := bbolt.Open(path, dbFilePermission, options)
|
||||
bdb, err := kvdb.Open(kvdb.BoltBackendName, path, opts.NoFreelistSync)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
chanDB := &DB{
|
||||
DB: bdb,
|
||||
dbPath: dbPath,
|
||||
now: time.Now,
|
||||
Backend: bdb,
|
||||
dbPath: dbPath,
|
||||
now: time.Now,
|
||||
}
|
||||
chanDB.graph = newChannelGraph(
|
||||
chanDB, opts.RejectCacheSize, opts.ChannelCacheSize,
|
||||
@@ -89,28 +84,28 @@ func createChannelDB(dbPath string) error {
|
||||
}
|
||||
|
||||
path := filepath.Join(dbPath, dbName)
|
||||
bdb, err := bbolt.Open(path, dbFilePermission, nil)
|
||||
bdb, err := kvdb.Create(kvdb.BoltBackendName, path, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = bdb.Update(func(tx *bbolt.Tx) error {
|
||||
if _, err := tx.CreateBucket(openChannelBucket); err != nil {
|
||||
err = kvdb.Update(bdb, func(tx kvdb.RwTx) error {
|
||||
if _, err := tx.CreateTopLevelBucket(openChannelBucket); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := tx.CreateBucket(closedChannelBucket); err != nil {
|
||||
if _, err := tx.CreateTopLevelBucket(closedChannelBucket); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := tx.CreateBucket(invoiceBucket); err != nil {
|
||||
if _, err := tx.CreateTopLevelBucket(invoiceBucket); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := tx.CreateBucket(paymentBucket); err != nil {
|
||||
if _, err := tx.CreateTopLevelBucket(paymentBucket); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
nodes, err := tx.CreateBucket(nodeBucket)
|
||||
nodes, err := tx.CreateTopLevelBucket(nodeBucket)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -123,7 +118,7 @@ func createChannelDB(dbPath string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
edges, err := tx.CreateBucket(edgeBucket)
|
||||
edges, err := tx.CreateTopLevelBucket(edgeBucket)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -140,7 +135,7 @@ func createChannelDB(dbPath string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
graphMeta, err := tx.CreateBucket(graphMetaBucket)
|
||||
graphMeta, err := tx.CreateTopLevelBucket(graphMetaBucket)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -149,7 +144,7 @@ func createChannelDB(dbPath string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := tx.CreateBucket(metaBucket); err != nil {
|
||||
if _, err := tx.CreateTopLevelBucket(metaBucket); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -185,8 +180,8 @@ func fileExists(path string) bool {
|
||||
func (d *DB) FetchClosedChannels(pendingOnly bool) ([]*ChannelCloseSummary, error) {
|
||||
var chanSummaries []*ChannelCloseSummary
|
||||
|
||||
if err := d.View(func(tx *bbolt.Tx) error {
|
||||
closeBucket := tx.Bucket(closedChannelBucket)
|
||||
if err := kvdb.View(d, func(tx kvdb.ReadTx) error {
|
||||
closeBucket := tx.ReadBucket(closedChannelBucket)
|
||||
if closeBucket == nil {
|
||||
return ErrNoClosedChannels
|
||||
}
|
||||
|
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/coreos/bbolt"
|
||||
"github.com/lightningnetwork/lnd/channeldb/kvdb"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
)
|
||||
|
||||
@@ -175,10 +175,10 @@ func newChannelGraph(db *DB, rejectCacheSize, chanCacheSize int) *ChannelGraph {
|
||||
// node based off the source node.
|
||||
func (c *ChannelGraph) SourceNode() (*LightningNode, error) {
|
||||
var source *LightningNode
|
||||
err := c.db.View(func(tx *bbolt.Tx) error {
|
||||
err := kvdb.View(c.db, func(tx kvdb.ReadTx) error {
|
||||
// First grab the nodes bucket which stores the mapping from
|
||||
// pubKey to node information.
|
||||
nodes := tx.Bucket(nodeBucket)
|
||||
nodes := tx.ReadBucket(nodeBucket)
|
||||
if nodes == nil {
|
||||
return ErrGraphNotFound
|
||||
}
|
||||
@@ -202,7 +202,7 @@ func (c *ChannelGraph) SourceNode() (*LightningNode, error) {
|
||||
// of the graph. The source node is treated as the center node within a
|
||||
// star-graph. This method may be used to kick off a path finding algorithm in
|
||||
// order to explore the reachability of another node based off the source node.
|
||||
func (c *ChannelGraph) sourceNode(nodes *bbolt.Bucket) (*LightningNode, error) {
|
||||
func (c *ChannelGraph) sourceNode(nodes kvdb.ReadBucket) (*LightningNode, error) {
|
||||
selfPub := nodes.Get(sourceKey)
|
||||
if selfPub == nil {
|
||||
return nil, ErrSourceNodeNotSet
|
||||
@@ -225,10 +225,10 @@ func (c *ChannelGraph) sourceNode(nodes *bbolt.Bucket) (*LightningNode, error) {
|
||||
func (c *ChannelGraph) SetSourceNode(node *LightningNode) error {
|
||||
nodePubBytes := node.PubKeyBytes[:]
|
||||
|
||||
return c.db.Update(func(tx *bbolt.Tx) error {
|
||||
return kvdb.Update(c.db, func(tx kvdb.RwTx) error {
|
||||
// First grab the nodes bucket which stores the mapping from
|
||||
// pubKey to node information.
|
||||
nodes, err := tx.CreateBucketIfNotExists(nodeBucket)
|
||||
nodes, err := tx.CreateTopLevelBucket(nodeBucket)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -245,8 +245,8 @@ func (c *ChannelGraph) SetSourceNode(node *LightningNode) error {
|
||||
})
|
||||
}
|
||||
|
||||
func addLightningNode(tx *bbolt.Tx, node *LightningNode) error {
|
||||
nodes, err := tx.CreateBucketIfNotExists(nodeBucket)
|
||||
func addLightningNode(tx kvdb.RwTx, node *LightningNode) error {
|
||||
nodes, err := tx.CreateTopLevelBucket(nodeBucket)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -270,17 +270,17 @@ func addLightningNode(tx *bbolt.Tx, node *LightningNode) error {
|
||||
// buckets using an existing database transaction. The returned boolean will be
|
||||
// true if the updated policy belongs to node1, and false if the policy belonged
|
||||
// to node2.
|
||||
func updateEdgePolicy(tx *bbolt.Tx, edge *ChannelEdgePolicy) (bool, error) {
|
||||
edges := tx.Bucket(edgeBucket)
|
||||
if edges == nil {
|
||||
func updateEdgePolicy(tx kvdb.RwTx, edge *ChannelEdgePolicy) (bool, error) {
|
||||
edges, err := tx.CreateTopLevelBucket(edgeBucket)
|
||||
if err != nil {
|
||||
return false, ErrEdgeNotFound
|
||||
|
||||
}
|
||||
edgeIndex := edges.Bucket(edgeIndexBucket)
|
||||
edgeIndex := edges.NestedReadWriteBucket(edgeIndexBucket)
|
||||
if edgeIndex == nil {
|
||||
return false, ErrEdgeNotFound
|
||||
}
|
||||
nodes, err := tx.CreateBucketIfNotExists(nodeBucket)
|
||||
nodes, err := tx.CreateTopLevelBucket(nodeBucket)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -551,8 +551,8 @@ func (c *ChannelEdgePolicy) IsDisabled() bool {
|
||||
lnwire.ChanUpdateDisabled
|
||||
}
|
||||
|
||||
func putLightningNode(nodeBucket *bbolt.Bucket, aliasBucket *bbolt.Bucket,
|
||||
updateIndex *bbolt.Bucket, node *LightningNode) error {
|
||||
func putLightningNode(nodeBucket kvdb.RwBucket, aliasBucket kvdb.RwBucket,
|
||||
updateIndex kvdb.RwBucket, node *LightningNode) error {
|
||||
|
||||
var (
|
||||
scratch [16]byte
|
||||
@@ -680,7 +680,7 @@ func putLightningNode(nodeBucket *bbolt.Bucket, aliasBucket *bbolt.Bucket,
|
||||
return nodeBucket.Put(nodePub, b.Bytes())
|
||||
}
|
||||
|
||||
func fetchLightningNode(nodeBucket *bbolt.Bucket,
|
||||
func fetchLightningNode(nodeBucket kvdb.ReadBucket,
|
||||
nodePub []byte) (LightningNode, error) {
|
||||
|
||||
nodeBytes := nodeBucket.Get(nodePub)
|
||||
@@ -863,7 +863,7 @@ func deserializeChanEdgeInfo(r io.Reader) (ChannelEdgeInfo, error) {
|
||||
return edgeInfo, nil
|
||||
}
|
||||
|
||||
func putChanEdgePolicy(edges, nodes *bbolt.Bucket, edge *ChannelEdgePolicy,
|
||||
func putChanEdgePolicy(edges, nodes kvdb.RwBucket, edge *ChannelEdgePolicy,
|
||||
from, to []byte) error {
|
||||
|
||||
var edgeKey [33 + 8]byte
|
||||
@@ -943,7 +943,7 @@ func putChanEdgePolicy(edges, nodes *bbolt.Bucket, edge *ChannelEdgePolicy,
|
||||
// in this bucket.
|
||||
// Maintaining the bucket this way allows a fast retrieval of disabled
|
||||
// channels, for example when prune is needed.
|
||||
func updateEdgePolicyDisabledIndex(edges *bbolt.Bucket, chanID uint64,
|
||||
func updateEdgePolicyDisabledIndex(edges kvdb.RwBucket, chanID uint64,
|
||||
direction bool, disabled bool) error {
|
||||
|
||||
var disabledEdgeKey [8 + 1]byte
|
||||
@@ -968,7 +968,7 @@ func updateEdgePolicyDisabledIndex(edges *bbolt.Bucket, chanID uint64,
|
||||
|
||||
// putChanEdgePolicyUnknown marks the edge policy as unknown
|
||||
// in the edges bucket.
|
||||
func putChanEdgePolicyUnknown(edges *bbolt.Bucket, channelID uint64,
|
||||
func putChanEdgePolicyUnknown(edges kvdb.RwBucket, channelID uint64,
|
||||
from []byte) error {
|
||||
|
||||
var edgeKey [33 + 8]byte
|
||||
@@ -983,8 +983,8 @@ func putChanEdgePolicyUnknown(edges *bbolt.Bucket, channelID uint64,
|
||||
return edges.Put(edgeKey[:], unknownPolicy)
|
||||
}
|
||||
|
||||
func fetchChanEdgePolicy(edges *bbolt.Bucket, chanID []byte,
|
||||
nodePub []byte, nodes *bbolt.Bucket) (*ChannelEdgePolicy, error) {
|
||||
func fetchChanEdgePolicy(edges kvdb.ReadBucket, chanID []byte,
|
||||
nodePub []byte, nodes kvdb.ReadBucket) (*ChannelEdgePolicy, error) {
|
||||
|
||||
var edgeKey [33 + 8]byte
|
||||
copy(edgeKey[:], nodePub)
|
||||
@@ -1084,7 +1084,7 @@ func serializeChanEdgePolicy(w io.Writer, edge *ChannelEdgePolicy,
|
||||
}
|
||||
|
||||
func deserializeChanEdgePolicy(r io.Reader,
|
||||
nodes *bbolt.Bucket) (*ChannelEdgePolicy, error) {
|
||||
nodes kvdb.ReadBucket) (*ChannelEdgePolicy, error) {
|
||||
|
||||
edge := &ChannelEdgePolicy{}
|
||||
|
||||
|
@@ -8,7 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/coreos/bbolt"
|
||||
"github.com/lightningnetwork/lnd/channeldb/kvdb"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/tlv"
|
||||
@@ -252,8 +252,8 @@ func validateInvoice(i *Invoice) error {
|
||||
func (d *DB) FetchAllInvoices(pendingOnly bool) ([]Invoice, error) {
|
||||
var invoices []Invoice
|
||||
|
||||
err := d.View(func(tx *bbolt.Tx) error {
|
||||
invoiceB := tx.Bucket(invoiceBucket)
|
||||
err := kvdb.View(d, func(tx kvdb.ReadTx) error {
|
||||
invoiceB := tx.ReadBucket(invoiceBucket)
|
||||
if invoiceB == nil {
|
||||
return ErrNoInvoicesCreated
|
||||
}
|
||||
|
@@ -1,6 +1,8 @@
|
||||
package migration_01_to_11
|
||||
|
||||
import "github.com/coreos/bbolt"
|
||||
import (
|
||||
"github.com/lightningnetwork/lnd/channeldb/kvdb"
|
||||
)
|
||||
|
||||
var (
|
||||
// metaBucket stores all the meta information concerning the state of
|
||||
@@ -21,8 +23,8 @@ type Meta struct {
|
||||
// putMeta is an internal helper function used in order to allow callers to
|
||||
// re-use a database transaction. See the publicly exported PutMeta method for
|
||||
// more information.
|
||||
func putMeta(meta *Meta, tx *bbolt.Tx) error {
|
||||
metaBucket, err := tx.CreateBucketIfNotExists(metaBucket)
|
||||
func putMeta(meta *Meta, tx kvdb.RwTx) error {
|
||||
metaBucket, err := tx.CreateTopLevelBucket(metaBucket)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -30,7 +32,7 @@ func putMeta(meta *Meta, tx *bbolt.Tx) error {
|
||||
return putDbVersion(metaBucket, meta)
|
||||
}
|
||||
|
||||
func putDbVersion(metaBucket *bbolt.Bucket, meta *Meta) error {
|
||||
func putDbVersion(metaBucket kvdb.RwBucket, meta *Meta) error {
|
||||
scratch := make([]byte, 4)
|
||||
byteOrder.PutUint32(scratch, meta.DbVersionNumber)
|
||||
return metaBucket.Put(dbVersionKey, scratch)
|
||||
|
@@ -3,8 +3,8 @@ package migration_01_to_11
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/coreos/bbolt"
|
||||
"github.com/go-errors/errors"
|
||||
"github.com/lightningnetwork/lnd/channeldb/kvdb"
|
||||
)
|
||||
|
||||
// applyMigration is a helper test function that encapsulates the general steps
|
||||
@@ -49,7 +49,7 @@ func applyMigration(t *testing.T, beforeMigration, afterMigration func(d *DB),
|
||||
}()
|
||||
|
||||
// Apply migration.
|
||||
err = cdb.Update(func(tx *bbolt.Tx) error {
|
||||
err = kvdb.Update(cdb, func(tx kvdb.RwTx) error {
|
||||
return migrationFunc(tx)
|
||||
})
|
||||
if err != nil {
|
||||
|
@@ -7,7 +7,7 @@ import (
|
||||
"io"
|
||||
"sort"
|
||||
|
||||
"github.com/coreos/bbolt"
|
||||
"github.com/lightningnetwork/lnd/channeldb/kvdb"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
)
|
||||
@@ -76,8 +76,8 @@ func (db *DB) addPayment(payment *outgoingPayment) error {
|
||||
}
|
||||
paymentBytes := b.Bytes()
|
||||
|
||||
return db.Batch(func(tx *bbolt.Tx) error {
|
||||
payments, err := tx.CreateBucketIfNotExists(paymentBucket)
|
||||
return kvdb.Update(db, func(tx kvdb.RwTx) error {
|
||||
payments, err := tx.CreateTopLevelBucket(paymentBucket)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -104,8 +104,8 @@ func (db *DB) addPayment(payment *outgoingPayment) error {
|
||||
func (db *DB) fetchAllPayments() ([]*outgoingPayment, error) {
|
||||
var payments []*outgoingPayment
|
||||
|
||||
err := db.View(func(tx *bbolt.Tx) error {
|
||||
bucket := tx.Bucket(paymentBucket)
|
||||
err := kvdb.View(db, func(tx kvdb.ReadTx) error {
|
||||
bucket := tx.ReadBucket(paymentBucket)
|
||||
if bucket == nil {
|
||||
return ErrNoPaymentsCreated
|
||||
}
|
||||
@@ -140,7 +140,7 @@ func (db *DB) fetchAllPayments() ([]*outgoingPayment, error) {
|
||||
// NOTE: Deprecated. Kept around for migration purposes.
|
||||
func (db *DB) fetchPaymentStatus(paymentHash [32]byte) (PaymentStatus, error) {
|
||||
var paymentStatus = StatusUnknown
|
||||
err := db.View(func(tx *bbolt.Tx) error {
|
||||
err := kvdb.View(db, func(tx kvdb.ReadTx) error {
|
||||
var err error
|
||||
paymentStatus, err = fetchPaymentStatusTx(tx, paymentHash)
|
||||
return err
|
||||
@@ -158,11 +158,11 @@ func (db *DB) fetchPaymentStatus(paymentHash [32]byte) (PaymentStatus, error) {
|
||||
// can be composed into other atomic operations.
|
||||
//
|
||||
// NOTE: Deprecated. Kept around for migration purposes.
|
||||
func fetchPaymentStatusTx(tx *bbolt.Tx, paymentHash [32]byte) (PaymentStatus, error) {
|
||||
func fetchPaymentStatusTx(tx kvdb.ReadTx, paymentHash [32]byte) (PaymentStatus, error) {
|
||||
// The default status for all payments that aren't recorded in database.
|
||||
var paymentStatus = StatusUnknown
|
||||
|
||||
bucket := tx.Bucket(paymentStatusBucket)
|
||||
bucket := tx.ReadBucket(paymentStatusBucket)
|
||||
if bucket == nil {
|
||||
return paymentStatus, nil
|
||||
}
|
||||
@@ -375,14 +375,14 @@ func deserializeHopMigration9(r io.Reader) (*Hop, error) {
|
||||
func (db *DB) fetchPaymentsMigration9() ([]*Payment, error) {
|
||||
var payments []*Payment
|
||||
|
||||
err := db.View(func(tx *bbolt.Tx) error {
|
||||
paymentsBucket := tx.Bucket(paymentsRootBucket)
|
||||
err := kvdb.View(db, func(tx kvdb.ReadTx) error {
|
||||
paymentsBucket := tx.ReadBucket(paymentsRootBucket)
|
||||
if paymentsBucket == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return paymentsBucket.ForEach(func(k, v []byte) error {
|
||||
bucket := paymentsBucket.Bucket(k)
|
||||
bucket := paymentsBucket.NestedReadBucket(k)
|
||||
if bucket == nil {
|
||||
// We only expect sub-buckets to be found in
|
||||
// this top-level bucket.
|
||||
@@ -401,13 +401,13 @@ func (db *DB) fetchPaymentsMigration9() ([]*Payment, error) {
|
||||
// payment has was possible. These will be found in a
|
||||
// sub-bucket indexed by their sequence number if
|
||||
// available.
|
||||
dup := bucket.Bucket(paymentDuplicateBucket)
|
||||
dup := bucket.NestedReadBucket(paymentDuplicateBucket)
|
||||
if dup == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return dup.ForEach(func(k, v []byte) error {
|
||||
subBucket := dup.Bucket(k)
|
||||
subBucket := dup.NestedReadBucket(k)
|
||||
if subBucket == nil {
|
||||
// We one bucket for each duplicate to
|
||||
// be found.
|
||||
@@ -437,7 +437,7 @@ func (db *DB) fetchPaymentsMigration9() ([]*Payment, error) {
|
||||
return payments, nil
|
||||
}
|
||||
|
||||
func fetchPaymentMigration9(bucket *bbolt.Bucket) (*Payment, error) {
|
||||
func fetchPaymentMigration9(bucket kvdb.ReadBucket) (*Payment, error) {
|
||||
var (
|
||||
err error
|
||||
p = &Payment{}
|
||||
|
@@ -4,15 +4,15 @@ import (
|
||||
"bytes"
|
||||
"io"
|
||||
|
||||
"github.com/coreos/bbolt"
|
||||
"github.com/lightningnetwork/lnd/channeldb/kvdb"
|
||||
)
|
||||
|
||||
// MigrateRouteSerialization migrates the way we serialize routes across the
|
||||
// entire database. At the time of writing of this migration, this includes our
|
||||
// payment attempts, as well as the payment results in mission control.
|
||||
func MigrateRouteSerialization(tx *bbolt.Tx) error {
|
||||
func MigrateRouteSerialization(tx kvdb.RwTx) error {
|
||||
// First, we'll do all the payment attempts.
|
||||
rootPaymentBucket := tx.Bucket(paymentsRootBucket)
|
||||
rootPaymentBucket := tx.ReadWriteBucket(paymentsRootBucket)
|
||||
if rootPaymentBucket == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -36,7 +36,7 @@ func MigrateRouteSerialization(tx *bbolt.Tx) error {
|
||||
// Now that we have all the payment hashes, we can carry out the
|
||||
// migration itself.
|
||||
for _, payHash := range payHashes {
|
||||
payHashBucket := rootPaymentBucket.Bucket(payHash)
|
||||
payHashBucket := rootPaymentBucket.NestedReadWriteBucket(payHash)
|
||||
|
||||
// First, we'll migrate the main (non duplicate) payment to
|
||||
// this hash.
|
||||
@@ -47,7 +47,7 @@ func MigrateRouteSerialization(tx *bbolt.Tx) error {
|
||||
|
||||
// Now that we've migrated the main payment, we'll also check
|
||||
// for any duplicate payments to the same payment hash.
|
||||
dupBucket := payHashBucket.Bucket(paymentDuplicateBucket)
|
||||
dupBucket := payHashBucket.NestedReadWriteBucket(paymentDuplicateBucket)
|
||||
|
||||
// If there's no dup bucket, then we can move on to the next
|
||||
// payment.
|
||||
@@ -69,7 +69,7 @@ func MigrateRouteSerialization(tx *bbolt.Tx) error {
|
||||
// Now in this second pass, we'll re-serialize their duplicate
|
||||
// payment attempts under the new encoding.
|
||||
for _, seqNo := range dupSeqNos {
|
||||
dupPayHashBucket := dupBucket.Bucket(seqNo)
|
||||
dupPayHashBucket := dupBucket.NestedReadWriteBucket(seqNo)
|
||||
err := migrateAttemptEncoding(tx, dupPayHashBucket)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -83,8 +83,8 @@ func MigrateRouteSerialization(tx *bbolt.Tx) error {
|
||||
"existing data")
|
||||
|
||||
resultsKey := []byte("missioncontrol-results")
|
||||
err = tx.DeleteBucket(resultsKey)
|
||||
if err != nil && err != bbolt.ErrBucketNotFound {
|
||||
err = tx.DeleteTopLevelBucket(resultsKey)
|
||||
if err != nil && err != kvdb.ErrBucketNotFound {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ func MigrateRouteSerialization(tx *bbolt.Tx) error {
|
||||
|
||||
// migrateAttemptEncoding migrates payment attempts using the legacy format to
|
||||
// the new format.
|
||||
func migrateAttemptEncoding(tx *bbolt.Tx, payHashBucket *bbolt.Bucket) error {
|
||||
func migrateAttemptEncoding(tx kvdb.RwTx, payHashBucket kvdb.RwBucket) error {
|
||||
payAttemptBytes := payHashBucket.Get(paymentAttemptInfoKey)
|
||||
if payAttemptBytes == nil {
|
||||
return nil
|
||||
|
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
bitcoinCfg "github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/coreos/bbolt"
|
||||
"github.com/lightningnetwork/lnd/channeldb/kvdb"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/zpay32"
|
||||
litecoinCfg "github.com/ltcsuite/ltcd/chaincfg"
|
||||
@@ -16,10 +16,10 @@ import (
|
||||
|
||||
// MigrateInvoices adds invoice htlcs and a separate cltv delta field to the
|
||||
// invoices.
|
||||
func MigrateInvoices(tx *bbolt.Tx) error {
|
||||
func MigrateInvoices(tx kvdb.RwTx) error {
|
||||
log.Infof("Migrating invoices to new invoice format")
|
||||
|
||||
invoiceB := tx.Bucket(invoiceBucket)
|
||||
invoiceB := tx.ReadWriteBucket(invoiceBucket)
|
||||
if invoiceB == nil {
|
||||
return nil
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
bitcoinCfg "github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/coreos/bbolt"
|
||||
"github.com/lightningnetwork/lnd/channeldb/kvdb"
|
||||
"github.com/lightningnetwork/lnd/zpay32"
|
||||
litecoinCfg "github.com/ltcsuite/ltcd/chaincfg"
|
||||
)
|
||||
@@ -26,8 +26,8 @@ var (
|
||||
|
||||
// beforeMigrationFuncV11 insert the test invoices in the database.
|
||||
func beforeMigrationFuncV11(t *testing.T, d *DB, invoices []Invoice) {
|
||||
err := d.Update(func(tx *bbolt.Tx) error {
|
||||
invoicesBucket, err := tx.CreateBucketIfNotExists(
|
||||
err := kvdb.Update(d, func(tx kvdb.RwTx) error {
|
||||
invoicesBucket, err := tx.CreateTopLevelBucket(
|
||||
invoiceBucket,
|
||||
)
|
||||
if err != nil {
|
||||
|
@@ -7,7 +7,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
"github.com/coreos/bbolt"
|
||||
"github.com/lightningnetwork/lnd/channeldb/kvdb"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
)
|
||||
|
||||
@@ -16,11 +16,11 @@ import (
|
||||
// (one for nodes and one for edges) to keep track of the last time a node or
|
||||
// edge was updated on the network. These new indexes allow us to implement the
|
||||
// new graph sync protocol added.
|
||||
func MigrateNodeAndEdgeUpdateIndex(tx *bbolt.Tx) error {
|
||||
func MigrateNodeAndEdgeUpdateIndex(tx kvdb.RwTx) error {
|
||||
// First, we'll populating the node portion of the new index. Before we
|
||||
// can add new values to the index, we'll first create the new bucket
|
||||
// where these items will be housed.
|
||||
nodes, err := tx.CreateBucketIfNotExists(nodeBucket)
|
||||
nodes, err := tx.CreateTopLevelBucket(nodeBucket)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to create node bucket: %v", err)
|
||||
}
|
||||
@@ -64,7 +64,7 @@ func MigrateNodeAndEdgeUpdateIndex(tx *bbolt.Tx) error {
|
||||
|
||||
// With the set of nodes updated, we'll now update all edges to have a
|
||||
// corresponding entry in the edge update index.
|
||||
edges, err := tx.CreateBucketIfNotExists(edgeBucket)
|
||||
edges, err := tx.CreateTopLevelBucket(edgeBucket)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to create edge bucket: %v", err)
|
||||
}
|
||||
@@ -121,8 +121,8 @@ func MigrateNodeAndEdgeUpdateIndex(tx *bbolt.Tx) error {
|
||||
// invoices an index in the add and/or the settle index. Additionally, all
|
||||
// existing invoices will have their bytes padded out in order to encode the
|
||||
// add+settle index as well as the amount paid.
|
||||
func MigrateInvoiceTimeSeries(tx *bbolt.Tx) error {
|
||||
invoices, err := tx.CreateBucketIfNotExists(invoiceBucket)
|
||||
func MigrateInvoiceTimeSeries(tx kvdb.RwTx) error {
|
||||
invoices, err := tx.CreateTopLevelBucket(invoiceBucket)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -258,8 +258,8 @@ func MigrateInvoiceTimeSeries(tx *bbolt.Tx) error {
|
||||
// migrateInvoiceTimeSeries migration. As at the time of writing, the
|
||||
// OutgoingPayment struct embeddeds an instance of the Invoice struct. As a
|
||||
// result, we also need to migrate the internal invoice to the new format.
|
||||
func MigrateInvoiceTimeSeriesOutgoingPayments(tx *bbolt.Tx) error {
|
||||
payBucket := tx.Bucket(paymentBucket)
|
||||
func MigrateInvoiceTimeSeriesOutgoingPayments(tx kvdb.RwTx) error {
|
||||
payBucket := tx.ReadWriteBucket(paymentBucket)
|
||||
if payBucket == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -339,18 +339,18 @@ func MigrateInvoiceTimeSeriesOutgoingPayments(tx *bbolt.Tx) error {
|
||||
// bucket. It ensure that edges with unknown policies will also have an entry
|
||||
// in the bucket. After the migration, there will be two edge entries for
|
||||
// every channel, regardless of whether the policies are known.
|
||||
func MigrateEdgePolicies(tx *bbolt.Tx) error {
|
||||
nodes := tx.Bucket(nodeBucket)
|
||||
func MigrateEdgePolicies(tx kvdb.RwTx) error {
|
||||
nodes := tx.ReadWriteBucket(nodeBucket)
|
||||
if nodes == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
edges := tx.Bucket(edgeBucket)
|
||||
edges := tx.ReadWriteBucket(edgeBucket)
|
||||
if edges == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
edgeIndex := edges.Bucket(edgeIndexBucket)
|
||||
edgeIndex := edges.NestedReadWriteBucket(edgeIndexBucket)
|
||||
if edgeIndex == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -411,10 +411,10 @@ func MigrateEdgePolicies(tx *bbolt.Tx) error {
|
||||
// PaymentStatusesMigration is a database migration intended for adding payment
|
||||
// statuses for each existing payment entity in bucket to be able control
|
||||
// transitions of statuses and prevent cases such as double payment
|
||||
func PaymentStatusesMigration(tx *bbolt.Tx) error {
|
||||
func PaymentStatusesMigration(tx kvdb.RwTx) error {
|
||||
// Get the bucket dedicated to storing statuses of payments,
|
||||
// where a key is payment hash, value is payment status.
|
||||
paymentStatuses, err := tx.CreateBucketIfNotExists(paymentStatusBucket)
|
||||
paymentStatuses, err := tx.CreateTopLevelBucket(paymentStatusBucket)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -422,7 +422,7 @@ func PaymentStatusesMigration(tx *bbolt.Tx) error {
|
||||
log.Infof("Migrating database to support payment statuses")
|
||||
|
||||
circuitAddKey := []byte("circuit-adds")
|
||||
circuits := tx.Bucket(circuitAddKey)
|
||||
circuits := tx.ReadWriteBucket(circuitAddKey)
|
||||
if circuits != nil {
|
||||
log.Infof("Marking all known circuits with status InFlight")
|
||||
|
||||
@@ -455,7 +455,7 @@ func PaymentStatusesMigration(tx *bbolt.Tx) error {
|
||||
log.Infof("Marking all existing payments with status Completed")
|
||||
|
||||
// Get the bucket dedicated to storing payments
|
||||
bucket := tx.Bucket(paymentBucket)
|
||||
bucket := tx.ReadWriteBucket(paymentBucket)
|
||||
if bucket == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -498,14 +498,14 @@ func PaymentStatusesMigration(tx *bbolt.Tx) error {
|
||||
// migration also fixes the case where the public keys within edge policies were
|
||||
// being serialized with an extra byte, causing an even greater error when
|
||||
// attempting to perform the offset calculation described earlier.
|
||||
func MigratePruneEdgeUpdateIndex(tx *bbolt.Tx) error {
|
||||
func MigratePruneEdgeUpdateIndex(tx kvdb.RwTx) error {
|
||||
// To begin the migration, we'll retrieve the update index bucket. If it
|
||||
// does not exist, we have nothing left to do so we can simply exit.
|
||||
edges := tx.Bucket(edgeBucket)
|
||||
edges := tx.ReadWriteBucket(edgeBucket)
|
||||
if edges == nil {
|
||||
return nil
|
||||
}
|
||||
edgeUpdateIndex := edges.Bucket(edgeUpdateIndexBucket)
|
||||
edgeUpdateIndex := edges.NestedReadWriteBucket(edgeUpdateIndexBucket)
|
||||
if edgeUpdateIndex == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -521,7 +521,7 @@ func MigratePruneEdgeUpdateIndex(tx *bbolt.Tx) error {
|
||||
return fmt.Errorf("unable to create/fetch edge index " +
|
||||
"bucket")
|
||||
}
|
||||
nodes, err := tx.CreateBucketIfNotExists(nodeBucket)
|
||||
nodes, err := tx.CreateTopLevelBucket(nodeBucket)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to make node bucket")
|
||||
}
|
||||
@@ -612,8 +612,8 @@ func MigratePruneEdgeUpdateIndex(tx *bbolt.Tx) error {
|
||||
// MigrateOptionalChannelCloseSummaryFields migrates the serialized format of
|
||||
// ChannelCloseSummary to a format where optional fields' presence is indicated
|
||||
// with boolean markers.
|
||||
func MigrateOptionalChannelCloseSummaryFields(tx *bbolt.Tx) error {
|
||||
closedChanBucket := tx.Bucket(closedChannelBucket)
|
||||
func MigrateOptionalChannelCloseSummaryFields(tx kvdb.RwTx) error {
|
||||
closedChanBucket := tx.ReadWriteBucket(closedChannelBucket)
|
||||
if closedChanBucket == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -671,11 +671,11 @@ var messageStoreBucket = []byte("message-store")
|
||||
// MigrateGossipMessageStoreKeys migrates the key format for gossip messages
|
||||
// found in the message store to a new one that takes into consideration the of
|
||||
// the message being stored.
|
||||
func MigrateGossipMessageStoreKeys(tx *bbolt.Tx) error {
|
||||
func MigrateGossipMessageStoreKeys(tx kvdb.RwTx) error {
|
||||
// We'll start by retrieving the bucket in which these messages are
|
||||
// stored within. If there isn't one, there's nothing left for us to do
|
||||
// so we can avoid the migration.
|
||||
messageStore := tx.Bucket(messageStoreBucket)
|
||||
messageStore := tx.ReadWriteBucket(messageStoreBucket)
|
||||
if messageStore == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -747,10 +747,10 @@ func MigrateGossipMessageStoreKeys(tx *bbolt.Tx) error {
|
||||
// InFlight (we have no PaymentAttemptInfo available for pre-migration
|
||||
// payments) we delete those statuses, so only Completed payments remain in the
|
||||
// new bucket structure.
|
||||
func MigrateOutgoingPayments(tx *bbolt.Tx) error {
|
||||
func MigrateOutgoingPayments(tx kvdb.RwTx) error {
|
||||
log.Infof("Migrating outgoing payments to new bucket structure")
|
||||
|
||||
oldPayments := tx.Bucket(paymentBucket)
|
||||
oldPayments := tx.ReadWriteBucket(paymentBucket)
|
||||
|
||||
// Return early if there are no payments to migrate.
|
||||
if oldPayments == nil {
|
||||
@@ -758,7 +758,7 @@ func MigrateOutgoingPayments(tx *bbolt.Tx) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
newPayments, err := tx.CreateBucket(paymentsRootBucket)
|
||||
newPayments, err := tx.CreateTopLevelBucket(paymentsRootBucket)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -767,7 +767,7 @@ func MigrateOutgoingPayments(tx *bbolt.Tx) error {
|
||||
// only attempt to fetch it if needed.
|
||||
sourcePub := func() ([33]byte, error) {
|
||||
var pub [33]byte
|
||||
nodes := tx.Bucket(nodeBucket)
|
||||
nodes := tx.ReadWriteBucket(nodeBucket)
|
||||
if nodes == nil {
|
||||
return pub, ErrGraphNotFound
|
||||
}
|
||||
@@ -862,8 +862,8 @@ func MigrateOutgoingPayments(tx *bbolt.Tx) error {
|
||||
// from a database containing duplicate payments to a payment
|
||||
// hash. To keep this information, we store such duplicate
|
||||
// payments in a sub-bucket.
|
||||
if err == bbolt.ErrBucketExists {
|
||||
pHashBucket := newPayments.Bucket(paymentHash[:])
|
||||
if err == kvdb.ErrBucketExists {
|
||||
pHashBucket := newPayments.NestedReadWriteBucket(paymentHash[:])
|
||||
|
||||
// Create a bucket for duplicate payments within this
|
||||
// payment hash's bucket.
|
||||
@@ -922,14 +922,14 @@ func MigrateOutgoingPayments(tx *bbolt.Tx) error {
|
||||
|
||||
// Now we delete the old buckets. Deleting the payment status buckets
|
||||
// deletes all payment statuses other than Complete.
|
||||
err = tx.DeleteBucket(paymentStatusBucket)
|
||||
if err != nil && err != bbolt.ErrBucketNotFound {
|
||||
err = tx.DeleteTopLevelBucket(paymentStatusBucket)
|
||||
if err != nil && err != kvdb.ErrBucketNotFound {
|
||||
return err
|
||||
}
|
||||
|
||||
// Finally delete the old payment bucket.
|
||||
err = tx.DeleteBucket(paymentBucket)
|
||||
if err != nil && err != bbolt.ErrBucketNotFound {
|
||||
err = tx.DeleteTopLevelBucket(paymentBucket)
|
||||
if err != nil && err != kvdb.ErrBucketNotFound {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@@ -11,9 +11,9 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/coreos/bbolt"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/go-errors/errors"
|
||||
"github.com/lightningnetwork/lnd/channeldb/kvdb"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
)
|
||||
@@ -59,8 +59,8 @@ func TestPaymentStatusesMigration(t *testing.T) {
|
||||
// locally-sourced payment should end up with an InFlight
|
||||
// status, while the other should remain unchanged, which
|
||||
// defaults to Grounded.
|
||||
err = d.Update(func(tx *bbolt.Tx) error {
|
||||
circuits, err := tx.CreateBucketIfNotExists(
|
||||
err = kvdb.Update(d, func(tx kvdb.RwTx) error {
|
||||
circuits, err := tx.CreateTopLevelBucket(
|
||||
[]byte("circuit-adds"),
|
||||
)
|
||||
if err != nil {
|
||||
@@ -377,8 +377,8 @@ func TestMigrateOptionalChannelCloseSummaryFields(t *testing.T) {
|
||||
// Get the old serialization format for this test's
|
||||
// close summary, and it to the closed channel bucket.
|
||||
old := test.oldSerialization(test.closeSummary)
|
||||
err = d.Update(func(tx *bbolt.Tx) error {
|
||||
closedChanBucket, err := tx.CreateBucketIfNotExists(
|
||||
err = kvdb.Update(d, func(tx kvdb.RwTx) error {
|
||||
closedChanBucket, err := tx.CreateTopLevelBucket(
|
||||
closedChannelBucket,
|
||||
)
|
||||
if err != nil {
|
||||
@@ -404,8 +404,8 @@ func TestMigrateOptionalChannelCloseSummaryFields(t *testing.T) {
|
||||
newSerialization := b.Bytes()
|
||||
|
||||
var dbSummary []byte
|
||||
err = d.View(func(tx *bbolt.Tx) error {
|
||||
closedChanBucket := tx.Bucket(closedChannelBucket)
|
||||
err = kvdb.View(d, func(tx kvdb.ReadTx) error {
|
||||
closedChanBucket := tx.ReadBucket(closedChannelBucket)
|
||||
if closedChanBucket == nil {
|
||||
return errors.New("unable to find bucket")
|
||||
}
|
||||
@@ -482,8 +482,8 @@ func TestMigrateGossipMessageStoreKeys(t *testing.T) {
|
||||
t.Fatalf("unable to serialize message: %v", err)
|
||||
}
|
||||
|
||||
err := db.Update(func(tx *bbolt.Tx) error {
|
||||
messageStore, err := tx.CreateBucketIfNotExists(
|
||||
err := kvdb.Update(db, func(tx kvdb.RwTx) error {
|
||||
messageStore, err := tx.CreateTopLevelBucket(
|
||||
messageStoreBucket,
|
||||
)
|
||||
if err != nil {
|
||||
@@ -503,8 +503,8 @@ func TestMigrateGossipMessageStoreKeys(t *testing.T) {
|
||||
// 3. The message matches the original.
|
||||
afterMigration := func(db *DB) {
|
||||
var rawMsg []byte
|
||||
err := db.View(func(tx *bbolt.Tx) error {
|
||||
messageStore := tx.Bucket(messageStoreBucket)
|
||||
err := kvdb.View(db, func(tx kvdb.ReadTx) error {
|
||||
messageStore := tx.ReadBucket(messageStoreBucket)
|
||||
if messageStore == nil {
|
||||
return errors.New("message store bucket not " +
|
||||
"found")
|
||||
@@ -666,8 +666,8 @@ func TestOutgoingPaymentsMigration(t *testing.T) {
|
||||
|
||||
// Finally, check that the payment sequence number is updated
|
||||
// to reflect the migrated payments.
|
||||
err = d.View(func(tx *bbolt.Tx) error {
|
||||
payments := tx.Bucket(paymentsRootBucket)
|
||||
err = kvdb.Update(d, func(tx kvdb.RwTx) error {
|
||||
payments := tx.ReadWriteBucket(paymentsRootBucket)
|
||||
if payments == nil {
|
||||
return fmt.Errorf("payments bucket not found")
|
||||
}
|
||||
@@ -746,8 +746,8 @@ func TestPaymentRouteSerialization(t *testing.T) {
|
||||
// We'll first add a series of fake payments, using the existing legacy
|
||||
// serialization format.
|
||||
beforeMigrationFunc := func(d *DB) {
|
||||
err := d.Update(func(tx *bbolt.Tx) error {
|
||||
paymentsBucket, err := tx.CreateBucket(
|
||||
err := kvdb.Update(d, func(tx kvdb.RwTx) error {
|
||||
paymentsBucket, err := tx.CreateTopLevelBucket(
|
||||
paymentsRootBucket,
|
||||
)
|
||||
if err != nil {
|
||||
@@ -798,7 +798,7 @@ func TestPaymentRouteSerialization(t *testing.T) {
|
||||
// the proper bucket. If this is the duplicate
|
||||
// payment, then we'll grab the dup bucket,
|
||||
// otherwise, we'll use the top level bucket.
|
||||
var payHashBucket *bbolt.Bucket
|
||||
var payHashBucket kvdb.RwBucket
|
||||
if i < numPayments-1 {
|
||||
payHashBucket, err = paymentsBucket.CreateBucket(
|
||||
payInfo.PaymentHash[:],
|
||||
@@ -807,7 +807,7 @@ func TestPaymentRouteSerialization(t *testing.T) {
|
||||
t.Fatalf("unable to create payments bucket: %v", err)
|
||||
}
|
||||
} else {
|
||||
payHashBucket = paymentsBucket.Bucket(
|
||||
payHashBucket = paymentsBucket.NestedReadWriteBucket(
|
||||
payInfo.PaymentHash[:],
|
||||
)
|
||||
dupPayBucket, err := payHashBucket.CreateBucket(
|
||||
|
@@ -1,12 +1,10 @@
|
||||
package migration_01_to_11
|
||||
|
||||
import (
|
||||
"github.com/coreos/bbolt"
|
||||
)
|
||||
import "github.com/lightningnetwork/lnd/channeldb/kvdb"
|
||||
|
||||
// fetchPaymentStatus fetches the payment status of the payment. If the payment
|
||||
// isn't found, it will default to "StatusUnknown".
|
||||
func fetchPaymentStatus(bucket *bbolt.Bucket) PaymentStatus {
|
||||
func fetchPaymentStatus(bucket kvdb.ReadBucket) PaymentStatus {
|
||||
if bucket.Get(paymentSettleInfoKey) != nil {
|
||||
return StatusSucceeded
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/coreos/bbolt"
|
||||
"github.com/lightningnetwork/lnd/channeldb/kvdb"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/tlv"
|
||||
@@ -254,14 +254,14 @@ type Payment struct {
|
||||
func (db *DB) FetchPayments() ([]*Payment, error) {
|
||||
var payments []*Payment
|
||||
|
||||
err := db.View(func(tx *bbolt.Tx) error {
|
||||
paymentsBucket := tx.Bucket(paymentsRootBucket)
|
||||
err := kvdb.View(db, func(tx kvdb.ReadTx) error {
|
||||
paymentsBucket := tx.ReadBucket(paymentsRootBucket)
|
||||
if paymentsBucket == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return paymentsBucket.ForEach(func(k, v []byte) error {
|
||||
bucket := paymentsBucket.Bucket(k)
|
||||
bucket := paymentsBucket.NestedReadBucket(k)
|
||||
if bucket == nil {
|
||||
// We only expect sub-buckets to be found in
|
||||
// this top-level bucket.
|
||||
@@ -280,13 +280,13 @@ func (db *DB) FetchPayments() ([]*Payment, error) {
|
||||
// payment has was possible. These will be found in a
|
||||
// sub-bucket indexed by their sequence number if
|
||||
// available.
|
||||
dup := bucket.Bucket(paymentDuplicateBucket)
|
||||
dup := bucket.NestedReadBucket(paymentDuplicateBucket)
|
||||
if dup == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return dup.ForEach(func(k, v []byte) error {
|
||||
subBucket := dup.Bucket(k)
|
||||
subBucket := dup.NestedReadBucket(k)
|
||||
if subBucket == nil {
|
||||
// We one bucket for each duplicate to
|
||||
// be found.
|
||||
@@ -316,7 +316,7 @@ func (db *DB) FetchPayments() ([]*Payment, error) {
|
||||
return payments, nil
|
||||
}
|
||||
|
||||
func fetchPayment(bucket *bbolt.Bucket) (*Payment, error) {
|
||||
func fetchPayment(bucket kvdb.ReadBucket) (*Payment, error) {
|
||||
var (
|
||||
err error
|
||||
p = &Payment{}
|
||||
|
Reference in New Issue
Block a user