Merge pull request #5922 from Roasbeef/graph-cache-panic-fix
channeldb: fix crash when inbound policy is unset
This commit is contained in:
4 files changed
+51
-3
No files matched your search
+6
-3
@@ -405,9 +405,12 @@ func (c *ChannelGraph) ForEachNodeChannel(tx kvdb.RTx, node route.Vertex,
|
|||||||
dbCallback := func(tx kvdb.RTx, e *ChannelEdgeInfo, p1,
|
dbCallback := func(tx kvdb.RTx, e *ChannelEdgeInfo, p1,
|
||||||
p2 *ChannelEdgePolicy) error {
|
p2 *ChannelEdgePolicy) error {
|
||||||
|
|
||||||
cachedInPolicy := NewCachedPolicy(p2)
|
var cachedInPolicy *CachedEdgePolicy
|
||||||
cachedInPolicy.ToNodePubKey = toNodeCallback
|
if p2 != nil {
|
||||||
cachedInPolicy.ToNodeFeatures = toNodeFeatures
|
cachedInPolicy = NewCachedPolicy(p2)
|
||||||
|
cachedInPolicy.ToNodePubKey = toNodeCallback
|
||||||
|
cachedInPolicy.ToNodeFeatures = toNodeFeatures
|
||||||
|
}
|
||||||
|
|
||||||
directedChannel := &DirectedChannel{
|
directedChannel := &DirectedChannel{
|
||||||
ChannelID: e.ChannelID,
|
ChannelID: e.ChannelID,
|
||||||
|
|||||||
@@ -60,6 +60,8 @@ func (n *node) ForEachChannel(tx kvdb.RTx,
|
|||||||
// TestGraphCacheAddNode tests that a channel going from node A to node B can be
|
// TestGraphCacheAddNode tests that a channel going from node A to node B can be
|
||||||
// cached correctly, independent of the direction we add the channel as.
|
// cached correctly, independent of the direction we add the channel as.
|
||||||
func TestGraphCacheAddNode(t *testing.T) {
|
func TestGraphCacheAddNode(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
runTest := func(nodeA, nodeB route.Vertex) {
|
runTest := func(nodeA, nodeB route.Vertex) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
|
|||||||
@@ -3692,3 +3692,43 @@ func BenchmarkForEachChannel(b *testing.B) {
|
|||||||
require.NoError(b, err)
|
require.NoError(b, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestGraphCacheForEachNodeChannel tests that the ForEachNodeChannel method
|
||||||
|
// works as expected, and is able to handle nil self edges.
|
||||||
|
func TestGraphCacheForEachNodeChannel(t *testing.T) {
|
||||||
|
graph, cleanUp, err := MakeTestGraph()
|
||||||
|
defer cleanUp()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Unset the channel graph cache to simulate the user running with the
|
||||||
|
// option turned off.
|
||||||
|
graph.graphCache = nil
|
||||||
|
|
||||||
|
node1, err := createTestVertex(graph.db)
|
||||||
|
require.Nil(t, err)
|
||||||
|
err = graph.AddLightningNode(node1)
|
||||||
|
require.Nil(t, err)
|
||||||
|
node2, err := createTestVertex(graph.db)
|
||||||
|
require.Nil(t, err)
|
||||||
|
err = graph.AddLightningNode(node2)
|
||||||
|
require.Nil(t, err)
|
||||||
|
|
||||||
|
// Create an edge and add it to the db.
|
||||||
|
edgeInfo, _, _ := createChannelEdge(graph.db, node1, node2)
|
||||||
|
|
||||||
|
// Add the channel, but only insert a single edge into the graph.
|
||||||
|
require.NoError(t, graph.AddChannelEdge(edgeInfo))
|
||||||
|
|
||||||
|
// We should be able to accumulate the single channel added, even
|
||||||
|
// though we have a nil edge policy here.
|
||||||
|
var numChans int
|
||||||
|
err = graph.ForEachNodeChannel(nil, node1.PubKeyBytes,
|
||||||
|
func(channel *DirectedChannel) error {
|
||||||
|
|
||||||
|
numChans++
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
require.Equal(t, numChans, 1)
|
||||||
|
}
|
||||||
@@ -595,6 +595,9 @@ messages directly. There is no routing/path finding involved.
|
|||||||
* [Don't print bucket names with special characters when compacting](
|
* [Don't print bucket names with special characters when compacting](
|
||||||
https://github.com/lightningnetwork/lnd/pull/5878)
|
https://github.com/lightningnetwork/lnd/pull/5878)
|
||||||
|
|
||||||
|
* [Fix pathfinding crash when inbound policy is unknown](
|
||||||
|
https://github.com/lightningnetwork/lnd/pull/5922)
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
The [code contribution guidelines have been updated to mention the new
|
The [code contribution guidelines have been updated to mention the new
|
||||||
|
|||||||
Reference in new issue
Block a user