graph/db: thread context through to FetchLightingNode
This commit is contained in:
12 files changed
+47
-39
No files matched your search
+2
-2
@@ -1265,10 +1265,10 @@ func (b *Builder) GetChannelByID(chanID lnwire.ShortChannelID) (
|
||||
// within the graph.
|
||||
//
|
||||
// NOTE: This method is part of the ChannelGraphSource interface.
|
||||
func (b *Builder) FetchLightningNode(
|
||||
func (b *Builder) FetchLightningNode(ctx context.Context,
|
||||
node route.Vertex) (*models.LightningNode, error) {
|
||||
|
||||
return b.cfg.Graph.FetchLightningNode(node)
|
||||
return b.cfg.Graph.FetchLightningNode(ctx, node)
|
||||
}
|
||||
|
||||
// ForAllOutgoingChannels is used to iterate over all outgoing channels owned by
|
||||
|
||||
+14
-13
@@ -132,7 +132,7 @@ func TestNodeInsertionAndDeletion(t *testing.T) {
|
||||
|
||||
// Next, fetch the node from the database to ensure everything was
|
||||
// serialized properly.
|
||||
dbNode, err := graph.FetchLightningNode(testPub)
|
||||
dbNode, err := graph.FetchLightningNode(ctx, testPub)
|
||||
require.NoError(t, err, "unable to locate node")
|
||||
|
||||
_, exists, err := graph.HasLightningNode(dbNode.PubKeyBytes)
|
||||
@@ -170,7 +170,7 @@ func TestNodeInsertionAndDeletion(t *testing.T) {
|
||||
|
||||
// Finally, attempt to fetch the node again. This should fail as the
|
||||
// node should have been deleted from the database.
|
||||
_, err = graph.FetchLightningNode(testPub)
|
||||
_, err = graph.FetchLightningNode(ctx, testPub)
|
||||
require.ErrorIs(t, err, ErrGraphNodeNotFound)
|
||||
|
||||
// Now, we'll specifically test the updating of addresses of a node
|
||||
@@ -192,7 +192,7 @@ func TestNodeInsertionAndDeletion(t *testing.T) {
|
||||
require.NoError(t, graph.AddLightningNode(ctx, node))
|
||||
|
||||
// Fetch the node and assert the empty addresses.
|
||||
dbNode, err = graph.FetchLightningNode(testPub)
|
||||
dbNode, err = graph.FetchLightningNode(ctx, testPub)
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, dbNode.Addresses)
|
||||
|
||||
@@ -219,7 +219,7 @@ func TestNodeInsertionAndDeletion(t *testing.T) {
|
||||
require.NoError(t, graph.AddLightningNode(ctx, node))
|
||||
|
||||
// Fetch the node and assert the updated addresses.
|
||||
dbNode, err = graph.FetchLightningNode(testPub)
|
||||
dbNode, err = graph.FetchLightningNode(ctx, testPub)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expAddrs, dbNode.Addresses)
|
||||
|
||||
@@ -240,7 +240,7 @@ func TestNodeInsertionAndDeletion(t *testing.T) {
|
||||
require.NoError(t, graph.AddLightningNode(ctx, node))
|
||||
|
||||
// Fetch the node and assert the updated addresses.
|
||||
dbNode, err = graph.FetchLightningNode(testPub)
|
||||
dbNode, err = graph.FetchLightningNode(ctx, testPub)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expAddrs, dbNode.Addresses)
|
||||
|
||||
@@ -253,7 +253,7 @@ func TestNodeInsertionAndDeletion(t *testing.T) {
|
||||
require.NoError(t, graph.AddLightningNode(ctx, node))
|
||||
|
||||
// Fetch the node and assert the updated addresses.
|
||||
dbNode, err = graph.FetchLightningNode(testPub)
|
||||
dbNode, err = graph.FetchLightningNode(ctx, testPub)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expAddrs, dbNode.Addresses)
|
||||
}
|
||||
@@ -262,6 +262,7 @@ func TestNodeInsertionAndDeletion(t *testing.T) {
|
||||
// only the pubkey is known to the database.
|
||||
func TestPartialNode(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
|
||||
graph := MakeTestGraphNew(t)
|
||||
|
||||
@@ -282,9 +283,9 @@ func TestPartialNode(t *testing.T) {
|
||||
|
||||
// Next, fetch the node2 from the database to ensure everything was
|
||||
// serialized properly.
|
||||
dbNode1, err := graph.FetchLightningNode(pubKey1)
|
||||
dbNode1, err := graph.FetchLightningNode(ctx, pubKey1)
|
||||
require.NoError(t, err)
|
||||
dbNode2, err := graph.FetchLightningNode(pubKey2)
|
||||
dbNode2, err := graph.FetchLightningNode(ctx, pubKey2)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, exists, err := graph.HasLightningNode(dbNode1.PubKeyBytes)
|
||||
@@ -322,7 +323,7 @@ func TestPartialNode(t *testing.T) {
|
||||
|
||||
// Finally, attempt to fetch the node again. This should fail as the
|
||||
// node should have been deleted from the database.
|
||||
_, err = graph.FetchLightningNode(testPub)
|
||||
_, err = graph.FetchLightningNode(ctx, testPub)
|
||||
require.ErrorIs(t, err, ErrGraphNodeNotFound)
|
||||
}
|
||||
|
||||
@@ -3338,7 +3339,7 @@ func TestPruneGraphNodes(t *testing.T) {
|
||||
|
||||
// Finally, we'll ensure that node3, the only fully unconnected node as
|
||||
// properly deleted from the graph and not another node in its place.
|
||||
_, err := graph.FetchLightningNode(node3.PubKeyBytes)
|
||||
_, err := graph.FetchLightningNode(ctx, node3.PubKeyBytes)
|
||||
require.NotNil(t, err)
|
||||
}
|
||||
|
||||
@@ -3364,11 +3365,11 @@ func TestAddChannelEdgeShellNodes(t *testing.T) {
|
||||
|
||||
// Ensure that node1 was inserted as a full node, while node2 only has
|
||||
// a shell node present.
|
||||
node1, err := graph.FetchLightningNode(node1.PubKeyBytes)
|
||||
node1, err := graph.FetchLightningNode(ctx, node1.PubKeyBytes)
|
||||
require.NoError(t, err, "unable to fetch node1")
|
||||
require.True(t, node1.HaveNodeAnnouncement)
|
||||
|
||||
node2, err = graph.FetchLightningNode(node2.PubKeyBytes)
|
||||
node2, err = graph.FetchLightningNode(ctx, node2.PubKeyBytes)
|
||||
require.NoError(t, err, "unable to fetch node2")
|
||||
require.False(t, node2.HaveNodeAnnouncement)
|
||||
|
||||
@@ -4350,7 +4351,7 @@ func TestLightningNodePersistence(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Read the node from disk.
|
||||
diskNode, err := graph.FetchLightningNode(node.PubKeyBytes)
|
||||
diskNode, err := graph.FetchLightningNode(ctx, node.PubKeyBytes)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Convert it back to a wire message.
|
||||
|
||||
@@ -126,8 +126,8 @@ type V1Store interface { //nolint:interfacebloat
|
||||
// FetchLightningNode attempts to look up a target node by its identity
|
||||
// public key. If the node isn't found in the database, then
|
||||
// ErrGraphNodeNotFound is returned.
|
||||
FetchLightningNode(nodePub route.Vertex) (
|
||||
*models.LightningNode, error)
|
||||
FetchLightningNode(ctx context.Context,
|
||||
nodePub route.Vertex) (*models.LightningNode, error)
|
||||
|
||||
// HasLightningNode determines if the graph has a vertex identified by
|
||||
// the target node identity public key. If the node exists in the
|
||||
|
||||
@@ -379,12 +379,14 @@ func initKVStore(db kvdb.Backend) error {
|
||||
func (c *KVStore) AddrsForNode(nodePub *btcec.PublicKey) (bool, []net.Addr,
|
||||
error) {
|
||||
|
||||
ctx := context.TODO()
|
||||
|
||||
pubKey, err := route.NewVertexFromBytes(nodePub.SerializeCompressed())
|
||||
if err != nil {
|
||||
return false, nil, err
|
||||
}
|
||||
|
||||
node, err := c.FetchLightningNode(pubKey)
|
||||
node, err := c.FetchLightningNode(ctx, pubKey)
|
||||
// We don't consider it an error if the graph is unaware of the node.
|
||||
switch {
|
||||
case err != nil && !errors.Is(err, ErrGraphNodeNotFound):
|
||||
@@ -2995,8 +2997,8 @@ func (c *KVStore) FetchLightningNodeTx(tx kvdb.RTx, nodePub route.Vertex) (
|
||||
// FetchLightningNode attempts to look up a target node by its identity public
|
||||
// key. If the node isn't found in the database, then ErrGraphNodeNotFound is
|
||||
// returned.
|
||||
func (c *KVStore) FetchLightningNode(nodePub route.Vertex) (
|
||||
*models.LightningNode, error) {
|
||||
func (c *KVStore) FetchLightningNode(_ context.Context,
|
||||
nodePub route.Vertex) (*models.LightningNode, error) {
|
||||
|
||||
return c.fetchLightningNode(nil, nodePub)
|
||||
}
|
||||
|
||||
@@ -193,10 +193,8 @@ func (s *SQLStore) AddLightningNode(ctx context.Context,
|
||||
// returned.
|
||||
//
|
||||
// NOTE: part of the V1Store interface.
|
||||
func (s *SQLStore) FetchLightningNode(pubKey route.Vertex) (
|
||||
*models.LightningNode, error) {
|
||||
|
||||
ctx := context.TODO()
|
||||
func (s *SQLStore) FetchLightningNode(ctx context.Context,
|
||||
pubKey route.Vertex) (*models.LightningNode, error) {
|
||||
|
||||
var node *models.LightningNode
|
||||
err := s.db.ExecTx(ctx, sqldb.ReadTxOpt(), func(db SQLQueries) error {
|
||||
|
||||
+4
-3
@@ -84,7 +84,8 @@ type ChannelGraphSource interface {
|
||||
// FetchLightningNode attempts to look up a target node by its identity
|
||||
// public key. channeldb.ErrGraphNodeNotFound is returned if the node
|
||||
// doesn't exist within the graph.
|
||||
FetchLightningNode(route.Vertex) (*models.LightningNode, error)
|
||||
FetchLightningNode(context.Context,
|
||||
route.Vertex) (*models.LightningNode, error)
|
||||
|
||||
// MarkZombieEdge marks the channel with the given ID as a zombie edge.
|
||||
MarkZombieEdge(chanID uint64) error
|
||||
@@ -242,8 +243,8 @@ type DB interface {
|
||||
// FetchLightningNode attempts to look up a target node by its identity
|
||||
// public key. If the node isn't found in the database, then
|
||||
// ErrGraphNodeNotFound is returned.
|
||||
FetchLightningNode(nodePub route.Vertex) (*models.LightningNode,
|
||||
error)
|
||||
FetchLightningNode(ctx context.Context,
|
||||
nodePub route.Vertex) (*models.LightningNode, error)
|
||||
|
||||
// ForEachNodeChannel iterates through all channels of the given node,
|
||||
// executing the passed callback with an edge info structure and the
|
||||
|
||||
Reference in new issue
Block a user