htlcswitch: convert to use new kvdb abstraction
This commit is contained in:
7 files changed
+61
-58
No files matched your search
+16
-16
@@ -5,10 +5,10 @@ import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/coreos/bbolt"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/go-errors/errors"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/channeldb/kvdb"
|
||||
"github.com/lightningnetwork/lnd/htlcswitch/hop"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
)
|
||||
@@ -213,13 +213,13 @@ func NewCircuitMap(cfg *CircuitMapConfig) (CircuitMap, error) {
|
||||
// initBuckets ensures that the primary buckets used by the circuit are
|
||||
// initialized so that we can assume their existence after startup.
|
||||
func (cm *circuitMap) initBuckets() error {
|
||||
return cm.cfg.DB.Update(func(tx *bbolt.Tx) error {
|
||||
_, err := tx.CreateBucketIfNotExists(circuitKeystoneKey)
|
||||
return kvdb.Update(cm.cfg.DB, func(tx kvdb.RwTx) error {
|
||||
_, err := tx.CreateTopLevelBucket(circuitKeystoneKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = tx.CreateBucketIfNotExists(circuitAddKey)
|
||||
_, err = tx.CreateTopLevelBucket(circuitAddKey)
|
||||
return err
|
||||
})
|
||||
}
|
||||
@@ -238,10 +238,10 @@ func (cm *circuitMap) restoreMemState() error {
|
||||
pending = make(map[CircuitKey]*PaymentCircuit)
|
||||
)
|
||||
|
||||
if err := cm.cfg.DB.Update(func(tx *bbolt.Tx) error {
|
||||
if err := kvdb.Update(cm.cfg.DB, func(tx kvdb.RwTx) error {
|
||||
// Restore any of the circuits persisted in the circuit bucket
|
||||
// back into memory.
|
||||
circuitBkt := tx.Bucket(circuitAddKey)
|
||||
circuitBkt := tx.ReadWriteBucket(circuitAddKey)
|
||||
if circuitBkt == nil {
|
||||
return ErrCorruptedCircuitMap
|
||||
}
|
||||
@@ -262,7 +262,7 @@ func (cm *circuitMap) restoreMemState() error {
|
||||
|
||||
// Furthermore, load the keystone bucket and resurrect the
|
||||
// keystones used in any open circuits.
|
||||
keystoneBkt := tx.Bucket(circuitKeystoneKey)
|
||||
keystoneBkt := tx.ReadWriteBucket(circuitKeystoneKey)
|
||||
if keystoneBkt == nil {
|
||||
return ErrCorruptedCircuitMap
|
||||
}
|
||||
@@ -463,8 +463,8 @@ func (cm *circuitMap) TrimOpenCircuits(chanID lnwire.ShortChannelID,
|
||||
return nil
|
||||
}
|
||||
|
||||
return cm.cfg.DB.Update(func(tx *bbolt.Tx) error {
|
||||
keystoneBkt := tx.Bucket(circuitKeystoneKey)
|
||||
return kvdb.Update(cm.cfg.DB, func(tx kvdb.RwTx) error {
|
||||
keystoneBkt := tx.ReadWriteBucket(circuitKeystoneKey)
|
||||
if keystoneBkt == nil {
|
||||
return ErrCorruptedCircuitMap
|
||||
}
|
||||
@@ -616,8 +616,8 @@ func (cm *circuitMap) CommitCircuits(circuits ...*PaymentCircuit) (
|
||||
// Write the entire batch of circuits to the persistent circuit bucket
|
||||
// using bolt's Batch write. This method must be called from multiple,
|
||||
// distinct goroutines to have any impact on performance.
|
||||
err := cm.cfg.DB.Batch(func(tx *bbolt.Tx) error {
|
||||
circuitBkt := tx.Bucket(circuitAddKey)
|
||||
err := kvdb.Batch(cm.cfg.DB.Backend, func(tx kvdb.RwTx) error {
|
||||
circuitBkt := tx.ReadWriteBucket(circuitAddKey)
|
||||
if circuitBkt == nil {
|
||||
return ErrCorruptedCircuitMap
|
||||
}
|
||||
@@ -706,10 +706,10 @@ func (cm *circuitMap) OpenCircuits(keystones ...Keystone) error {
|
||||
}
|
||||
cm.mtx.RUnlock()
|
||||
|
||||
err := cm.cfg.DB.Update(func(tx *bbolt.Tx) error {
|
||||
err := kvdb.Update(cm.cfg.DB, func(tx kvdb.RwTx) error {
|
||||
// Now, load the circuit bucket to which we will write the
|
||||
// already serialized circuit.
|
||||
keystoneBkt := tx.Bucket(circuitKeystoneKey)
|
||||
keystoneBkt := tx.ReadWriteBucket(circuitKeystoneKey)
|
||||
if keystoneBkt == nil {
|
||||
return ErrCorruptedCircuitMap
|
||||
}
|
||||
@@ -847,13 +847,13 @@ func (cm *circuitMap) DeleteCircuits(inKeys ...CircuitKey) error {
|
||||
}
|
||||
cm.mtx.Unlock()
|
||||
|
||||
err := cm.cfg.DB.Batch(func(tx *bbolt.Tx) error {
|
||||
err := kvdb.Batch(cm.cfg.DB.Backend, func(tx kvdb.RwTx) error {
|
||||
for _, circuit := range removedCircuits {
|
||||
// If this htlc made it to an outgoing link, load the
|
||||
// keystone bucket from which we will remove the
|
||||
// outgoing circuit key.
|
||||
if circuit.HasKeystone() {
|
||||
keystoneBkt := tx.Bucket(circuitKeystoneKey)
|
||||
keystoneBkt := tx.ReadWriteBucket(circuitKeystoneKey)
|
||||
if keystoneBkt == nil {
|
||||
return ErrCorruptedCircuitMap
|
||||
}
|
||||
@@ -868,7 +868,7 @@ func (cm *circuitMap) DeleteCircuits(inKeys ...CircuitKey) error {
|
||||
|
||||
// Remove the circuit itself based on the incoming
|
||||
// circuit key.
|
||||
circuitBkt := tx.Bucket(circuitAddKey)
|
||||
circuitBkt := tx.ReadWriteBucket(circuitAddKey)
|
||||
if circuitBkt == nil {
|
||||
return ErrCorruptedCircuitMap
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user