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:
36 files changed
+804
-752
No files matched your search
@@ -4,7 +4,7 @@ import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
|
||||
"github.com/coreos/bbolt"
|
||||
"github.com/lightningnetwork/lnd/channeldb/kvdb"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -48,13 +48,13 @@ var (
|
||||
|
||||
// MigrateMPP migrates the payments to a new structure that accommodates for mpp
|
||||
// payments.
|
||||
func MigrateMPP(tx *bbolt.Tx) error {
|
||||
func MigrateMPP(tx kvdb.RwTx) error {
|
||||
log.Infof("Migrating payments to mpp structure")
|
||||
|
||||
// Iterate over all payments and store their indexing keys. This is
|
||||
// needed, because no modifications are allowed inside a Bucket.ForEach
|
||||
// loop.
|
||||
paymentsBucket := tx.Bucket(paymentsRootBucket)
|
||||
paymentsBucket := tx.ReadWriteBucket(paymentsRootBucket)
|
||||
if paymentsBucket == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -70,7 +70,7 @@ func MigrateMPP(tx *bbolt.Tx) error {
|
||||
|
||||
// With all keys retrieved, start the migration.
|
||||
for _, k := range paymentKeys {
|
||||
bucket := paymentsBucket.Bucket(k)
|
||||
bucket := paymentsBucket.NestedReadWriteBucket(k)
|
||||
|
||||
// We only expect sub-buckets to be found in
|
||||
// this top-level bucket.
|
||||
|
||||
@@ -3,7 +3,7 @@ package migration13
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/coreos/bbolt"
|
||||
"github.com/lightningnetwork/lnd/channeldb/kvdb"
|
||||
"github.com/lightningnetwork/lnd/channeldb/migtest"
|
||||
)
|
||||
|
||||
@@ -111,10 +111,10 @@ func TestMigrateMpp(t *testing.T) {
|
||||
|
||||
migtest.ApplyMigration(
|
||||
t,
|
||||
func(tx *bbolt.Tx) error {
|
||||
func(tx kvdb.RwTx) error {
|
||||
return migtest.RestoreDB(tx, paymentsRootBucket, pre)
|
||||
},
|
||||
func(tx *bbolt.Tx) error {
|
||||
func(tx kvdb.RwTx) error {
|
||||
return migtest.VerifyDB(tx, paymentsRootBucket, post)
|
||||
},
|
||||
MigrateMPP,
|
||||
|
||||
Reference in new issue
Block a user