mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-30 23:53:41 +02:00
mod+kvdb+channeldb: use btcwallet new DB interface
Depends on btcsuite/btcwallet#757. Pulls in the updated version of btcwallet and walletdb that have the DB interface enhanced by their own View() and Update() methods with the reset callback/closure supported out of the box. That way the global package-level View() and Update() functions now become pure redirects.
This commit is contained in:
@@ -2,7 +2,7 @@ module github.com/lightningnetwork/lnd/kvdb
|
||||
|
||||
require (
|
||||
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f
|
||||
github.com/btcsuite/btcwallet/walletdb v1.3.5-0.20210513043850-3a2f12e3a954
|
||||
github.com/btcsuite/btcwallet/walletdb v1.3.6-0.20210803004036-eebed51155ec
|
||||
github.com/lightningnetwork/lnd/healthcheck v1.0.0
|
||||
github.com/stretchr/testify v1.7.0
|
||||
go.etcd.io/bbolt v1.3.6
|
||||
|
@@ -35,8 +35,8 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB
|
||||
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
|
||||
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f h1:bAs4lUbRJpnnkd9VhRV3jjAVU7DJVjMaK+IsvSeZvFo=
|
||||
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA=
|
||||
github.com/btcsuite/btcwallet/walletdb v1.3.5-0.20210513043850-3a2f12e3a954 h1:CB6chiHPhZWmbCL7kFCADDf15V6I3EUNDgGC25jbptc=
|
||||
github.com/btcsuite/btcwallet/walletdb v1.3.5-0.20210513043850-3a2f12e3a954/go.mod h1:oJDxAEUHVtnmIIBaa22wSBPTVcs6hUp5NKWmI8xDwwU=
|
||||
github.com/btcsuite/btcwallet/walletdb v1.3.6-0.20210803004036-eebed51155ec h1:zcAU3Ij8SmqaE+ITtS76fua2Niq7DRNp46sJRhi8PiI=
|
||||
github.com/btcsuite/btcwallet/walletdb v1.3.6-0.20210803004036-eebed51155ec/go.mod h1:oJDxAEUHVtnmIIBaa22wSBPTVcs6hUp5NKWmI8xDwwU=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/certifi/gocertifi v0.0.0-20191021191039-0944d244cd40/go.mod h1:sGbDF6GwGcLpkNXPUTkMRoywsNa/ol15pxFe6ERfguA=
|
||||
github.com/certifi/gocertifi v0.0.0-20200922220541-2c3bb06c6054 h1:uH66TXeswKn5PW5zdZ39xEwfS9an067BirqA+P4QaLI=
|
||||
|
@@ -13,12 +13,7 @@ import (
|
||||
// database backend used), the reset function will be called before each retry
|
||||
// respectively.
|
||||
func Update(db Backend, f func(tx RwTx) error, reset func()) error {
|
||||
if extendedDB, ok := db.(ExtendedBackend); ok {
|
||||
return extendedDB.Update(f, reset)
|
||||
}
|
||||
|
||||
reset()
|
||||
return walletdb.Update(db, f)
|
||||
return db.Update(f, reset)
|
||||
}
|
||||
|
||||
// View opens a database read transaction and executes the function f with the
|
||||
@@ -29,15 +24,7 @@ func Update(db Backend, f func(tx RwTx) error, reset func()) error {
|
||||
// expect retries of the f closure (depending on the database backend used), the
|
||||
// reset function will be called before each retry respectively.
|
||||
func View(db Backend, f func(tx RTx) error, reset func()) error {
|
||||
if extendedDB, ok := db.(ExtendedBackend); ok {
|
||||
return extendedDB.View(f, reset)
|
||||
}
|
||||
|
||||
// Since we know that walletdb simply calls into bbolt which never
|
||||
// retries transactions, we'll call the reset function here before View.
|
||||
reset()
|
||||
|
||||
return walletdb.View(db, f)
|
||||
return db.View(f, reset)
|
||||
}
|
||||
|
||||
// Batch is identical to the Update call, but it attempts to combine several
|
||||
@@ -46,10 +33,12 @@ func View(db Backend, f func(tx RTx) error, reset func()) error {
|
||||
// Batch. For etcd Batch simply does an Update since combination is more complex
|
||||
// in that case due to STM retries.
|
||||
func Batch(db Backend, f func(tx RwTx) error) error {
|
||||
if extendedDB, ok := db.(ExtendedBackend); ok {
|
||||
// Fall back to the normal Update method if the backend doesn't support
|
||||
// batching.
|
||||
if _, ok := db.(walletdb.BatchDB); !ok {
|
||||
// Since Batch calls handle external state reset, we can safely
|
||||
// pass in an empty reset closure.
|
||||
return extendedDB.Update(f, func() {})
|
||||
return db.Update(f, func() {})
|
||||
}
|
||||
|
||||
return walletdb.Batch(db, f)
|
||||
@@ -66,35 +55,6 @@ var Create = walletdb.Create
|
||||
// through read or read+write transactions.
|
||||
type Backend = walletdb.DB
|
||||
|
||||
// ExtendedBackend is and interface that supports View and Update and also able
|
||||
// to collect database access patterns.
|
||||
type ExtendedBackend interface {
|
||||
Backend
|
||||
|
||||
// PrintStats returns all collected stats pretty printed into a string.
|
||||
PrintStats() string
|
||||
|
||||
// View opens a database read transaction and executes the function f
|
||||
// with the transaction passed as a parameter. After f exits, the
|
||||
// transaction is rolled back. If f errors, its error is returned, not a
|
||||
// rollback error (if any occur). The passed reset function is called
|
||||
// before the start of the transaction and can be used to reset
|
||||
// intermediate state. As callers may expect retries of the f closure
|
||||
// (depending on the database backend used), the reset function will be
|
||||
//called before each retry respectively.
|
||||
View(f func(tx walletdb.ReadTx) error, reset func()) error
|
||||
|
||||
// Update opens a database read/write transaction and executes the
|
||||
// function f with the transaction passed as a parameter. After f exits,
|
||||
// if f did not error, the transaction is committed. Otherwise, if f did
|
||||
// error, the transaction is rolled back. If the rollback fails, the
|
||||
// original error returned by f is still returned. If the commit fails,
|
||||
// the commit error is returned. As callers may expect retries of the f
|
||||
// closure (depending on the database backend used), the reset function
|
||||
// will be called before each retry respectively.
|
||||
Update(f func(tx walletdb.ReadWriteTx) error, reset func()) error
|
||||
}
|
||||
|
||||
// Open opens an existing database for the specified type. The arguments are
|
||||
// specific to the database type driver. See the documentation for the database
|
||||
// driver for further details.
|
||||
@@ -129,9 +89,8 @@ type RwBucket = walletdb.ReadWriteBucket
|
||||
// operations.
|
||||
type RwCursor = walletdb.ReadWriteCursor
|
||||
|
||||
// ReadWriteTx represents a database transaction that can be used for both
|
||||
// reads and writes. When only reads are necessary, consider using a RTx
|
||||
// instead.
|
||||
// RwTx represents a database transaction that can be used for both reads and
|
||||
// writes. When only reads are necessary, consider using a RTx instead.
|
||||
type RwTx = walletdb.ReadWriteTx
|
||||
|
||||
var (
|
||||
|
Reference in New Issue
Block a user