channeldb: extract AddNodeFeatures

Preparation for efficient graph cache loading where we don't iterate
over the channels of each node in the network individually.
This commit is contained in:
Joost Jager committed 2022-01-12 19:11:54 +01:00
1 parent b8408a1484
commit aff9685a61
1 file changed
+8 -3
+8 -3
View File
@@ -205,9 +205,8 @@ func (c *GraphCache) Stats() string {
numChannels)
}
// AddNode adds a graph node, including all the (directed) channels of that
// node.
func (c *GraphCache) AddNode(tx kvdb.RTx, node GraphCacheNode) error {
// AddNodeFeatures adds a graph node and its features to the cache.
func (c *GraphCache) AddNodeFeatures(node GraphCacheNode) {
nodePubKey := node.PubKey()
// Only hold the lock for a short time. The `ForEachChannel()` below is
@@ -217,6 +216,12 @@ func (c *GraphCache) AddNode(tx kvdb.RTx, node GraphCacheNode) error {
c.mtx.Lock()
c.nodeFeatures[nodePubKey] = node.Features()
c.mtx.Unlock()
}
// AddNode adds a graph node, including all the (directed) channels of that
// node.
func (c *GraphCache) AddNode(tx kvdb.RTx, node GraphCacheNode) error {
c.AddNodeFeatures(node)
return node.ForEachChannel(
tx, func(tx kvdb.RTx, info *ChannelEdgeInfo,