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 2021-12-24 11:30:13 +01:00
parent b8408a1484
commit aff9685a61
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7

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,