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

lightningnetwork / lnd / 15838907453

24 Jun 2025 01:26AM UTC coverage: 57.079% (-11.1%) from 68.172%
15838907453

Pull #9982

github

web-flow
Merge e42780be2 into 45c15646c
Pull Request #9982: lnwire+lnwallet: add LocalNonces field for splice nonce coordination w/ taproot channels

103 of 167 new or added lines in 5 files covered. (61.68%)

30191 existing lines in 463 files now uncovered.

96331 of 168768 relevant lines covered (57.08%)

0.6 hits per line

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

61.34
/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) {
1✔
46

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

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

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

64
        return g, nil
1✔
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 {
1✔
71
        if !c.started.CompareAndSwap(false, true) {
1✔
UNCOV
72
                return nil
×
UNCOV
73
        }
×
74
        log.Debugf("ChannelGraph starting")
1✔
75
        defer log.Debug("ChannelGraph started")
1✔
76

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

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

1✔
87
        return nil
1✔
88
}
89

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

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

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

1✔
102
        return nil
1✔
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() {
1✔
111
        defer c.wg.Done()
1✔
112

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

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

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

145
                                continue
1✔
146
                        }
147

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

153
                case <-c.quit:
1✔
154
                        return
1✔
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() error {
1✔
163
        startTime := time.Now()
1✔
164
        log.Info("Populating in-memory channel graph, this might take a " +
1✔
165
                "while...")
1✔
166

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

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

1✔
172
                return nil
1✔
173
        })
1✔
174
        if err != nil {
1✔
175
                return err
×
176
        }
×
177

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

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

1✔
184
                        return nil
1✔
185
                })
1✔
186
        if err != nil {
1✔
187
                return err
×
188
        }
×
189

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

1✔
193
        return nil
1✔
194
}
195

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

1✔
209
        if c.graphCache != nil {
2✔
210
                return c.graphCache.ForEachChannel(node, cb)
1✔
211
        }
1✔
212

213
        return c.V1Store.ForEachNodeDirectedChannel(node, cb)
1✔
214
}
215

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

1✔
225
        if c.graphCache != nil {
2✔
226
                return c.graphCache.GetFeatures(node), nil
1✔
227
        }
1✔
228

229
        return c.V1Store.FetchNodeFeatures(node)
1✔
230
}
231

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

UNCOV
241
        return c.V1Store.GraphSession(cb)
×
242
}
243

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

×
UNCOV
251
        if c.graphCache != nil {
×
252
                return c.graphCache.ForEachNode(cb)
×
253
        }
×
254

UNCOV
255
        return c.V1Store.ForEachNodeCached(cb)
×
256
}
257

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

1✔
267
        err := c.V1Store.AddLightningNode(ctx, node, op...)
1✔
268
        if err != nil {
1✔
269
                return err
×
270
        }
×
271

272
        if c.graphCache != nil {
2✔
273
                c.graphCache.AddNodeFeatures(
1✔
274
                        node.PubKeyBytes, node.Features,
1✔
275
                )
1✔
276
        }
1✔
277

278
        select {
1✔
279
        case c.topologyUpdate <- node:
1✔
280
        case <-c.quit:
×
281
                return ErrChanGraphShuttingDown
×
282
        }
283

284
        return nil
1✔
285
}
286

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

×
UNCOV
292
        err := c.V1Store.DeleteLightningNode(ctx, nodePub)
×
UNCOV
293
        if err != nil {
×
UNCOV
294
                return err
×
UNCOV
295
        }
×
296

UNCOV
297
        if c.graphCache != nil {
×
UNCOV
298
                c.graphCache.RemoveNode(nodePub)
×
UNCOV
299
        }
×
300

UNCOV
301
        return nil
×
302
}
303

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

1✔
313
        err := c.V1Store.AddChannelEdge(ctx, edge, op...)
1✔
314
        if err != nil {
1✔
UNCOV
315
                return err
×
UNCOV
316
        }
×
317

318
        if c.graphCache != nil {
2✔
319
                c.graphCache.AddChannel(models.NewCachedEdge(edge), nil, nil)
1✔
320
        }
1✔
321

322
        select {
1✔
323
        case c.topologyUpdate <- edge:
1✔
324
        case <-c.quit:
×
325
                return ErrChanGraphShuttingDown
×
326
        }
327

328
        return nil
1✔
329
}
330

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

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

UNCOV
348
                if len(infos) == 0 {
×
UNCOV
349
                        return nil
×
UNCOV
350
                }
×
351

352
                info := infos[0]
×
353

×
354
                var policy1, policy2 *models.CachedEdgePolicy
×
355
                if info.Policy1 != nil {
×
356
                        policy1 = models.NewCachedPolicy(info.Policy1)
×
357
                }
×
358
                if info.Policy2 != nil {
×
359
                        policy2 = models.NewCachedPolicy(info.Policy2)
×
360
                }
×
361

362
                c.graphCache.AddChannel(
×
363
                        models.NewCachedEdge(info.Info), policy1, policy2,
×
364
                )
×
365
        }
366

367
        return nil
×
368
}
369

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

1✔
381
        infos, err := c.V1Store.DeleteChannelEdges(
1✔
382
                strictZombiePruning, markZombie, chanIDs...,
1✔
383
        )
1✔
384
        if err != nil {
1✔
UNCOV
385
                return err
×
UNCOV
386
        }
×
387

388
        if c.graphCache != nil {
2✔
389
                for _, info := range infos {
2✔
390
                        c.graphCache.RemoveChannel(
1✔
391
                                info.NodeKey1Bytes, info.NodeKey2Bytes,
1✔
392
                                info.ChannelID,
1✔
393
                        )
1✔
394
                }
1✔
395
        }
396

397
        return err
1✔
398
}
399

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

1✔
410
        edges, err := c.V1Store.DisconnectBlockAtHeight(height)
1✔
411
        if err != nil {
1✔
412
                return nil, err
×
413
        }
×
414

415
        if c.graphCache != nil {
2✔
416
                for _, edge := range edges {
2✔
417
                        c.graphCache.RemoveChannel(
1✔
418
                                edge.NodeKey1Bytes, edge.NodeKey2Bytes,
1✔
419
                                edge.ChannelID,
1✔
420
                        )
1✔
421
                }
1✔
422
        }
423

424
        return edges, nil
1✔
425
}
426

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

1✔
438
        edges, nodes, err := c.V1Store.PruneGraph(
1✔
439
                spentOutputs, blockHash, blockHeight,
1✔
440
        )
1✔
441
        if err != nil {
1✔
442
                return nil, err
×
443
        }
×
444

445
        if c.graphCache != nil {
2✔
446
                for _, edge := range edges {
2✔
447
                        c.graphCache.RemoveChannel(
1✔
448
                                edge.NodeKey1Bytes, edge.NodeKey2Bytes,
1✔
449
                                edge.ChannelID,
1✔
450
                        )
1✔
451
                }
1✔
452

453
                for _, node := range nodes {
2✔
454
                        c.graphCache.RemoveNode(node)
1✔
455
                }
1✔
456

457
                log.Debugf("Pruned graph, cache now has %s",
1✔
458
                        c.graphCache.Stats())
1✔
459
        }
460

461
        if len(edges) != 0 {
2✔
462
                // Notify all currently registered clients of the newly closed
1✔
463
                // channels.
1✔
464
                closeSummaries := createCloseSummaries(
1✔
465
                        blockHeight, edges...,
1✔
466
                )
1✔
467

1✔
468
                select {
1✔
469
                case c.topologyUpdate <- closeSummaries:
1✔
470
                case <-c.quit:
×
471
                        return nil, ErrChanGraphShuttingDown
×
472
                }
473
        }
474

475
        return edges, nil
1✔
476
}
477

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

488
        if c.graphCache != nil {
2✔
489
                for _, node := range nodes {
1✔
UNCOV
490
                        c.graphCache.RemoveNode(node)
×
UNCOV
491
                }
×
492
        }
493

494
        return nil
1✔
495
}
496

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

1✔
505
        unknown, knownZombies, err := c.V1Store.FilterKnownChanIDs(chansInfo)
1✔
506
        if err != nil {
1✔
507
                return nil, err
×
508
        }
×
509

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

×
UNCOV
526
                if isStillZombie {
×
UNCOV
527
                        continue
×
528
                }
529

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

546
        return unknown, nil
1✔
547
}
548

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

×
UNCOV
555
        err := c.V1Store.MarkEdgeZombie(chanID, pubKey1, pubKey2)
×
UNCOV
556
        if err != nil {
×
557
                return err
×
558
        }
×
559

UNCOV
560
        if c.graphCache != nil {
×
UNCOV
561
                c.graphCache.RemoveChannel(pubKey1, pubKey2, chanID)
×
UNCOV
562
        }
×
563

UNCOV
564
        return nil
×
565
}
566

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

1✔
577
        from, to, err := c.V1Store.UpdateEdgePolicy(ctx, edge, op...)
1✔
578
        if err != nil {
1✔
UNCOV
579
                return err
×
UNCOV
580
        }
×
581

582
        if c.graphCache != nil {
2✔
583
                c.graphCache.UpdatePolicy(
1✔
584
                        models.NewCachedPolicy(edge), from, to,
1✔
585
                )
1✔
586
        }
1✔
587

588
        select {
1✔
589
        case c.topologyUpdate <- edge:
1✔
590
        case <-c.quit:
×
591
                return ErrChanGraphShuttingDown
×
592
        }
593

594
        return nil
1✔
595
}
596

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

×
UNCOV
609
        t.Helper()
×
UNCOV
610

×
UNCOV
611
        store := NewTestDB(t)
×
UNCOV
612

×
UNCOV
613
        graph, err := NewChannelGraph(store, opts...)
×
UNCOV
614
        require.NoError(t, err)
×
UNCOV
615
        require.NoError(t, graph.Start())
×
UNCOV
616

×
UNCOV
617
        t.Cleanup(func() {
×
UNCOV
618
                require.NoError(t, graph.Stop())
×
UNCOV
619
        })
×
620

UNCOV
621
        return graph
×
622
}
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