From aff9685a61e0c51d20f894976524548b4e44ecf7 Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Fri, 24 Dec 2021 11:30:13 +0100 Subject: [PATCH] channeldb: extract AddNodeFeatures Preparation for efficient graph cache loading where we don't iterate over the channels of each node in the network individually. --- channeldb/graph_cache.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/channeldb/graph_cache.go b/channeldb/graph_cache.go index 0af8fb591..2c3bc9024 100644 --- a/channeldb/graph_cache.go +++ b/channeldb/graph_cache.go @@ -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,