Skip to content

Commit 03899ab

Browse files
committed
graph/db: use View directly instead of manual Tx handling
In this commit, we use the available kvdb `View` method directly for starting a graph session instead of manually creating and commiting the transaction. Note this changes behaviour since failed tx create/commit will now error instead of just log.
1 parent f380500 commit 03899ab

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"
@@ -3898,29 +3899,16 @@ func (c *ChannelGraph) IsClosedScid(scid lnwire.ShortChannelID) (bool, error) {
38983899
// the graph cache is not enabled, then the call-back will be provided with
38993900
// access to the graph via a consistent read-only transaction.
39003901
func (c *ChannelGraph) GraphSession(cb func(graph NodeTraverser) error) error {
3901-
var (
3902-
tx kvdb.RTx
3903-
err error
3904-
commit = func() {}
3905-
)
3906-
if c.graphCache == nil {
3907-
tx, err = c.db.BeginReadTx()
3908-
if err != nil {
3909-
return err
3910-
}
3911-
3912-
commit = func() {
3913-
if err := tx.Rollback(); err != nil {
3914-
log.Errorf("Unable to rollback tx: %v", err)
3915-
}
3916-
}
3902+
if c.graphCache != nil {
3903+
return cb(&nodeTraverserSession{db: c})
39173904
}
3918-
defer commit()
39193905

3920-
return cb(&nodeTraverserSession{
3921-
db: c,
3922-
tx: tx,
3923-
})
3906+
return c.db.View(func(tx walletdb.ReadTx) error {
3907+
return cb(&nodeTraverserSession{
3908+
db: c,
3909+
tx: tx,
3910+
})
3911+
}, func() {})
39243912
}
39253913

39263914
// nodeTraverserSession implements the NodeTraverser interface but with a

0 commit comments

Comments
 (0)