From d1fa5701eb583d9aa8fba73d54b911a34d848ca5 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Tue, 17 Jun 2025 11:52:02 +0200 Subject: [PATCH] graph/db: thread context through to DeleteLightningNode --- graph/db/graph.go | 6 ++++-- graph/db/graph_test.go | 12 ++++++------ graph/db/interfaces.go | 2 +- graph/db/kv_store.go | 4 +++- graph/db/sql_store.go | 4 ++-- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/graph/db/graph.go b/graph/db/graph.go index a02e8193f..fb2a9975a 100644 --- a/graph/db/graph.go +++ b/graph/db/graph.go @@ -286,8 +286,10 @@ func (c *ChannelGraph) AddLightningNode(ctx context.Context, // DeleteLightningNode starts a new database transaction to remove a vertex/node // from the database according to the node's public key. -func (c *ChannelGraph) DeleteLightningNode(nodePub route.Vertex) error { - err := c.V1Store.DeleteLightningNode(nodePub) +func (c *ChannelGraph) DeleteLightningNode(ctx context.Context, + nodePub route.Vertex) error { + + err := c.V1Store.DeleteLightningNode(ctx, nodePub) if err != nil { return err } diff --git a/graph/db/graph_test.go b/graph/db/graph_test.go index 25409df09..a87d66bfc 100644 --- a/graph/db/graph_test.go +++ b/graph/db/graph_test.go @@ -159,13 +159,14 @@ func TestNodeInsertionAndDeletion(t *testing.T) { // Next, delete the node from the graph, this should purge all data // related to the node. - require.NoError(t, graph.DeleteLightningNode(testPub)) + require.NoError(t, graph.DeleteLightningNode(ctx, testPub)) assertNodeNotInCache(t, graph, testPub) // Attempting to delete the node again should return an error since // the node is no longer known. require.ErrorIs( - t, graph.DeleteLightningNode(testPub), ErrGraphNodeNotFound, + t, graph.DeleteLightningNode(ctx, testPub), + ErrGraphNodeNotFound, ) // Finally, attempt to fetch the node again. This should fail as the @@ -318,7 +319,7 @@ func TestPartialNode(t *testing.T) { // Next, delete the node from the graph, this should purge all data // related to the node. - require.NoError(t, graph.DeleteLightningNode(pubKey1)) + require.NoError(t, graph.DeleteLightningNode(ctx, pubKey1)) assertNodeNotInCache(t, graph, testPub) // Finally, attempt to fetch the node again. This should fail as the @@ -3416,9 +3417,8 @@ func TestNodePruningUpdateIndexDeletion(t *testing.T) { // We'll now delete the node from the graph, this should result in it // being removed from the update index as well. - if err := graph.DeleteLightningNode(node1.PubKeyBytes); err != nil { - t.Fatalf("unable to delete node: %v", err) - } + err = graph.DeleteLightningNode(ctx, node1.PubKeyBytes) + require.NoError(t, err) // Now that the node has been deleted, we'll again query the nodes in // the horizon. This time we should have no nodes at all. diff --git a/graph/db/interfaces.go b/graph/db/interfaces.go index 9f5eb6c8f..f45c663f5 100644 --- a/graph/db/interfaces.go +++ b/graph/db/interfaces.go @@ -114,7 +114,7 @@ type V1Store interface { //nolint:interfacebloat // DeleteLightningNode starts a new database transaction to remove a // vertex/node from the database according to the node's public key. - DeleteLightningNode(nodePub route.Vertex) error + DeleteLightningNode(ctx context.Context, nodePub route.Vertex) error // NodeUpdatesInHorizon returns all the known lightning node which have // an update timestamp within the passed range. This method can be used diff --git a/graph/db/kv_store.go b/graph/db/kv_store.go index be8ab2d9d..0ce190420 100644 --- a/graph/db/kv_store.go +++ b/graph/db/kv_store.go @@ -1032,7 +1032,9 @@ func (c *KVStore) LookupAlias(pub *btcec.PublicKey) (string, error) { // DeleteLightningNode starts a new database transaction to remove a vertex/node // from the database according to the node's public key. -func (c *KVStore) DeleteLightningNode(nodePub route.Vertex) error { +func (c *KVStore) DeleteLightningNode(_ context.Context, + nodePub route.Vertex) error { + // TODO(roasbeef): ensure dangling edges are removed... return kvdb.Update(c.db, func(tx kvdb.RwTx) error { nodes := tx.ReadWriteBucket(nodeBucket) diff --git a/graph/db/sql_store.go b/graph/db/sql_store.go index 1fd68a7f9..a3be9c8a6 100644 --- a/graph/db/sql_store.go +++ b/graph/db/sql_store.go @@ -291,8 +291,8 @@ func (s *SQLStore) AddrsForNode(nodePub *btcec.PublicKey) (bool, []net.Addr, // from the database according to the node's public key. // // NOTE: part of the V1Store interface. -func (s *SQLStore) DeleteLightningNode(pubKey route.Vertex) error { - ctx := context.TODO() +func (s *SQLStore) DeleteLightningNode(ctx context.Context, + pubKey route.Vertex) error { err := s.db.ExecTx(ctx, sqldb.WriteTxOpt(), func(db SQLQueries) error { res, err := db.DeleteNodeByPubKey(