graph/db: thread context to AddLightningNode

This commit is contained in:
Elle Mouton committed 2025-06-17 19:20:27 +02:00
1 parent c1740c14ba
commit d1cfb47428
15 files changed
+126 -81

No files matched your search

+7 -2
View File
@@ -2,6 +2,7 @@ package routing
import (
"bytes"
"context"
"crypto/sha256"
"encoding/hex"
"encoding/json"
@@ -181,6 +182,8 @@ func makeTestGraph(t *testing.T, useCache bool) (*graphdb.ChannelGraph,
func parseTestGraph(t *testing.T, useCache bool, path string) (
*testGraphInstance, error) {
ctx := context.Background()
graphJSON, err := os.ReadFile(path)
if err != nil {
return nil, err
@@ -290,7 +293,7 @@ func parseTestGraph(t *testing.T, useCache bool, path string) (
// With the node fully parsed, add it as a vertex within the
// graph.
if err := graph.AddLightningNode(dbNode); err != nil {
if err := graph.AddLightningNode(ctx, dbNode); err != nil {
return nil, err
}
}
@@ -515,6 +518,8 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
testChannels []*testChannel, source string,
sourceFeatureBits ...lnwire.FeatureBit) (*testGraphInstance, error) {
ctx := context.Background()
// We'll use this fake address for the IP address of all the nodes in
// our tests. This value isn't needed for path finding so it doesn't
// need to be unique.
@@ -566,7 +571,7 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
// With the node fully parsed, add it as a vertex within the
// graph.
if err := graph.AddLightningNode(dbNode); err != nil {
if err := graph.AddLightningNode(ctx, dbNode); err != nil {
return nil, err
}
+4 -2
View File
@@ -2,6 +2,7 @@ package routing
import (
"bytes"
"context"
"fmt"
"image/color"
"math"
@@ -2706,6 +2707,7 @@ func TestNewRouteRequest(t *testing.T) {
// announcements for the channel vertexes to be able to use the channel.
func TestAddEdgeUnknownVertexes(t *testing.T) {
t.Parallel()
ctxb := context.Background()
const startingBlockHeight = 101
ctx := createTestCtxFromFile(t, startingBlockHeight, basicGraphFilePath)
@@ -2879,7 +2881,7 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
}
copy(n1.PubKeyBytes[:], priv1.PubKey().SerializeCompressed())
require.NoError(t, ctx.graph.AddLightningNode(n1))
require.NoError(t, ctx.graph.AddLightningNode(ctxb, n1))
n2 := &models.LightningNode{
HaveNodeAnnouncement: true,
@@ -2892,7 +2894,7 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
}
copy(n2.PubKeyBytes[:], priv2.PubKey().SerializeCompressed())
require.NoError(t, ctx.graph.AddLightningNode(n2))
require.NoError(t, ctx.graph.AddLightningNode(ctxb, n2))
// Should still be able to find the route, and the info should be
// updated.