Skip to content

Commit 3416a13

Browse files
committed
graphdb: invalidate node cache
In this commit, we remove nodes from the node cache in various db method call site which execution could affect the public status of the nodes.
1 parent b9214d0 commit 3416a13

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

graph/db/sql_store.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,10 @@ func (s *SQLStore) DeleteNode(ctx context.Context,
423423
return fmt.Errorf("unable to delete node: %w", err)
424424
}
425425

426+
s.cacheMu.Lock()
427+
s.removePublicNodeCache(pubKey)
428+
s.cacheMu.Unlock()
429+
426430
return nil
427431
}
428432

@@ -733,6 +737,10 @@ func (s *SQLStore) AddChannelEdge(ctx context.Context,
733737
default:
734738
s.rejectCache.remove(edge.ChannelID)
735739
s.chanCache.remove(edge.ChannelID)
740+
s.removePublicNodeCache(
741+
edge.NodeKey1Bytes, edge.NodeKey2Bytes,
742+
)
743+
736744
return nil
737745
}
738746
},
@@ -1749,6 +1757,7 @@ func (s *SQLStore) MarkEdgeZombie(chanID uint64,
17491757

17501758
s.rejectCache.remove(chanID)
17511759
s.chanCache.remove(chanID)
1760+
s.removePublicNodeCache(pubKey1, pubKey2)
17521761

17531762
return nil
17541763
}
@@ -1976,6 +1985,14 @@ func (s *SQLStore) DeleteChannelEdges(strictZombiePruning, markZombie bool,
19761985
s.chanCache.remove(chanID)
19771986
}
19781987

1988+
var pubkeys [][33]byte
1989+
for _, edge := range edges {
1990+
pubkeys = append(
1991+
pubkeys, edge.NodeKey1Bytes, edge.NodeKey2Bytes,
1992+
)
1993+
}
1994+
s.removePublicNodeCache(pubkeys...)
1995+
19791996
return edges, nil
19801997
}
19811998

@@ -2704,6 +2721,9 @@ func (s *SQLStore) PruneGraph(spentOutputs []*wire.OutPoint,
27042721
for _, channel := range closedChans {
27052722
s.rejectCache.remove(channel.ChannelID)
27062723
s.chanCache.remove(channel.ChannelID)
2724+
s.removePublicNodeCache(
2725+
channel.NodeKey1Bytes, channel.NodeKey2Bytes,
2726+
)
27072727
}
27082728

27092729
return closedChans, prunedNodes, nil
@@ -2972,6 +2992,9 @@ func (s *SQLStore) DisconnectBlockAtHeight(height uint32) (
29722992
for _, channel := range removedChans {
29732993
s.rejectCache.remove(channel.ChannelID)
29742994
s.chanCache.remove(channel.ChannelID)
2995+
s.removePublicNodeCache(
2996+
channel.NodeKey1Bytes, channel.NodeKey2Bytes,
2997+
)
29752998
}
29762999
s.cacheMu.Unlock()
29773000

@@ -5918,3 +5941,13 @@ func handleZombieMarking(ctx context.Context, db SQLQueries,
59185941
},
59195942
)
59205943
}
5944+
5945+
// removePublicNodeCache takes in a list of public keys and removes the
5946+
// corresponding nodes info from the cache if it exists.
5947+
//
5948+
// NOTE: This method must be called with cacheMu held.
5949+
func (s *SQLStore) removePublicNodeCache(pubkeys ...[33]byte) {
5950+
for _, pubkey := range pubkeys {
5951+
s.publicNodeCache.Delete(pubkey)
5952+
}
5953+
}

0 commit comments

Comments
 (0)