channeldb: fix graph cache feature handling [skip ci]

Fixes #5830.
When a channel for a node is announced before the node itself is
announced on the network, it's possible that we have channels for a node
but no features defined yet. This was previously logged as a warning
which spammed the log unnecessarily.
This commit is contained in:
Oliver Gugger committed 2021-10-08 10:02:11 +02:00
1 parent ccc03931ad
commit 77bf6cfed3
2 files changed
+10 -5

No files matched your search

+2 -1
View File
@@ -376,7 +376,8 @@ func (c *ChannelGraph) ForEachNodeChannel(node route.Vertex,
return c.graphCache.ForEachChannel(node, cb) return c.graphCache.ForEachChannel(node, cb)
} }
// FetchNodeFeatures returns the features of a given node. // FetchNodeFeatures returns the features of a given node. If no features are
// known for the node, an empty feature vector is returned.
func (c *ChannelGraph) FetchNodeFeatures( func (c *ChannelGraph) FetchNodeFeatures(
node route.Vertex) (*lnwire.FeatureVector, error) { node route.Vertex) (*lnwire.FeatureVector, error) {
+8 -4
View File
@@ -415,9 +415,12 @@ func (c *GraphCache) ForEachChannel(node route.Vertex,
features, ok := c.nodeFeatures[node] features, ok := c.nodeFeatures[node]
if !ok { if !ok {
log.Warnf("Node %v has no features defined, falling back to "+ // If the features were set to nil explicitly, that's fine here.
"default feature vector for path finding", node) // The router will overwrite the features of the destination
// node with those found in the invoice if necessary. But if we
// didn't yet get a node announcement we want to mimic the
// behavior of the old DB based code that would always set an
// empty feature vector instead of leaving it nil.
features = lnwire.EmptyFeatureVector() features = lnwire.EmptyFeatureVector()
} }
@@ -444,7 +447,8 @@ func (c *GraphCache) ForEachChannel(node route.Vertex,
return nil return nil
} }
// GetFeatures returns the features of the node with the given ID. // GetFeatures returns the features of the node with the given ID. If no
// features are known for the node, an empty feature vector is returned.
func (c *GraphCache) GetFeatures(node route.Vertex) *lnwire.FeatureVector { func (c *GraphCache) GetFeatures(node route.Vertex) *lnwire.FeatureVector {
c.mtx.RLock() c.mtx.RLock()
defer c.mtx.RUnlock() defer c.mtx.RUnlock()