graph/db: version reject cache for policies

Make the reject cache version-aware so v1 and v2 policy state can be
cached independently per channel ID.  Add helpers to store v1 timestamps
or v2 block heights and thread the versioned cache key through KV/SQL
store cache accesses.
This commit is contained in:
Elle Mouton committed 2026-02-13 07:21:24 +02:00
1 parent 40e3ac964f
commit 4a6213c35e
4 files changed
+141 -49

No files matched your search

+11 -11
View File
@@ -1179,7 +1179,7 @@ func (c *KVStore) AddChannelEdge(ctx context.Context,
case alreadyExists:
return ErrEdgeAlreadyExist
default:
c.rejectCache.remove(edge.ChannelID)
c.rejectCache.remove(lnwire.GossipVersion1, edge.ChannelID)
c.chanCache.remove(edge.ChannelID)
return nil
}
@@ -1302,7 +1302,7 @@ func (c *KVStore) HasChannelEdge(
// We'll query the cache with the shared lock held to allow multiple
// readers to access values in the cache concurrently if they exist.
c.cacheMu.RLock()
if entry, ok := c.rejectCache.get(chanID); ok {
if entry, ok := c.rejectCache.get(lnwire.GossipVersion1, chanID); ok {
c.cacheMu.RUnlock()
upd1Time = time.Unix(entry.upd1Time, 0)
upd2Time = time.Unix(entry.upd2Time, 0)
@@ -1318,7 +1318,7 @@ func (c *KVStore) HasChannelEdge(
// The item was not found with the shared lock, so we'll acquire the
// exclusive lock and check the cache again in case another method added
// the entry to the cache while no lock was held.
if entry, ok := c.rejectCache.get(chanID); ok {
if entry, ok := c.rejectCache.get(lnwire.GossipVersion1, chanID); ok {
upd1Time = time.Unix(entry.upd1Time, 0)
upd2Time = time.Unix(entry.upd2Time, 0)
exists, isZombie = entry.flags.unpack()
@@ -1385,7 +1385,7 @@ func (c *KVStore) HasChannelEdge(
return time.Time{}, time.Time{}, exists, isZombie, err
}
c.rejectCache.insert(chanID, rejectCacheEntry{
c.rejectCache.insert(lnwire.GossipVersion1, chanID, rejectCacheEntry{
upd1Time: upd1Time.Unix(),
upd2Time: upd2Time.Unix(),
flags: packRejectFlags(exists, isZombie),
@@ -1564,7 +1564,7 @@ func (c *KVStore) PruneGraph(spentOutputs []*wire.OutPoint,
}
for _, channel := range chansClosed {
c.rejectCache.remove(channel.ChannelID)
c.rejectCache.remove(lnwire.GossipVersion1, channel.ChannelID)
c.chanCache.remove(channel.ChannelID)
}
@@ -1831,7 +1831,7 @@ func (c *KVStore) DisconnectBlockAtHeight(height uint32) (
}
for _, channel := range removedChans {
c.rejectCache.remove(channel.ChannelID)
c.rejectCache.remove(lnwire.GossipVersion1, channel.ChannelID)
c.chanCache.remove(channel.ChannelID)
}
@@ -1950,7 +1950,7 @@ func (c *KVStore) DeleteChannelEdges(v lnwire.GossipVersion,
}
for _, chanID := range chanIDs {
c.rejectCache.remove(chanID)
c.rejectCache.remove(lnwire.GossipVersion1, chanID)
c.chanCache.remove(chanID)
}
@@ -3265,13 +3265,13 @@ func (c *KVStore) updateEdgeCache(e *models.ChannelEdgePolicy,
// the entry with the updated timestamp for the direction that was just
// written. If the edge doesn't exist, we'll load the cache entry lazily
// during the next query for this edge.
if entry, ok := c.rejectCache.get(e.ChannelID); ok {
if entry, ok := c.rejectCache.get(lnwire.GossipVersion1, e.ChannelID); ok {
if isUpdate1 {
entry.upd1Time = e.LastUpdate.Unix()
} else {
entry.upd2Time = e.LastUpdate.Unix()
}
c.rejectCache.insert(e.ChannelID, entry)
c.rejectCache.insert(lnwire.GossipVersion1, e.ChannelID, entry)
}
// If an entry for this channel is found in channel cache, we'll modify
@@ -4185,7 +4185,7 @@ func (c *KVStore) MarkEdgeZombie(chanID uint64,
return err
}
c.rejectCache.remove(chanID)
c.rejectCache.remove(lnwire.GossipVersion1, chanID)
c.chanCache.remove(chanID)
return nil
@@ -4254,7 +4254,7 @@ func (c *KVStore) markEdgeLiveUnsafe(tx kvdb.RwTx, chanID uint64) error {
return err
}
c.rejectCache.remove(chanID)
c.rejectCache.remove(lnwire.GossipVersion1, chanID)
c.chanCache.remove(chanID)
return nil