Skip to content

Commit 765fc6c

Browse files
committed
graph/db: remove ChannelGraph cacheMu
We remove the mutex that was previously held between DB calls and calls that update the graphCache. This is done so that the underlying DB calls can make use of any batch requests which they currently cannot since the mutex prevents multiple requests from calling the methods at once. The reason the cacheMu was originally added here was during a code refactor that moved the `graphCache` out of the `KVStore` and into the `ChannelGraph` and the aim was then to have a best effort way of ensuring that updates to the DB and updates to the graphCache were as consistent/atomic as possible.
1 parent ee25c22 commit 765fc6c

File tree

1 file changed

+0
-35
lines changed

1 file changed

+0
-35
lines changed

graph/db/graph.go

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ type ChannelGraph struct {
4141
started atomic.Bool
4242
stopped atomic.Bool
4343

44-
// cacheMu guards any writes to the graphCache. It should be held
45-
// across the DB write call and the graphCache update to make the
46-
// two updates as atomic as possible.
47-
cacheMu sync.Mutex
48-
4944
graphCache *GraphCache
5045

5146
*KVStore
@@ -283,9 +278,6 @@ func (c *ChannelGraph) ForEachNodeCached(cb func(node route.Vertex,
283278
func (c *ChannelGraph) AddLightningNode(node *models.LightningNode,
284279
op ...batch.SchedulerOption) error {
285280

286-
c.cacheMu.Lock()
287-
defer c.cacheMu.Unlock()
288-
289281
err := c.KVStore.AddLightningNode(node, op...)
290282
if err != nil {
291283
return err
@@ -309,9 +301,6 @@ func (c *ChannelGraph) AddLightningNode(node *models.LightningNode,
309301
// DeleteLightningNode starts a new database transaction to remove a vertex/node
310302
// from the database according to the node's public key.
311303
func (c *ChannelGraph) DeleteLightningNode(nodePub route.Vertex) error {
312-
c.cacheMu.Lock()
313-
defer c.cacheMu.Unlock()
314-
315304
err := c.KVStore.DeleteLightningNode(nodePub)
316305
if err != nil {
317306
return err
@@ -333,9 +322,6 @@ func (c *ChannelGraph) DeleteLightningNode(nodePub route.Vertex) error {
333322
func (c *ChannelGraph) AddChannelEdge(edge *models.ChannelEdgeInfo,
334323
op ...batch.SchedulerOption) error {
335324

336-
c.cacheMu.Lock()
337-
defer c.cacheMu.Unlock()
338-
339325
err := c.KVStore.AddChannelEdge(edge, op...)
340326
if err != nil {
341327
return err
@@ -358,9 +344,6 @@ func (c *ChannelGraph) AddChannelEdge(edge *models.ChannelEdgeInfo,
358344
// If the cache is enabled, the edge will be added back to the graph cache if
359345
// we still have a record of this channel in the DB.
360346
func (c *ChannelGraph) MarkEdgeLive(chanID uint64) error {
361-
c.cacheMu.Lock()
362-
defer c.cacheMu.Unlock()
363-
364347
err := c.KVStore.MarkEdgeLive(chanID)
365348
if err != nil {
366349
return err
@@ -397,9 +380,6 @@ func (c *ChannelGraph) MarkEdgeLive(chanID uint64) error {
397380
func (c *ChannelGraph) DeleteChannelEdges(strictZombiePruning, markZombie bool,
398381
chanIDs ...uint64) error {
399382

400-
c.cacheMu.Lock()
401-
defer c.cacheMu.Unlock()
402-
403383
infos, err := c.KVStore.DeleteChannelEdges(
404384
strictZombiePruning, markZombie, chanIDs...,
405385
)
@@ -429,9 +409,6 @@ func (c *ChannelGraph) DeleteChannelEdges(strictZombiePruning, markZombie bool,
429409
func (c *ChannelGraph) DisconnectBlockAtHeight(height uint32) (
430410
[]*models.ChannelEdgeInfo, error) {
431411

432-
c.cacheMu.Lock()
433-
defer c.cacheMu.Unlock()
434-
435412
edges, err := c.KVStore.DisconnectBlockAtHeight(height)
436413
if err != nil {
437414
return nil, err
@@ -460,9 +437,6 @@ func (c *ChannelGraph) PruneGraph(spentOutputs []*wire.OutPoint,
460437
blockHash *chainhash.Hash, blockHeight uint32) (
461438
[]*models.ChannelEdgeInfo, error) {
462439

463-
c.cacheMu.Lock()
464-
defer c.cacheMu.Unlock()
465-
466440
edges, nodes, err := c.KVStore.PruneGraph(
467441
spentOutputs, blockHash, blockHeight,
468442
)
@@ -505,9 +479,6 @@ func (c *ChannelGraph) PruneGraph(spentOutputs []*wire.OutPoint,
505479
// that we only maintain a graph of reachable nodes. In the event that a pruned
506480
// node gains more channels, it will be re-added back to the graph.
507481
func (c *ChannelGraph) PruneGraphNodes() error {
508-
c.cacheMu.Lock()
509-
defer c.cacheMu.Unlock()
510-
511482
nodes, err := c.KVStore.PruneGraphNodes()
512483
if err != nil {
513484
return err
@@ -580,9 +551,6 @@ func (c *ChannelGraph) FilterKnownChanIDs(chansInfo []ChannelUpdateInfo,
580551
func (c *ChannelGraph) MarkEdgeZombie(chanID uint64,
581552
pubKey1, pubKey2 [33]byte) error {
582553

583-
c.cacheMu.Lock()
584-
defer c.cacheMu.Unlock()
585-
586554
err := c.KVStore.MarkEdgeZombie(chanID, pubKey1, pubKey2)
587555
if err != nil {
588556
return err
@@ -605,9 +573,6 @@ func (c *ChannelGraph) MarkEdgeZombie(chanID uint64,
605573
func (c *ChannelGraph) UpdateEdgePolicy(edge *models.ChannelEdgePolicy,
606574
op ...batch.SchedulerOption) error {
607575

608-
c.cacheMu.Lock()
609-
defer c.cacheMu.Unlock()
610-
611576
from, to, err := c.KVStore.UpdateEdgePolicy(edge, op...)
612577
if err != nil {
613578
return err

0 commit comments

Comments
 (0)