@@ -435,6 +435,10 @@ func (s *SQLStore) DeleteNode(ctx context.Context,
435435 return fmt .Errorf ("unable to delete node: %w" , err )
436436 }
437437
438+ s .cacheMu .Lock ()
439+ s .removePublicNodeCache (pubKey )
440+ s .cacheMu .Unlock ()
441+
438442 return nil
439443}
440444
@@ -734,6 +738,10 @@ func (s *SQLStore) AddChannelEdge(ctx context.Context,
734738 default :
735739 s .rejectCache .remove (edge .ChannelID )
736740 s .chanCache .remove (edge .ChannelID )
741+ s .removePublicNodeCache (
742+ edge .NodeKey1Bytes , edge .NodeKey2Bytes ,
743+ )
744+
737745 return nil
738746 }
739747 },
@@ -1740,6 +1748,7 @@ func (s *SQLStore) MarkEdgeZombie(chanID uint64,
17401748
17411749 s .rejectCache .remove (chanID )
17421750 s .chanCache .remove (chanID )
1751+ s .removePublicNodeCache (pubKey1 , pubKey2 )
17431752
17441753 return nil
17451754}
@@ -1965,6 +1974,14 @@ func (s *SQLStore) DeleteChannelEdges(strictZombiePruning, markZombie bool,
19651974 s .chanCache .remove (chanID )
19661975 }
19671976
1977+ var pubkeys [][33 ]byte
1978+ for _ , edge := range edges {
1979+ pubkeys = append (
1980+ pubkeys , edge .NodeKey1Bytes , edge .NodeKey2Bytes ,
1981+ )
1982+ }
1983+ s .removePublicNodeCache (pubkeys ... )
1984+
19681985 return edges , nil
19691986}
19701987
@@ -2694,6 +2711,9 @@ func (s *SQLStore) PruneGraph(spentOutputs []*wire.OutPoint,
26942711 for _ , channel := range closedChans {
26952712 s .rejectCache .remove (channel .ChannelID )
26962713 s .chanCache .remove (channel .ChannelID )
2714+ s .removePublicNodeCache (
2715+ channel .NodeKey1Bytes , channel .NodeKey2Bytes ,
2716+ )
26972717 }
26982718
26992719 return closedChans , prunedNodes , nil
@@ -2958,9 +2978,15 @@ func (s *SQLStore) DisconnectBlockAtHeight(height uint32) (
29582978 "height: %w" , err )
29592979 }
29602980
2981+ s .cacheMu .Lock ()
2982+ defer s .cacheMu .Unlock ()
2983+
29612984 for _ , channel := range removedChans {
29622985 s .rejectCache .remove (channel .ChannelID )
29632986 s .chanCache .remove (channel .ChannelID )
2987+ s .removePublicNodeCache (
2988+ channel .NodeKey1Bytes , channel .NodeKey2Bytes ,
2989+ )
29642990 }
29652991
29662992 return removedChans , nil
@@ -5783,3 +5809,13 @@ func handleZombieMarking(ctx context.Context, db SQLQueries,
57835809 },
57845810 )
57855811}
5812+
5813+ // removePublicNodeCache takes in a list of public keys and removes the
5814+ // corresponding nodes info from the cache if it exists.
5815+ //
5816+ // NOTE: This method must be called with cacheMu held.
5817+ func (s * SQLStore ) removePublicNodeCache (pubkeys ... [33 ]byte ) {
5818+ for _ , pubkey := range pubkeys {
5819+ s .publicNodeCache .Delete (pubkey )
5820+ }
5821+ }
0 commit comments