Skip to content

Commit 016fd9b

Browse files
committed
graph/db: create a re-usable forEachChannel
Create a forEachChannel function that does not rely on a KVStore being instantiated. We will use this in our upcoming kvdb->SQL migration.
1 parent 9452c0b commit 016fd9b

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

graph/db/kv_store.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,22 @@ func (c *KVStore) AddrsForNode(ctx context.Context,
407407
func (c *KVStore) ForEachChannel(cb func(*models.ChannelEdgeInfo,
408408
*models.ChannelEdgePolicy, *models.ChannelEdgePolicy) error) error {
409409

410-
return c.db.View(func(tx kvdb.RTx) error {
410+
return forEachChannel(c.db, cb)
411+
}
412+
413+
// forEachChannel iterates through all the channel edges stored within the
414+
// graph and invokes the passed callback for each edge. The callback takes two
415+
// edges as since this is a directed graph, both the in/out edges are visited.
416+
// If the callback returns an error, then the transaction is aborted and the
417+
// iteration stops early.
418+
//
419+
// NOTE: If an edge can't be found, or wasn't advertised, then a nil pointer
420+
// for that particular channel edge routing policy will be passed into the
421+
// callback.
422+
func forEachChannel(db kvdb.Backend, cb func(*models.ChannelEdgeInfo,
423+
*models.ChannelEdgePolicy, *models.ChannelEdgePolicy) error) error {
424+
425+
return db.View(func(tx kvdb.RTx) error {
411426
edges := tx.ReadBucket(edgeBucket)
412427
if edges == nil {
413428
return ErrGraphNoEdgesFound

0 commit comments

Comments
 (0)