@@ -881,19 +881,23 @@ func (c *KVStore) ForEachNodeCacheable(cb func(route.Vertex,
881
881
// as the center node within a star-graph. This method may be used to kick off
882
882
// a path finding algorithm in order to explore the reachability of another
883
883
// node based off the source node.
884
- func (c * KVStore ) SourceNode (_ context.Context ) (* models.LightningNode ,
885
- error ) {
884
+ func (c * KVStore ) SourceNode (_ context.Context ) (* models.LightningNode , error ) {
885
+ return sourceNode (c .db )
886
+ }
886
887
888
+ // sourceNode fetches the source node of the graph. The source node is treated
889
+ // as the center node within a star-graph.
890
+ func sourceNode (db kvdb.Backend ) (* models.LightningNode , error ) {
887
891
var source * models.LightningNode
888
- err := kvdb .View (c . db , func (tx kvdb.RTx ) error {
892
+ err := kvdb .View (db , func (tx kvdb.RTx ) error {
889
893
// First grab the nodes bucket which stores the mapping from
890
894
// pubKey to node information.
891
895
nodes := tx .ReadBucket (nodeBucket )
892
896
if nodes == nil {
893
897
return ErrGraphNotFound
894
898
}
895
899
896
- node , err := c . sourceNode (nodes )
900
+ node , err := sourceNodeWithTx (nodes )
897
901
if err != nil {
898
902
return err
899
903
}
@@ -910,13 +914,11 @@ func (c *KVStore) SourceNode(_ context.Context) (*models.LightningNode,
910
914
return source , nil
911
915
}
912
916
913
- // sourceNode uses an existing database transaction and returns the source node
914
- // of the graph. The source node is treated as the center node within a
917
+ // sourceNodeWithTx uses an existing database transaction and returns the source
918
+ // node of the graph. The source node is treated as the center node within a
915
919
// star-graph. This method may be used to kick off a path finding algorithm in
916
920
// order to explore the reachability of another node based off the source node.
917
- func (c * KVStore ) sourceNode (nodes kvdb.RBucket ) (* models.LightningNode ,
918
- error ) {
919
-
921
+ func sourceNodeWithTx (nodes kvdb.RBucket ) (* models.LightningNode , error ) {
920
922
selfPub := nodes .Get (sourceKey )
921
923
if selfPub == nil {
922
924
return nil , ErrSourceNodeNotSet
@@ -1569,7 +1571,7 @@ func (c *KVStore) pruneGraphNodes(nodes kvdb.RwBucket,
1569
1571
1570
1572
// We'll retrieve the graph's source node to ensure we don't remove it
1571
1573
// even if it no longer has any open channels.
1572
- sourceNode , err := c . sourceNode (nodes )
1574
+ sourceNode , err := sourceNodeWithTx (nodes )
1573
1575
if err != nil {
1574
1576
return nil , err
1575
1577
}
@@ -3255,7 +3257,7 @@ func (c *KVStore) ForEachSourceNodeChannel(cb func(chanPoint wire.OutPoint,
3255
3257
return ErrGraphNotFound
3256
3258
}
3257
3259
3258
- node , err := c . sourceNode (nodes )
3260
+ node , err := sourceNodeWithTx (nodes )
3259
3261
if err != nil {
3260
3262
return err
3261
3263
}
0 commit comments