graphdb: pass context to GraphSession
This commit is contained in:
9 files changed
+19
-16
No files matched your search
+3
-3
@@ -253,14 +253,14 @@ func (c *ChannelGraph) FetchNodeFeatures(ctx context.Context,
|
|||||||
// instance which can be used to perform queries against the channel graph. If
|
// instance which can be used to perform queries against the channel graph. If
|
||||||
// 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,
|
func (c *ChannelGraph) GraphSession(ctx context.Context,
|
||||||
reset func()) error {
|
cb func(graph NodeTraverser) error, reset func()) error {
|
||||||
|
|
||||||
if c.graphCache != nil {
|
if c.graphCache != nil {
|
||||||
return cb(c)
|
return cb(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.db.GraphSession(cb, reset)
|
return c.db.GraphSession(ctx, cb, reset)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ForEachNodeCached iterates through all the stored vertices/nodes in the
|
// ForEachNodeCached iterates through all the stored vertices/nodes in the
|
||||||
|
|||||||
@@ -156,7 +156,8 @@ type Store interface { //nolint:interfacebloat
|
|||||||
// GraphSession will provide the call-back with access to a
|
// GraphSession will provide the call-back with access to a
|
||||||
// NodeTraverser instance which can be used to perform queries against
|
// NodeTraverser instance which can be used to perform queries against
|
||||||
// the channel graph.
|
// the channel graph.
|
||||||
GraphSession(cb func(graph NodeTraverser) error, reset func()) error
|
GraphSession(ctx context.Context,
|
||||||
|
cb func(graph NodeTraverser) error, reset func()) error
|
||||||
|
|
||||||
// ForEachChannel iterates through all the channel edges stored within
|
// ForEachChannel iterates through all the channel edges stored within
|
||||||
// the graph and invokes the passed callback for each edge. The callback
|
// the graph and invokes the passed callback for each edge. The callback
|
||||||
|
|||||||
@@ -4487,8 +4487,8 @@ func (c *KVStore) IsClosedScid(_ context.Context,
|
|||||||
|
|
||||||
// GraphSession will provide the call-back with access to a NodeTraverser
|
// GraphSession will provide the call-back with access to a NodeTraverser
|
||||||
// instance which can be used to perform queries against the channel graph.
|
// instance which can be used to perform queries against the channel graph.
|
||||||
func (c *KVStore) GraphSession(cb func(graph NodeTraverser) error,
|
func (c *KVStore) GraphSession(_ context.Context,
|
||||||
reset func()) error {
|
cb func(graph NodeTraverser) error, reset func()) error {
|
||||||
|
|
||||||
return c.db.View(func(tx walletdb.ReadTx) error {
|
return c.db.View(func(tx walletdb.ReadTx) error {
|
||||||
return cb(&nodeTraverserSession{
|
return cb(&nodeTraverserSession{
|
||||||
|
|||||||
@@ -3316,10 +3316,8 @@ func (s *SQLStore) IsClosedScid(ctx context.Context,
|
|||||||
// instance which can be used to perform queries against the channel graph.
|
// instance which can be used to perform queries against the channel graph.
|
||||||
//
|
//
|
||||||
// NOTE: part of the Store interface.
|
// NOTE: part of the Store interface.
|
||||||
func (s *SQLStore) GraphSession(cb func(graph NodeTraverser) error,
|
func (s *SQLStore) GraphSession(ctx context.Context,
|
||||||
reset func()) error {
|
cb func(graph NodeTraverser) error, reset func()) error {
|
||||||
|
|
||||||
var ctx = context.TODO()
|
|
||||||
|
|
||||||
return s.db.ExecTx(ctx, sqldb.ReadTxOpt(), func(db SQLQueries) error {
|
return s.db.ExecTx(ctx, sqldb.ReadTxOpt(), func(db SQLQueries) error {
|
||||||
return cb(newSQLNodeTraverser(db, s.cfg.ChainHash))
|
return cb(newSQLNodeTraverser(db, s.cfg.ChainHash))
|
||||||
|
|||||||
+2
-1
@@ -32,7 +32,8 @@ type GraphSessionFactory interface {
|
|||||||
// GraphSession will provide the call-back with access to a
|
// GraphSession will provide the call-back with access to a
|
||||||
// graphdb.NodeTraverser instance which can be used to perform queries
|
// graphdb.NodeTraverser instance which can be used to perform queries
|
||||||
// against the channel graph.
|
// against the channel graph.
|
||||||
GraphSession(cb func(graph graphdb.NodeTraverser) error,
|
GraphSession(ctx context.Context,
|
||||||
|
cb func(graph graphdb.NodeTraverser) error,
|
||||||
reset func()) error
|
reset func()) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -234,8 +234,8 @@ func (m *mockGraph) FetchNodeFeatures(_ context.Context,
|
|||||||
// the channel graph.
|
// the channel graph.
|
||||||
//
|
//
|
||||||
// NOTE: Part of the GraphSessionFactory interface.
|
// NOTE: Part of the GraphSessionFactory interface.
|
||||||
func (m *mockGraph) GraphSession(cb func(graph graphdb.NodeTraverser) error,
|
func (m *mockGraph) GraphSession(_ context.Context,
|
||||||
_ func()) error {
|
cb func(graph graphdb.NodeTraverser) error, _ func()) error {
|
||||||
|
|
||||||
return cb(m)
|
return cb(m)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3326,7 +3326,7 @@ func dbFindPath(graph *graphdb.VersionedGraph,
|
|||||||
}
|
}
|
||||||
|
|
||||||
var route []*unifiedEdge
|
var route []*unifiedEdge
|
||||||
err = graph.GraphSession(func(graph graphdb.NodeTraverser) error {
|
err = graph.GraphSession(ctx, func(graph graphdb.NodeTraverser) error {
|
||||||
route, _, err = findPath(
|
route, _, err = findPath(
|
||||||
&graphParams{
|
&graphParams{
|
||||||
additionalEdges: additionalEdges,
|
additionalEdges: additionalEdges,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package routing
|
package routing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcec/v2"
|
"github.com/btcsuite/btcd/btcec/v2"
|
||||||
@@ -344,6 +345,7 @@ func (p *paymentSession) RequestRoute(maxAmt, feeLimit lnwire.MilliSatoshi,
|
|||||||
|
|
||||||
for {
|
for {
|
||||||
err := p.graphSessFactory.GraphSession(
|
err := p.graphSessFactory.GraphSession(
|
||||||
|
context.TODO(),
|
||||||
findPath, func() {
|
findPath, func() {
|
||||||
path = nil
|
path = nil
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package routing
|
package routing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -260,8 +261,8 @@ func (g *sessionGraph) sourceNode() route.Vertex {
|
|||||||
return route.Vertex{}
|
return route.Vertex{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *sessionGraph) GraphSession(cb func(graph graphdb.NodeTraverser) error,
|
func (g *sessionGraph) GraphSession(_ context.Context,
|
||||||
_ func()) error {
|
cb func(graph graphdb.NodeTraverser) error, _ func()) error {
|
||||||
|
|
||||||
return cb(g)
|
return cb(g)
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user