@@ -529,7 +529,7 @@ func (c *ChannelGraph) FetchNodeFeatures(
529529 }
530530
531531 // Fallback that uses the database.
532- targetNode , err := c .FetchLightningNode (nil , node )
532+ targetNode , err := c .FetchLightningNode (node )
533533 switch err {
534534 // If the node exists and has features, return them directly.
535535 case nil :
@@ -565,7 +565,7 @@ func (c *ChannelGraph) ForEachNodeCached(cb func(node route.Vertex,
565565 return c .ForEachNode (func (tx kvdb.RTx , node * LightningNode ) error {
566566 channels := make (map [uint64 ]* DirectedChannel )
567567
568- err := c .ForEachNodeChannel (tx , node .PubKeyBytes ,
568+ err := c .ForEachNodeChannelTx (tx , node .PubKeyBytes ,
569569 func (tx kvdb.RTx , e * models.ChannelEdgeInfo ,
570570 p1 * models.ChannelEdgePolicy ,
571571 p2 * models.ChannelEdgePolicy ) error {
@@ -2374,10 +2374,19 @@ func (c *ChannelGraph) FilterChannelRange(startHeight,
23742374// skipped and the result will contain only those edges that exist at the time
23752375// of the query. This can be used to respond to peer queries that are seeking to
23762376// fill in gaps in their view of the channel graph.
2377+ func (c * ChannelGraph ) FetchChanInfos (chanIDs []uint64 ) ([]ChannelEdge , error ) {
2378+ return c .fetchChanInfos (nil , chanIDs )
2379+ }
2380+
2381+ // fetchChanInfos returns the set of channel edges that correspond to the passed
2382+ // channel ID's. If an edge is the query is unknown to the database, it will
2383+ // skipped and the result will contain only those edges that exist at the time
2384+ // of the query. This can be used to respond to peer queries that are seeking to
2385+ // fill in gaps in their view of the channel graph.
23772386//
23782387// NOTE: An optional transaction may be provided. If none is provided, then a
23792388// new one will be created.
2380- func (c * ChannelGraph ) FetchChanInfos (tx kvdb.RTx , chanIDs []uint64 ) (
2389+ func (c * ChannelGraph ) fetchChanInfos (tx kvdb.RTx , chanIDs []uint64 ) (
23812390 []ChannelEdge , error ) {
23822391 // TODO(roasbeef): sort cids?
23832392
@@ -2922,7 +2931,7 @@ func (c *ChannelGraph) isPublic(tx kvdb.RTx, nodePub route.Vertex,
29222931 // used to terminate the check early.
29232932 nodeIsPublic := false
29242933 errDone := errors .New ("done" )
2925- err := c .ForEachNodeChannel (tx , nodePub , func (tx kvdb.RTx ,
2934+ err := c .ForEachNodeChannelTx (tx , nodePub , func (tx kvdb.RTx ,
29262935 info * models.ChannelEdgeInfo , _ * models.ChannelEdgePolicy ,
29272936 _ * models.ChannelEdgePolicy ) error {
29282937
@@ -2954,12 +2963,31 @@ func (c *ChannelGraph) isPublic(tx kvdb.RTx, nodePub route.Vertex,
29542963 return nodeIsPublic , nil
29552964}
29562965
2966+ // FetchLightningNodeTx attempts to look up a target node by its identity
2967+ // public key. If the node isn't found in the database, then
2968+ // ErrGraphNodeNotFound is returned. An optional transaction may be provided.
2969+ // If none is provided, then a new one will be created.
2970+ func (c * ChannelGraph ) FetchLightningNodeTx (tx kvdb.RTx , nodePub route.Vertex ) (
2971+ * LightningNode , error ) {
2972+
2973+ return c .fetchLightningNode (tx , nodePub )
2974+ }
2975+
29572976// FetchLightningNode attempts to look up a target node by its identity public
29582977// key. If the node isn't found in the database, then ErrGraphNodeNotFound is
2978+ // returned.
2979+ func (c * ChannelGraph ) FetchLightningNode (nodePub route.Vertex ) (* LightningNode ,
2980+ error ) {
2981+
2982+ return c .fetchLightningNode (nil , nodePub )
2983+ }
2984+
2985+ // fetchLightningNode attempts to look up a target node by its identity public
2986+ // key. If the node isn't found in the database, then ErrGraphNodeNotFound is
29592987// returned. An optional transaction may be provided. If none is provided, then
29602988// a new one will be created.
2961- func (c * ChannelGraph ) FetchLightningNode (tx kvdb.RTx , nodePub route. Vertex ) (
2962- * LightningNode , error ) {
2989+ func (c * ChannelGraph ) fetchLightningNode (tx kvdb.RTx ,
2990+ nodePub route. Vertex ) ( * LightningNode , error ) {
29632991
29642992 var node * LightningNode
29652993 fetch := func (tx kvdb.RTx ) error {
@@ -3196,13 +3224,29 @@ func nodeTraversal(tx kvdb.RTx, nodePub []byte, db kvdb.Backend,
31963224// halted with the error propagated back up to the caller.
31973225//
31983226// Unknown policies are passed into the callback as nil values.
3227+ func (c * ChannelGraph ) ForEachNodeChannel (nodePub route.Vertex ,
3228+ cb func (kvdb.RTx , * models.ChannelEdgeInfo , * models.ChannelEdgePolicy ,
3229+ * models.ChannelEdgePolicy ) error ) error {
3230+
3231+ return nodeTraversal (nil , nodePub [:], c .db , cb )
3232+ }
3233+
3234+ // ForEachNodeChannelTx iterates through all channels of the given node,
3235+ // executing the passed callback with an edge info structure and the policies
3236+ // of each end of the channel. The first edge policy is the outgoing edge *to*
3237+ // the connecting node, while the second is the incoming edge *from* the
3238+ // connecting node. If the callback returns an error, then the iteration is
3239+ // halted with the error propagated back up to the caller.
3240+ //
3241+ // Unknown policies are passed into the callback as nil values.
31993242//
32003243// If the caller wishes to re-use an existing boltdb transaction, then it
3201- // should be passed as the first argument. Otherwise the first argument should
3244+ // should be passed as the first argument. Otherwise, the first argument should
32023245// be nil and a fresh transaction will be created to execute the graph
32033246// traversal.
3204- func (c * ChannelGraph ) ForEachNodeChannel (tx kvdb.RTx , nodePub route.Vertex ,
3205- cb func (kvdb.RTx , * models.ChannelEdgeInfo , * models.ChannelEdgePolicy ,
3247+ func (c * ChannelGraph ) ForEachNodeChannelTx (tx kvdb.RTx ,
3248+ nodePub route.Vertex , cb func (kvdb.RTx , * models.ChannelEdgeInfo ,
3249+ * models.ChannelEdgePolicy ,
32063250 * models.ChannelEdgePolicy ) error ) error {
32073251
32083252 return nodeTraversal (tx , nodePub [:], c .db , cb )
@@ -3705,7 +3749,7 @@ func (c *ChannelGraph) markEdgeLiveUnsafe(tx kvdb.RwTx, chanID uint64) error {
37053749 // We need to add the channel back into our graph cache, otherwise we
37063750 // won't use it for path finding.
37073751 if c .graphCache != nil {
3708- edgeInfos , err := c .FetchChanInfos (tx , []uint64 {chanID })
3752+ edgeInfos , err := c .fetchChanInfos (tx , []uint64 {chanID })
37093753 if err != nil {
37103754 return err
37113755 }
0 commit comments