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

lightningnetwork / lnd / 16918135633

12 Aug 2025 06:56PM UTC coverage: 56.955% (-9.9%) from 66.9%
16918135633

push

github

web-flow
Merge pull request #9871 from GeorgeTsagk/htlc-noop-add

Add `NoopAdd` HTLCs

48 of 147 new or added lines in 3 files covered. (32.65%)

29154 existing lines in 462 files now uncovered.

98265 of 172532 relevant lines covered (56.95%)

1.19 hits per line

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

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

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

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

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

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

35
        graphCache *GraphCache
36

37
        V1Store
38
        *topologyManager
39

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

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

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

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

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

65
        return g, nil
2✔
66
}
67

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

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

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

2✔
88
        return nil
2✔
89
}
90

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

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

2✔
100
        close(c.quit)
2✔
101
        c.wg.Wait()
2✔
102

2✔
103
        return nil
2✔
104
}
105

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

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

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

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

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

2✔
143
                                        close(client.ntfnChan)
2✔
144
                                }
2✔
145

146
                                continue
2✔
147
                        }
148

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

154
                case <-c.quit:
2✔
155
                        return
2✔
156
                }
157
        }
158
}
159

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

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

2✔
171
                c.graphCache.AddNodeFeatures(node, features)
2✔
172

2✔
173
                return nil
2✔
174
        }, func() {})
4✔
175
        if err != nil {
2✔
176
                return err
×
177
        }
×
178

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

2✔
183
                        c.graphCache.AddChannel(info, policy1, policy2)
2✔
184

2✔
185
                        return nil
2✔
186
                }, func() {},
4✔
187
        )
188
        if err != nil {
2✔
189
                return err
×
190
        }
×
191

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

2✔
195
        return nil
2✔
196
}
197

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

2✔
211
        if c.graphCache != nil {
4✔
212
                return c.graphCache.ForEachChannel(node, cb)
2✔
213
        }
2✔
214

215
        return c.V1Store.ForEachNodeDirectedChannel(node, cb, reset)
2✔
216
}
217

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

2✔
227
        if c.graphCache != nil {
4✔
228
                return c.graphCache.GetFeatures(node), nil
2✔
229
        }
2✔
230

231
        return c.V1Store.FetchNodeFeatures(node)
2✔
232
}
233

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

2✔
241
        if c.graphCache != nil {
4✔
242
                return cb(c)
2✔
243
        }
2✔
244

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

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

×
UNCOV
256
        if !withAddrs && c.graphCache != nil {
×
257
                return c.graphCache.ForEachNode(
×
258
                        func(node route.Vertex,
×
259
                                channels map[uint64]*DirectedChannel) error {
×
260

×
261
                                return cb(ctx, node, nil, channels)
×
262
                        },
×
263
                )
264
        }
265

UNCOV
266
        return c.V1Store.ForEachNodeCached(ctx, withAddrs, cb, reset)
×
267
}
268

269
// AddLightningNode adds a vertex/node to the graph database. If the node is not
270
// in the database from before, this will add a new, unconnected one to the
271
// graph. If it is present from before, this will update that node's
272
// information. Note that this method is expected to only be called to update an
273
// already present node from a node announcement, or to insert a node found in a
274
// channel update.
275
func (c *ChannelGraph) AddLightningNode(ctx context.Context,
276
        node *models.LightningNode, op ...batch.SchedulerOption) error {
2✔
277

2✔
278
        err := c.V1Store.AddLightningNode(ctx, node, op...)
2✔
279
        if err != nil {
2✔
280
                return err
×
281
        }
×
282

283
        if c.graphCache != nil {
4✔
284
                c.graphCache.AddNodeFeatures(
2✔
285
                        node.PubKeyBytes, node.Features,
2✔
286
                )
2✔
287
        }
2✔
288

289
        select {
2✔
290
        case c.topologyUpdate <- node:
2✔
291
        case <-c.quit:
×
292
                return ErrChanGraphShuttingDown
×
293
        }
294

295
        return nil
2✔
296
}
297

298
// DeleteLightningNode starts a new database transaction to remove a vertex/node
299
// from the database according to the node's public key.
300
func (c *ChannelGraph) DeleteLightningNode(ctx context.Context,
UNCOV
301
        nodePub route.Vertex) error {
×
UNCOV
302

×
UNCOV
303
        err := c.V1Store.DeleteLightningNode(ctx, nodePub)
×
UNCOV
304
        if err != nil {
×
UNCOV
305
                return err
×
UNCOV
306
        }
×
307

UNCOV
308
        if c.graphCache != nil {
×
UNCOV
309
                c.graphCache.RemoveNode(nodePub)
×
UNCOV
310
        }
×
311

UNCOV
312
        return nil
×
313
}
314

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

2✔
324
        err := c.V1Store.AddChannelEdge(ctx, edge, op...)
2✔
325
        if err != nil {
2✔
UNCOV
326
                return err
×
UNCOV
327
        }
×
328

329
        if c.graphCache != nil {
4✔
330
                c.graphCache.AddChannel(models.NewCachedEdge(edge), nil, nil)
2✔
331
        }
2✔
332

333
        select {
2✔
334
        case c.topologyUpdate <- edge:
2✔
335
        case <-c.quit:
×
336
                return ErrChanGraphShuttingDown
×
337
        }
338

339
        return nil
2✔
340
}
341

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

UNCOV
351
        if c.graphCache != nil {
×
UNCOV
352
                // We need to add the channel back into our graph cache,
×
UNCOV
353
                // otherwise we won't use it for path finding.
×
UNCOV
354
                infos, err := c.V1Store.FetchChanInfos([]uint64{chanID})
×
UNCOV
355
                if err != nil {
×
356
                        return err
×
357
                }
×
358

UNCOV
359
                if len(infos) == 0 {
×
UNCOV
360
                        return nil
×
UNCOV
361
                }
×
362

363
                info := infos[0]
×
364

×
365
                var policy1, policy2 *models.CachedEdgePolicy
×
366
                if info.Policy1 != nil {
×
367
                        policy1 = models.NewCachedPolicy(info.Policy1)
×
368
                }
×
369
                if info.Policy2 != nil {
×
370
                        policy2 = models.NewCachedPolicy(info.Policy2)
×
371
                }
×
372

373
                c.graphCache.AddChannel(
×
374
                        models.NewCachedEdge(info.Info), policy1, policy2,
×
375
                )
×
376
        }
377

378
        return nil
×
379
}
380

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

2✔
392
        infos, err := c.V1Store.DeleteChannelEdges(
2✔
393
                strictZombiePruning, markZombie, chanIDs...,
2✔
394
        )
2✔
395
        if err != nil {
2✔
UNCOV
396
                return err
×
UNCOV
397
        }
×
398

399
        if c.graphCache != nil {
4✔
400
                for _, info := range infos {
4✔
401
                        c.graphCache.RemoveChannel(
2✔
402
                                info.NodeKey1Bytes, info.NodeKey2Bytes,
2✔
403
                                info.ChannelID,
2✔
404
                        )
2✔
405
                }
2✔
406
        }
407

408
        return err
2✔
409
}
410

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

2✔
421
        edges, err := c.V1Store.DisconnectBlockAtHeight(height)
2✔
422
        if err != nil {
2✔
423
                return nil, err
×
424
        }
×
425

426
        if c.graphCache != nil {
4✔
427
                for _, edge := range edges {
3✔
428
                        c.graphCache.RemoveChannel(
1✔
429
                                edge.NodeKey1Bytes, edge.NodeKey2Bytes,
1✔
430
                                edge.ChannelID,
1✔
431
                        )
1✔
432
                }
1✔
433
        }
434

435
        return edges, nil
2✔
436
}
437

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

2✔
449
        edges, nodes, err := c.V1Store.PruneGraph(
2✔
450
                spentOutputs, blockHash, blockHeight,
2✔
451
        )
2✔
452
        if err != nil {
2✔
453
                return nil, err
×
454
        }
×
455

456
        if c.graphCache != nil {
4✔
457
                for _, edge := range edges {
4✔
458
                        c.graphCache.RemoveChannel(
2✔
459
                                edge.NodeKey1Bytes, edge.NodeKey2Bytes,
2✔
460
                                edge.ChannelID,
2✔
461
                        )
2✔
462
                }
2✔
463

464
                for _, node := range nodes {
4✔
465
                        c.graphCache.RemoveNode(node)
2✔
466
                }
2✔
467

468
                log.Debugf("Pruned graph, cache now has %s",
2✔
469
                        c.graphCache.Stats())
2✔
470
        }
471

472
        if len(edges) != 0 {
4✔
473
                // Notify all currently registered clients of the newly closed
2✔
474
                // channels.
2✔
475
                closeSummaries := createCloseSummaries(
2✔
476
                        blockHeight, edges...,
2✔
477
                )
2✔
478

2✔
479
                select {
2✔
480
                case c.topologyUpdate <- closeSummaries:
2✔
481
                case <-c.quit:
×
482
                        return nil, ErrChanGraphShuttingDown
×
483
                }
484
        }
485

486
        return edges, nil
2✔
487
}
488

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

499
        if c.graphCache != nil {
4✔
500
                for _, node := range nodes {
2✔
UNCOV
501
                        c.graphCache.RemoveNode(node)
×
UNCOV
502
                }
×
503
        }
504

505
        return nil
2✔
506
}
507

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

2✔
516
        unknown, knownZombies, err := c.V1Store.FilterKnownChanIDs(chansInfo)
2✔
517
        if err != nil {
2✔
518
                return nil, err
×
519
        }
×
520

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

×
UNCOV
537
                if isStillZombie {
×
UNCOV
538
                        continue
×
539
                }
540

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

557
        return unknown, nil
2✔
558
}
559

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

×
UNCOV
566
        err := c.V1Store.MarkEdgeZombie(chanID, pubKey1, pubKey2)
×
UNCOV
567
        if err != nil {
×
568
                return err
×
569
        }
×
570

UNCOV
571
        if c.graphCache != nil {
×
UNCOV
572
                c.graphCache.RemoveChannel(pubKey1, pubKey2, chanID)
×
UNCOV
573
        }
×
574

UNCOV
575
        return nil
×
576
}
577

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

2✔
588
        from, to, err := c.V1Store.UpdateEdgePolicy(ctx, edge, op...)
2✔
589
        if err != nil {
2✔
UNCOV
590
                return err
×
UNCOV
591
        }
×
592

593
        if c.graphCache != nil {
4✔
594
                c.graphCache.UpdatePolicy(
2✔
595
                        models.NewCachedPolicy(edge), from, to,
2✔
596
                )
2✔
597
        }
2✔
598

599
        select {
2✔
600
        case c.topologyUpdate <- edge:
2✔
601
        case <-c.quit:
×
602
                return ErrChanGraphShuttingDown
×
603
        }
604

605
        return nil
2✔
606
}
607

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

×
UNCOV
620
        t.Helper()
×
UNCOV
621

×
UNCOV
622
        store := NewTestDB(t)
×
UNCOV
623

×
UNCOV
624
        graph, err := NewChannelGraph(store, opts...)
×
UNCOV
625
        require.NoError(t, err)
×
UNCOV
626
        require.NoError(t, graph.Start())
×
UNCOV
627

×
UNCOV
628
        t.Cleanup(func() {
×
UNCOV
629
                require.NoError(t, graph.Stop())
×
UNCOV
630
        })
×
631

UNCOV
632
        return graph
×
633
}
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