Skip to content

Commit bdced12

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 ca7f649 commit bdced12

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

graph/db/sql_store.go

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

426+
s.removePublicNodeCache(pubKey)
427+
426428
return nil
427429
}
428430

@@ -733,6 +735,10 @@ func (s *SQLStore) AddChannelEdge(ctx context.Context,
733735
default:
734736
s.rejectCache.remove(edge.ChannelID)
735737
s.chanCache.remove(edge.ChannelID)
738+
s.removePublicNodeCache(
739+
edge.NodeKey1Bytes, edge.NodeKey2Bytes,
740+
)
741+
736742
return nil
737743
}
738744
},
@@ -1749,6 +1755,7 @@ func (s *SQLStore) MarkEdgeZombie(chanID uint64,
17491755

17501756
s.rejectCache.remove(chanID)
17511757
s.chanCache.remove(chanID)
1758+
s.removePublicNodeCache(pubKey1, pubKey2)
17521759

17531760
return nil
17541761
}
@@ -1976,6 +1983,14 @@ func (s *SQLStore) DeleteChannelEdges(strictZombiePruning, markZombie bool,
19761983
s.chanCache.remove(chanID)
19771984
}
19781985

1986+
var pubkeys [][33]byte
1987+
for _, edge := range edges {
1988+
pubkeys = append(
1989+
pubkeys, edge.NodeKey1Bytes, edge.NodeKey2Bytes,
1990+
)
1991+
}
1992+
s.removePublicNodeCache(pubkeys...)
1993+
19791994
return edges, nil
19801995
}
19811996

@@ -2693,6 +2708,9 @@ func (s *SQLStore) PruneGraph(spentOutputs []*wire.OutPoint,
26932708
for _, channel := range closedChans {
26942709
s.rejectCache.remove(channel.ChannelID)
26952710
s.chanCache.remove(channel.ChannelID)
2711+
s.removePublicNodeCache(
2712+
channel.NodeKey1Bytes, channel.NodeKey2Bytes,
2713+
)
26962714
}
26972715

26982716
return closedChans, prunedNodes, nil
@@ -2961,6 +2979,9 @@ func (s *SQLStore) DisconnectBlockAtHeight(height uint32) (
29612979
for _, channel := range removedChans {
29622980
s.rejectCache.remove(channel.ChannelID)
29632981
s.chanCache.remove(channel.ChannelID)
2982+
s.removePublicNodeCache(
2983+
channel.NodeKey1Bytes, channel.NodeKey2Bytes,
2984+
)
29642985
}
29652986
s.cacheMu.Unlock()
29662987

@@ -5907,3 +5928,14 @@ func handleZombieMarking(ctx context.Context, db SQLQueries,
59075928
},
59085929
)
59095930
}
5931+
5932+
// removePublicNodeCache takes in a list of public keys and removes the
5933+
// corresponding nodes info from the cache if it exists.
5934+
//
5935+
// NOTE: This can safely be called without holding a lock since the lru is
5936+
// thread safe.
5937+
func (s *SQLStore) removePublicNodeCache(pubkeys ...[33]byte) {
5938+
for _, pubkey := range pubkeys {
5939+
s.publicNodeCache.Delete(pubkey)
5940+
}
5941+
}

0 commit comments

Comments
 (0)