Skip to content

Commit 0e87863

Browse files
authored
Merge pull request #9523 from ellemouton/graph9
graph/db: use View directly instead of manual DB tx creation and commit
2 parents 31418e4 + 03899ab commit 0e87863

File tree

1 file changed

+9
-21
lines changed

1 file changed

+9
-21
lines changed

graph/db/graph.go

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/btcsuite/btcd/chaincfg/chainhash"
1919
"github.com/btcsuite/btcd/txscript"
2020
"github.com/btcsuite/btcd/wire"
21+
"github.com/btcsuite/btcwallet/walletdb"
2122
"github.com/lightningnetwork/lnd/aliasmgr"
2223
"github.com/lightningnetwork/lnd/batch"
2324
"github.com/lightningnetwork/lnd/graph/db/models"
@@ -3895,29 +3896,16 @@ func (c *ChannelGraph) IsClosedScid(scid lnwire.ShortChannelID) (bool, error) {
38953896
// the graph cache is not enabled, then the call-back will be provided with
38963897
// access to the graph via a consistent read-only transaction.
38973898
func (c *ChannelGraph) GraphSession(cb func(graph NodeTraverser) error) error {
3898-
var (
3899-
tx kvdb.RTx
3900-
err error
3901-
commit = func() {}
3902-
)
3903-
if c.graphCache == nil {
3904-
tx, err = c.db.BeginReadTx()
3905-
if err != nil {
3906-
return err
3907-
}
3908-
3909-
commit = func() {
3910-
if err := tx.Rollback(); err != nil {
3911-
log.Errorf("Unable to rollback tx: %v", err)
3912-
}
3913-
}
3899+
if c.graphCache != nil {
3900+
return cb(&nodeTraverserSession{db: c})
39143901
}
3915-
defer commit()
39163902

3917-
return cb(&nodeTraverserSession{
3918-
db: c,
3919-
tx: tx,
3920-
})
3903+
return c.db.View(func(tx walletdb.ReadTx) error {
3904+
return cb(&nodeTraverserSession{
3905+
db: c,
3906+
tx: tx,
3907+
})
3908+
}, func() {})
39213909
}
39223910

39233911
// nodeTraverserSession implements the NodeTraverser interface but with a

0 commit comments

Comments
 (0)