graph/db: move some cache writes to ChannelGraph.

Here we move the cache writes for DisconnectBlockAtHeight and
DeleteChannelEdges to the ChannelGraph.
This commit is contained in:
Elle Mouton committed 2025-03-24 15:05:46 +02:00
1 parent 081c9dc082
commit 71e5ab6200
2 files changed
+71 -19

No files matched your search

+8 -19
View File
@@ -1654,14 +1654,6 @@ func (c *KVStore) DisconnectBlockAtHeight(height uint32) (
return err
}
if c.graphCache != nil {
c.graphCache.RemoveChannel(
edgeInfo.NodeKey1Bytes,
edgeInfo.NodeKey2Bytes,
edgeInfo.ChannelID,
)
}
removedChans = append(removedChans, edgeInfo)
}
@@ -1768,7 +1760,7 @@ func (c *KVStore) PruneTip() (*chainhash.Hash, uint32, error) {
// that resurrects the channel from its zombie state. The markZombie bool
// denotes whether or not to mark the channel as a zombie.
func (c *KVStore) DeleteChannelEdges(strictZombiePruning, markZombie bool,
chanIDs ...uint64) error {
chanIDs ...uint64) ([]*models.ChannelEdgeInfo, error) {
// TODO(roasbeef): possibly delete from node bucket if node has no more
// channels
@@ -1777,6 +1769,7 @@ func (c *KVStore) DeleteChannelEdges(strictZombiePruning, markZombie bool,
c.cacheMu.Lock()
defer c.cacheMu.Unlock()
var infos []*models.ChannelEdgeInfo
err := kvdb.Update(c.db, func(tx kvdb.RwTx) error {
edges := tx.ReadWriteBucket(edgeBucket)
if edges == nil {
@@ -1810,19 +1803,15 @@ func (c *KVStore) DeleteChannelEdges(strictZombiePruning, markZombie bool,
return err
}
if c.graphCache != nil {
c.graphCache.RemoveChannel(
edgeInfo.NodeKey1Bytes,
edgeInfo.NodeKey2Bytes,
edgeInfo.ChannelID,
)
}
infos = append(infos, edgeInfo)
}
return nil
}, func() {})
}, func() {
infos = nil
})
if err != nil {
return err
return nil, err
}
for _, chanID := range chanIDs {
@@ -1830,7 +1819,7 @@ func (c *KVStore) DeleteChannelEdges(strictZombiePruning, markZombie bool,
c.chanCache.remove(chanID)
}
return nil
return infos, nil
}
// ChannelID attempt to lookup the 8-byte compact channel ID which maps to the