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:
1 file changed
+8
-3
@@ -205,9 +205,8 @@ func (c *GraphCache) Stats() string {
|
|||||||
numChannels)
|
numChannels)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddNode adds a graph node, including all the (directed) channels of that
|
// AddNodeFeatures adds a graph node and its features to the cache.
|
||||||
// node.
|
func (c *GraphCache) AddNodeFeatures(node GraphCacheNode) {
|
||||||
func (c *GraphCache) AddNode(tx kvdb.RTx, node GraphCacheNode) error {
|
|
||||||
nodePubKey := node.PubKey()
|
nodePubKey := node.PubKey()
|
||||||
|
|
||||||
// Only hold the lock for a short time. The `ForEachChannel()` below is
|
// 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.mtx.Lock()
|
||||||
c.nodeFeatures[nodePubKey] = node.Features()
|
c.nodeFeatures[nodePubKey] = node.Features()
|
||||||
c.mtx.Unlock()
|
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(
|
return node.ForEachChannel(
|
||||||
tx, func(tx kvdb.RTx, info *ChannelEdgeInfo,
|
tx, func(tx kvdb.RTx, info *ChannelEdgeInfo,
|
||||||
|
|||||||
Reference in new issue
Block a user