graph/db: move various cache write calls to ChannelGraph

Here, we move the graph cache writes for AddLightningNode,
DeleteLightningNode, AddChannelEdge and MarkEdgeLive to the
ChannelGraph. Since these are writes, the cache is only updated if the
DB write is successful.
This commit is contained in:
Elle Mouton committed 2025-03-24 15:05:46 +02:00
1 parent 9fe9e32c6e
commit f75e6a1c10
3 files changed
+107 -30

No files matched your search

-30
View File
@@ -884,12 +884,6 @@ func (c *KVStore) AddLightningNode(node *models.LightningNode,
r := &batch.Request{
Update: func(tx kvdb.RwTx) error {
if c.graphCache != nil {
c.graphCache.AddNodeFeatures(
node.PubKeyBytes, node.Features,
)
}
return addLightningNode(tx, node)
},
}
@@ -969,10 +963,6 @@ func (c *KVStore) DeleteLightningNode(nodePub route.Vertex) error {
return ErrGraphNodeNotFound
}
if c.graphCache != nil {
c.graphCache.RemoveNode(nodePub)
}
return c.deleteLightningNode(nodes, nodePub[:])
}, func() {})
}
@@ -1104,10 +1094,6 @@ func (c *KVStore) addChannelEdge(tx kvdb.RwTx,
return ErrEdgeAlreadyExist
}
if c.graphCache != nil {
c.graphCache.AddChannel(edge, nil, nil)
}
// Before we insert the channel into the database, we'll ensure that
// both nodes already exist in the channel graph. If either node
// doesn't, then we'll insert a "shell" node that just includes its
@@ -3717,22 +3703,6 @@ func (c *KVStore) markEdgeLiveUnsafe(tx kvdb.RwTx, chanID uint64) error {
c.rejectCache.remove(chanID)
c.chanCache.remove(chanID)
// We need to add the channel back into our graph cache, otherwise we
// won't use it for path finding.
if c.graphCache != nil {
edgeInfos, err := c.fetchChanInfos(tx, []uint64{chanID})
if err != nil {
return err
}
for _, edgeInfo := range edgeInfos {
c.graphCache.AddChannel(
edgeInfo.Info, edgeInfo.Policy1,
edgeInfo.Policy2,
)
}
}
return nil
}