Merge pull request #9523 from ellemouton/graph9
graph/db: use View directly instead of manual DB tx creation and commit
This commit is contained in:
1 file changed
+9
-21
+9
-21
@@ -18,6 +18,7 @@ import (
|
|||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
"github.com/btcsuite/btcd/txscript"
|
"github.com/btcsuite/btcd/txscript"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
|
"github.com/btcsuite/btcwallet/walletdb"
|
||||||
"github.com/lightningnetwork/lnd/aliasmgr"
|
"github.com/lightningnetwork/lnd/aliasmgr"
|
||||||
"github.com/lightningnetwork/lnd/batch"
|
"github.com/lightningnetwork/lnd/batch"
|
||||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||||
@@ -3895,29 +3896,16 @@ func (c *ChannelGraph) IsClosedScid(scid lnwire.ShortChannelID) (bool, error) {
|
|||||||
// the graph cache is not enabled, then the call-back will be provided with
|
// the graph cache is not enabled, then the call-back will be provided with
|
||||||
// access to the graph via a consistent read-only transaction.
|
// access to the graph via a consistent read-only transaction.
|
||||||
func (c *ChannelGraph) GraphSession(cb func(graph NodeTraverser) error) error {
|
func (c *ChannelGraph) GraphSession(cb func(graph NodeTraverser) error) error {
|
||||||
var (
|
if c.graphCache != nil {
|
||||||
tx kvdb.RTx
|
return cb(&nodeTraverserSession{db: c})
|
||||||
err error
|
|
||||||
commit = func() {}
|
|
||||||
)
|
|
||||||
if c.graphCache == nil {
|
|
||||||
tx, err = c.db.BeginReadTx()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
commit = func() {
|
|
||||||
if err := tx.Rollback(); err != nil {
|
|
||||||
log.Errorf("Unable to rollback tx: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
defer commit()
|
|
||||||
|
|
||||||
return cb(&nodeTraverserSession{
|
return c.db.View(func(tx walletdb.ReadTx) error {
|
||||||
db: c,
|
return cb(&nodeTraverserSession{
|
||||||
tx: tx,
|
db: c,
|
||||||
})
|
tx: tx,
|
||||||
|
})
|
||||||
|
}, func() {})
|
||||||
}
|
}
|
||||||
|
|
||||||
// nodeTraverserSession implements the NodeTraverser interface but with a
|
// nodeTraverserSession implements the NodeTraverser interface but with a
|
||||||
|
|||||||
Reference in new issue
Block a user