Skip to content

Commit b0cba7d

Browse files
authored
Merge pull request #9804 from ellemouton/removeChanGraphCacheMu
graph/db: remove ChannelGraph cacheMu
2 parents 1db6c31 + 765fc6c commit b0cba7d

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
)
@@ -508,9 +482,6 @@ func (c *ChannelGraph) PruneGraph(spentOutputs []*wire.OutPoint,
508482
// that we only maintain a graph of reachable nodes. In the event that a pruned
509483
// node gains more channels, it will be re-added back to the graph.
510484
func (c *ChannelGraph) PruneGraphNodes() error {
511-
c.cacheMu.Lock()
512-
defer c.cacheMu.Unlock()
513-
514485
nodes, err := c.KVStore.PruneGraphNodes()
515486
if err != nil {
516487
return err
@@ -583,9 +554,6 @@ func (c *ChannelGraph) FilterKnownChanIDs(chansInfo []ChannelUpdateInfo,
583554
func (c *ChannelGraph) MarkEdgeZombie(chanID uint64,
584555
pubKey1, pubKey2 [33]byte) error {
585556

586-
c.cacheMu.Lock()
587-
defer c.cacheMu.Unlock()
588-
589557
err := c.KVStore.MarkEdgeZombie(chanID, pubKey1, pubKey2)
590558
if err != nil {
591559
return err
@@ -608,9 +576,6 @@ func (c *ChannelGraph) MarkEdgeZombie(chanID uint64,
608576
func (c *ChannelGraph) UpdateEdgePolicy(edge *models.ChannelEdgePolicy,
609577
op ...batch.SchedulerOption) error {
610578

611-
c.cacheMu.Lock()
612-
defer c.cacheMu.Unlock()
613-
614579
from, to, err := c.KVStore.UpdateEdgePolicy(edge, op...)
615580
if err != nil {
616581
return err

0 commit comments

Comments
 (0)