• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 16293817609

15 Jul 2025 12:53PM UTC coverage: 57.584% (-9.8%) from 67.338%
16293817609

Pull #10031

github

web-flow
Merge 8fd26da8b into df6c02e3a
Pull Request #10031: Skip unnecessary disconnect and wait for disconnect to finish in shutdown

36 of 40 new or added lines in 2 files covered. (90.0%)

28482 existing lines in 458 files now uncovered.

98681 of 171370 relevant lines covered (57.58%)

1.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

61.45
/graph/db/graph.go
1
package graphdb
2

3
import (
4
        "context"
5
        "errors"
6
        "fmt"
7
        "sync"
8
        "sync/atomic"
9
        "testing"
10
        "time"
11

12
        "github.com/btcsuite/btcd/chaincfg/chainhash"
13
        "github.com/btcsuite/btcd/wire"
14
        "github.com/lightningnetwork/lnd/batch"
15
        "github.com/lightningnetwork/lnd/graph/db/models"
16
        "github.com/lightningnetwork/lnd/lnwire"
17
        "github.com/lightningnetwork/lnd/routing/route"
18
        "github.com/stretchr/testify/require"
19
)
20

21
// ErrChanGraphShuttingDown indicates that the ChannelGraph has shutdown or is
22
// busy shutting down.
23
var ErrChanGraphShuttingDown = fmt.Errorf("ChannelGraph shutting down")
24

25
// ChannelGraph is a layer above the graph's CRUD layer.
26
//
27
// NOTE: currently, this is purely a pass-through layer directly to the backing
28
// KVStore. Upcoming commits will move the graph cache out of the KVStore and
29
// into this layer so that the KVStore is only responsible for CRUD operations.
30
type ChannelGraph struct {
31
        started atomic.Bool
32
        stopped atomic.Bool
33

34
        graphCache *GraphCache
35

36
        V1Store
37
        *topologyManager
38

39
        quit chan struct{}
40
        wg   sync.WaitGroup
41
}
42

43
// NewChannelGraph creates a new ChannelGraph instance with the given backend.
44
func NewChannelGraph(v1Store V1Store,
45
        options ...ChanGraphOption) (*ChannelGraph, error) {
3✔
46

3✔
47
        opts := defaultChanGraphOptions()
3✔
48
        for _, o := range options {
6✔
49
                o(opts)
3✔
50
        }
3✔
51

52
        g := &ChannelGraph{
3✔
53
                V1Store:         v1Store,
3✔
54
                topologyManager: newTopologyManager(),
3✔
55
                quit:            make(chan struct{}),
3✔
56
        }
3✔
57

3✔
58
        // The graph cache can be turned off (e.g. for mobile users) for a
3✔
59
        // speed/memory usage tradeoff.
3✔
60
        if opts.useGraphCache {
6✔
61
                g.graphCache = NewGraphCache(opts.preAllocCacheNumNodes)
3✔
62
        }
3✔
63

64
        return g, nil
3✔
65
}
66

67
// Start kicks off any goroutines required for the ChannelGraph to function.
68
// If the graph cache is enabled, then it will be populated with the contents of
69
// the database.
70
func (c *ChannelGraph) Start() error {
3✔
71
        if !c.started.CompareAndSwap(false, true) {
3✔
UNCOV
72
                return nil
×
UNCOV
73
        }
×
74
        log.Debugf("ChannelGraph starting")
3✔
75
        defer log.Debug("ChannelGraph started")
3✔
76

3✔
77
        if c.graphCache != nil {
6✔
78
                if err := c.populateCache(context.TODO()); err != nil {
3✔
79
                        return fmt.Errorf("could not populate the graph "+
×
80
                                "cache: %w", err)
×
81
                }
×
82
        }
83

84
        c.wg.Add(1)
3✔
85
        go c.handleTopologySubscriptions()
3✔
86

3✔
87
        return nil
3✔
88
}
89

90
// Stop signals any active goroutines for a graceful closure.
91
func (c *ChannelGraph) Stop() error {
3✔
92
        if !c.stopped.CompareAndSwap(false, true) {
3✔
UNCOV
93
                return nil
×
UNCOV
94
        }
×
95

96
        log.Debugf("ChannelGraph shutting down...")
3✔
97
        defer log.Debug("ChannelGraph shutdown complete")
3✔
98

3✔
99
        close(c.quit)
3✔
100
        c.wg.Wait()
3✔
101

3✔
102
        return nil
3✔
103
}
104

105
// handleTopologySubscriptions ensures that topology client subscriptions,
106
// subscription cancellations and topology notifications are handled
107
// synchronously.
108
//
109
// NOTE: this MUST be run in a goroutine.
110
func (c *ChannelGraph) handleTopologySubscriptions() {
3✔
111
        defer c.wg.Done()
3✔
112

3✔
113
        for {
6✔
114
                select {
3✔
115
                // A new fully validated topology update has just arrived.
116
                // We'll notify any registered clients.
117
                case update := <-c.topologyUpdate:
3✔
118
                        // TODO(elle): change topology handling to be handled
3✔
119
                        // synchronously so that we can guarantee the order of
3✔
120
                        // notification delivery.
3✔
121
                        c.wg.Add(1)
3✔
122
                        go c.handleTopologyUpdate(update)
3✔
123

124
                        // TODO(roasbeef): remove all unconnected vertexes
125
                        // after N blocks pass with no corresponding
126
                        // announcements.
127

128
                // A new notification client update has arrived. We're either
129
                // gaining a new client, or cancelling notifications for an
130
                // existing client.
131
                case ntfnUpdate := <-c.ntfnClientUpdates:
3✔
132
                        clientID := ntfnUpdate.clientID
3✔
133

3✔
134
                        if ntfnUpdate.cancel {
6✔
135
                                client, ok := c.topologyClients.LoadAndDelete(
3✔
136
                                        clientID,
3✔
137
                                )
3✔
138
                                if ok {
6✔
139
                                        close(client.exit)
3✔
140
                                        client.wg.Wait()
3✔
141

3✔
142
                                        close(client.ntfnChan)
3✔
143
                                }
3✔
144

145
                                continue
3✔
146
                        }
147

148
                        c.topologyClients.Store(clientID, &topologyClient{
3✔
149
                                ntfnChan: ntfnUpdate.ntfnChan,
3✔
150
                                exit:     make(chan struct{}),
3✔
151
                        })
3✔
152

153
                case <-c.quit:
3✔
154
                        return
3✔
155
                }
156
        }
157
}
158

159
// populateCache loads the entire channel graph into the in-memory graph cache.
160
//
161
// NOTE: This should only be called if the graphCache has been constructed.
162
func (c *ChannelGraph) populateCache(ctx context.Context) error {
3✔
163
        startTime := time.Now()
3✔
164
        log.Info("Populating in-memory channel graph, this might take a " +
3✔
165
                "while...")
3✔
166

3✔
167
        err := c.V1Store.ForEachNodeCacheable(ctx, func(node route.Vertex,
3✔
168
                features *lnwire.FeatureVector) error {
6✔
169

3✔
170
                c.graphCache.AddNodeFeatures(node, features)
3✔
171

3✔
172
                return nil
3✔
173
        }, func() {})
6✔
174
        if err != nil {
3✔
175
                return err
×
176
        }
×
177

178
        err = c.V1Store.ForEachChannelCacheable(
3✔
179
                func(info *models.CachedEdgeInfo,
3✔
180
                        policy1, policy2 *models.CachedEdgePolicy) error {
6✔
181

3✔
182
                        c.graphCache.AddChannel(info, policy1, policy2)
3✔
183

3✔
184
                        return nil
3✔
185
                }, func() {},
6✔
186
        )
187
        if err != nil {
3✔
188
                return err
×
189
        }
×
190

191
        log.Infof("Finished populating in-memory channel graph (took %v, %s)",
3✔
192
                time.Since(startTime), c.graphCache.Stats())
3✔
193

3✔
194
        return nil
3✔
195
}
196

197
// ForEachNodeDirectedChannel iterates through all channels of a given node,
198
// executing the passed callback on the directed edge representing the channel
199
// and its incoming policy. If the callback returns an error, then the iteration
200
// is halted with the error propagated back up to the caller. If the graphCache
201
// is available, then it will be used to retrieve the node's channels instead
202
// of the database.
203
//
204
// Unknown policies are passed into the callback as nil values.
205
//
206
// NOTE: this is part of the graphdb.NodeTraverser interface.
207
func (c *ChannelGraph) ForEachNodeDirectedChannel(node route.Vertex,
208
        cb func(channel *DirectedChannel) error, reset func()) error {
3✔
209

3✔
210
        if c.graphCache != nil {
6✔
211
                return c.graphCache.ForEachChannel(node, cb)
3✔
212
        }
3✔
213

214
        return c.V1Store.ForEachNodeDirectedChannel(node, cb, reset)
3✔
215
}
216

217
// FetchNodeFeatures returns the features of the given node. If no features are
218
// known for the node, an empty feature vector is returned.
219
// If the graphCache is available, then it will be used to retrieve the node's
220
// features instead of the database.
221
//
222
// NOTE: this is part of the graphdb.NodeTraverser interface.
223
func (c *ChannelGraph) FetchNodeFeatures(node route.Vertex) (
224
        *lnwire.FeatureVector, error) {
3✔
225

3✔
226
        if c.graphCache != nil {
6✔
227
                return c.graphCache.GetFeatures(node), nil
3✔
228
        }
3✔
229

230
        return c.V1Store.FetchNodeFeatures(node)
3✔
231
}
232

233
// GraphSession will provide the call-back with access to a NodeTraverser
234
// instance which can be used to perform queries against the channel graph. If
235
// the graph cache is not enabled, then the call-back will be provided with
236
// access to the graph via a consistent read-only transaction.
237
func (c *ChannelGraph) GraphSession(cb func(graph NodeTraverser) error,
238
        reset func()) error {
3✔
239

3✔
240
        if c.graphCache != nil {
6✔
241
                return cb(c)
3✔
242
        }
3✔
243

UNCOV
244
        return c.V1Store.GraphSession(cb, reset)
×
245
}
246

247
// ForEachNodeCached iterates through all the stored vertices/nodes in the
248
// graph, executing the passed callback with each node encountered.
249
//
250
// NOTE: The callback contents MUST not be modified.
251
func (c *ChannelGraph) ForEachNodeCached(ctx context.Context,
252
        cb func(node route.Vertex, chans map[uint64]*DirectedChannel) error,
UNCOV
253
        reset func()) error {
×
UNCOV
254

×
UNCOV
255
        if c.graphCache != nil {
×
256
                return c.graphCache.ForEachNode(cb)
×
257
        }
×
258

UNCOV
259
        return c.V1Store.ForEachNodeCached(ctx, cb, reset)
×
260
}
261

262
// AddLightningNode adds a vertex/node to the graph database. If the node is not
263
// in the database from before, this will add a new, unconnected one to the
264
// graph. If it is present from before, this will update that node's
265
// information. Note that this method is expected to only be called to update an
266
// already present node from a node announcement, or to insert a node found in a
267
// channel update.
268
func (c *ChannelGraph) AddLightningNode(ctx context.Context,
269
        node *models.LightningNode, op ...batch.SchedulerOption) error {
3✔
270

3✔
271
        err := c.V1Store.AddLightningNode(ctx, node, op...)
3✔
272
        if err != nil {
3✔
273
                return err
×
274
        }
×
275

276
        if c.graphCache != nil {
6✔
277
                c.graphCache.AddNodeFeatures(
3✔
278
                        node.PubKeyBytes, node.Features,
3✔
279
                )
3✔
280
        }
3✔
281

282
        select {
3✔
283
        case c.topologyUpdate <- node:
3✔
284
        case <-c.quit:
×
285
                return ErrChanGraphShuttingDown
×
286
        }
287

288
        return nil
3✔
289
}
290

291
// DeleteLightningNode starts a new database transaction to remove a vertex/node
292
// from the database according to the node's public key.
293
func (c *ChannelGraph) DeleteLightningNode(ctx context.Context,
UNCOV
294
        nodePub route.Vertex) error {
×
UNCOV
295

×
UNCOV
296
        err := c.V1Store.DeleteLightningNode(ctx, nodePub)
×
UNCOV
297
        if err != nil {
×
UNCOV
298
                return err
×
UNCOV
299
        }
×
300

UNCOV
301
        if c.graphCache != nil {
×
UNCOV
302
                c.graphCache.RemoveNode(nodePub)
×
UNCOV
303
        }
×
304

UNCOV
305
        return nil
×
306
}
307

308
// AddChannelEdge adds a new (undirected, blank) edge to the graph database. An
309
// undirected edge from the two target nodes are created. The information stored
310
// denotes the static attributes of the channel, such as the channelID, the keys
311
// involved in creation of the channel, and the set of features that the channel
312
// supports. The chanPoint and chanID are used to uniquely identify the edge
313
// globally within the database.
314
func (c *ChannelGraph) AddChannelEdge(ctx context.Context,
315
        edge *models.ChannelEdgeInfo, op ...batch.SchedulerOption) error {
3✔
316

3✔
317
        err := c.V1Store.AddChannelEdge(ctx, edge, op...)
3✔
318
        if err != nil {
3✔
UNCOV
319
                return err
×
UNCOV
320
        }
×
321

322
        if c.graphCache != nil {
6✔
323
                c.graphCache.AddChannel(models.NewCachedEdge(edge), nil, nil)
3✔
324
        }
3✔
325

326
        select {
3✔
327
        case c.topologyUpdate <- edge:
3✔
328
        case <-c.quit:
×
329
                return ErrChanGraphShuttingDown
×
330
        }
331

332
        return nil
3✔
333
}
334

335
// MarkEdgeLive clears an edge from our zombie index, deeming it as live.
336
// If the cache is enabled, the edge will be added back to the graph cache if
337
// we still have a record of this channel in the DB.
UNCOV
338
func (c *ChannelGraph) MarkEdgeLive(chanID uint64) error {
×
UNCOV
339
        err := c.V1Store.MarkEdgeLive(chanID)
×
UNCOV
340
        if err != nil {
×
UNCOV
341
                return err
×
UNCOV
342
        }
×
343

UNCOV
344
        if c.graphCache != nil {
×
UNCOV
345
                // We need to add the channel back into our graph cache,
×
UNCOV
346
                // otherwise we won't use it for path finding.
×
UNCOV
347
                infos, err := c.V1Store.FetchChanInfos([]uint64{chanID})
×
UNCOV
348
                if err != nil {
×
349
                        return err
×
350
                }
×
351

UNCOV
352
                if len(infos) == 0 {
×
UNCOV
353
                        return nil
×
UNCOV
354
                }
×
355

356
                info := infos[0]
×
357

×
358
                var policy1, policy2 *models.CachedEdgePolicy
×
359
                if info.Policy1 != nil {
×
360
                        policy1 = models.NewCachedPolicy(info.Policy1)
×
361
                }
×
362
                if info.Policy2 != nil {
×
363
                        policy2 = models.NewCachedPolicy(info.Policy2)
×
364
                }
×
365

366
                c.graphCache.AddChannel(
×
367
                        models.NewCachedEdge(info.Info), policy1, policy2,
×
368
                )
×
369
        }
370

371
        return nil
×
372
}
373

374
// DeleteChannelEdges removes edges with the given channel IDs from the
375
// database and marks them as zombies. This ensures that we're unable to re-add
376
// it to our database once again. If an edge does not exist within the
377
// database, then ErrEdgeNotFound will be returned. If strictZombiePruning is
378
// true, then when we mark these edges as zombies, we'll set up the keys such
379
// that we require the node that failed to send the fresh update to be the one
380
// that resurrects the channel from its zombie state. The markZombie bool
381
// denotes whether to mark the channel as a zombie.
382
func (c *ChannelGraph) DeleteChannelEdges(strictZombiePruning, markZombie bool,
383
        chanIDs ...uint64) error {
3✔
384

3✔
385
        infos, err := c.V1Store.DeleteChannelEdges(
3✔
386
                strictZombiePruning, markZombie, chanIDs...,
3✔
387
        )
3✔
388
        if err != nil {
3✔
UNCOV
389
                return err
×
UNCOV
390
        }
×
391

392
        if c.graphCache != nil {
6✔
393
                for _, info := range infos {
6✔
394
                        c.graphCache.RemoveChannel(
3✔
395
                                info.NodeKey1Bytes, info.NodeKey2Bytes,
3✔
396
                                info.ChannelID,
3✔
397
                        )
3✔
398
                }
3✔
399
        }
400

401
        return err
3✔
402
}
403

404
// DisconnectBlockAtHeight is used to indicate that the block specified
405
// by the passed height has been disconnected from the main chain. This
406
// will "rewind" the graph back to the height below, deleting channels
407
// that are no longer confirmed from the graph. The prune log will be
408
// set to the last prune height valid for the remaining chain.
409
// Channels that were removed from the graph resulting from the
410
// disconnected block are returned.
411
func (c *ChannelGraph) DisconnectBlockAtHeight(height uint32) (
412
        []*models.ChannelEdgeInfo, error) {
2✔
413

2✔
414
        edges, err := c.V1Store.DisconnectBlockAtHeight(height)
2✔
415
        if err != nil {
2✔
416
                return nil, err
×
417
        }
×
418

419
        if c.graphCache != nil {
4✔
420
                for _, edge := range edges {
4✔
421
                        c.graphCache.RemoveChannel(
2✔
422
                                edge.NodeKey1Bytes, edge.NodeKey2Bytes,
2✔
423
                                edge.ChannelID,
2✔
424
                        )
2✔
425
                }
2✔
426
        }
427

428
        return edges, nil
2✔
429
}
430

431
// PruneGraph prunes newly closed channels from the channel graph in response
432
// to a new block being solved on the network. Any transactions which spend the
433
// funding output of any known channels within he graph will be deleted.
434
// Additionally, the "prune tip", or the last block which has been used to
435
// prune the graph is stored so callers can ensure the graph is fully in sync
436
// with the current UTXO state. A slice of channels that have been closed by
437
// the target block are returned if the function succeeds without error.
438
func (c *ChannelGraph) PruneGraph(spentOutputs []*wire.OutPoint,
439
        blockHash *chainhash.Hash, blockHeight uint32) (
440
        []*models.ChannelEdgeInfo, error) {
3✔
441

3✔
442
        edges, nodes, err := c.V1Store.PruneGraph(
3✔
443
                spentOutputs, blockHash, blockHeight,
3✔
444
        )
3✔
445
        if err != nil {
3✔
446
                return nil, err
×
447
        }
×
448

449
        if c.graphCache != nil {
6✔
450
                for _, edge := range edges {
6✔
451
                        c.graphCache.RemoveChannel(
3✔
452
                                edge.NodeKey1Bytes, edge.NodeKey2Bytes,
3✔
453
                                edge.ChannelID,
3✔
454
                        )
3✔
455
                }
3✔
456

457
                for _, node := range nodes {
6✔
458
                        c.graphCache.RemoveNode(node)
3✔
459
                }
3✔
460

461
                log.Debugf("Pruned graph, cache now has %s",
3✔
462
                        c.graphCache.Stats())
3✔
463
        }
464

465
        if len(edges) != 0 {
6✔
466
                // Notify all currently registered clients of the newly closed
3✔
467
                // channels.
3✔
468
                closeSummaries := createCloseSummaries(
3✔
469
                        blockHeight, edges...,
3✔
470
                )
3✔
471

3✔
472
                select {
3✔
473
                case c.topologyUpdate <- closeSummaries:
3✔
474
                case <-c.quit:
×
475
                        return nil, ErrChanGraphShuttingDown
×
476
                }
477
        }
478

479
        return edges, nil
3✔
480
}
481

482
// PruneGraphNodes is a garbage collection method which attempts to prune out
483
// any nodes from the channel graph that are currently unconnected. This ensure
484
// that we only maintain a graph of reachable nodes. In the event that a pruned
485
// node gains more channels, it will be re-added back to the graph.
486
func (c *ChannelGraph) PruneGraphNodes() error {
3✔
487
        nodes, err := c.V1Store.PruneGraphNodes()
3✔
488
        if err != nil {
3✔
489
                return err
×
490
        }
×
491

492
        if c.graphCache != nil {
6✔
493
                for _, node := range nodes {
3✔
UNCOV
494
                        c.graphCache.RemoveNode(node)
×
UNCOV
495
                }
×
496
        }
497

498
        return nil
3✔
499
}
500

501
// FilterKnownChanIDs takes a set of channel IDs and return the subset of chan
502
// ID's that we don't know and are not known zombies of the passed set. In other
503
// words, we perform a set difference of our set of chan ID's and the ones
504
// passed in. This method can be used by callers to determine the set of
505
// channels another peer knows of that we don't.
506
func (c *ChannelGraph) FilterKnownChanIDs(chansInfo []ChannelUpdateInfo,
507
        isZombieChan func(time.Time, time.Time) bool) ([]uint64, error) {
3✔
508

3✔
509
        unknown, knownZombies, err := c.V1Store.FilterKnownChanIDs(chansInfo)
3✔
510
        if err != nil {
3✔
511
                return nil, err
×
512
        }
×
513

514
        for _, info := range knownZombies {
3✔
UNCOV
515
                // TODO(ziggie): Make sure that for the strict pruning case we
×
UNCOV
516
                // compare the pubkeys and whether the right timestamp is not
×
UNCOV
517
                // older than the `ChannelPruneExpiry`.
×
UNCOV
518
                //
×
UNCOV
519
                // NOTE: The timestamp data has no verification attached to it
×
UNCOV
520
                // in the `ReplyChannelRange` msg so we are trusting this data
×
UNCOV
521
                // at this point. However it is not critical because we are just
×
UNCOV
522
                // removing the channel from the db when the timestamps are more
×
UNCOV
523
                // recent. During the querying of the gossip msg verification
×
UNCOV
524
                // happens as usual. However we should start punishing peers
×
UNCOV
525
                // when they don't provide us honest data ?
×
UNCOV
526
                isStillZombie := isZombieChan(
×
UNCOV
527
                        info.Node1UpdateTimestamp, info.Node2UpdateTimestamp,
×
UNCOV
528
                )
×
UNCOV
529

×
UNCOV
530
                if isStillZombie {
×
UNCOV
531
                        continue
×
532
                }
533

534
                // If we have marked it as a zombie but the latest update
535
                // timestamps could bring it back from the dead, then we mark it
536
                // alive, and we let it be added to the set of IDs to query our
537
                // peer for.
UNCOV
538
                err := c.V1Store.MarkEdgeLive(
×
UNCOV
539
                        info.ShortChannelID.ToUint64(),
×
UNCOV
540
                )
×
UNCOV
541
                // Since there is a chance that the edge could have been marked
×
UNCOV
542
                // as "live" between the FilterKnownChanIDs call and the
×
UNCOV
543
                // MarkEdgeLive call, we ignore the error if the edge is already
×
UNCOV
544
                // marked as live.
×
UNCOV
545
                if err != nil && !errors.Is(err, ErrZombieEdgeNotFound) {
×
546
                        return nil, err
×
547
                }
×
548
        }
549

550
        return unknown, nil
3✔
551
}
552

553
// MarkEdgeZombie attempts to mark a channel identified by its channel ID as a
554
// zombie. This method is used on an ad-hoc basis, when channels need to be
555
// marked as zombies outside the normal pruning cycle.
556
func (c *ChannelGraph) MarkEdgeZombie(chanID uint64,
UNCOV
557
        pubKey1, pubKey2 [33]byte) error {
×
UNCOV
558

×
UNCOV
559
        err := c.V1Store.MarkEdgeZombie(chanID, pubKey1, pubKey2)
×
UNCOV
560
        if err != nil {
×
561
                return err
×
562
        }
×
563

UNCOV
564
        if c.graphCache != nil {
×
UNCOV
565
                c.graphCache.RemoveChannel(pubKey1, pubKey2, chanID)
×
UNCOV
566
        }
×
567

UNCOV
568
        return nil
×
569
}
570

571
// UpdateEdgePolicy updates the edge routing policy for a single directed edge
572
// within the database for the referenced channel. The `flags` attribute within
573
// the ChannelEdgePolicy determines which of the directed edges are being
574
// updated. If the flag is 1, then the first node's information is being
575
// updated, otherwise it's the second node's information. The node ordering is
576
// determined by the lexicographical ordering of the identity public keys of the
577
// nodes on either side of the channel.
578
func (c *ChannelGraph) UpdateEdgePolicy(ctx context.Context,
579
        edge *models.ChannelEdgePolicy, op ...batch.SchedulerOption) error {
3✔
580

3✔
581
        from, to, err := c.V1Store.UpdateEdgePolicy(ctx, edge, op...)
3✔
582
        if err != nil {
3✔
UNCOV
583
                return err
×
UNCOV
584
        }
×
585

586
        if c.graphCache != nil {
6✔
587
                c.graphCache.UpdatePolicy(
3✔
588
                        models.NewCachedPolicy(edge), from, to,
3✔
589
                )
3✔
590
        }
3✔
591

592
        select {
3✔
593
        case c.topologyUpdate <- edge:
3✔
594
        case <-c.quit:
×
595
                return ErrChanGraphShuttingDown
×
596
        }
597

598
        return nil
3✔
599
}
600

601
// MakeTestGraph creates a new instance of the ChannelGraph for testing
602
// purposes. The backing V1Store implementation depends on the version of
603
// NewTestDB included in the current build.
604
//
605
// NOTE: this is currently unused, but is left here for future use to show how
606
// NewTestDB can be used. As the SQL implementation of the V1Store is
607
// implemented, unit tests will be switched to use this function instead of
608
// the existing MakeTestGraph helper. Once only this function is used, the
609
// existing MakeTestGraph function will be removed and this one will be renamed.
610
func MakeTestGraph(t testing.TB,
UNCOV
611
        opts ...ChanGraphOption) *ChannelGraph {
×
UNCOV
612

×
UNCOV
613
        t.Helper()
×
UNCOV
614

×
UNCOV
615
        store := NewTestDB(t)
×
UNCOV
616

×
UNCOV
617
        graph, err := NewChannelGraph(store, opts...)
×
UNCOV
618
        require.NoError(t, err)
×
UNCOV
619
        require.NoError(t, graph.Start())
×
UNCOV
620

×
UNCOV
621
        t.Cleanup(func() {
×
UNCOV
622
                require.NoError(t, graph.Stop())
×
UNCOV
623
        })
×
624

UNCOV
625
        return graph
×
626
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc