Skip to content

Commit d1fa570

Browse files
committed
graph/db: thread context through to DeleteLightningNode
1 parent dc6259f commit d1fa570

File tree

5 files changed

+16
-12
lines changed

5 files changed

+16
-12
lines changed

graph/db/graph.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,10 @@ func (c *ChannelGraph) AddLightningNode(ctx context.Context,
286286

287287
// DeleteLightningNode starts a new database transaction to remove a vertex/node
288288
// from the database according to the node's public key.
289-
func (c *ChannelGraph) DeleteLightningNode(nodePub route.Vertex) error {
290-
err := c.V1Store.DeleteLightningNode(nodePub)
289+
func (c *ChannelGraph) DeleteLightningNode(ctx context.Context,
290+
nodePub route.Vertex) error {
291+
292+
err := c.V1Store.DeleteLightningNode(ctx, nodePub)
291293
if err != nil {
292294
return err
293295
}

graph/db/graph_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,14 @@ func TestNodeInsertionAndDeletion(t *testing.T) {
159159

160160
// Next, delete the node from the graph, this should purge all data
161161
// related to the node.
162-
require.NoError(t, graph.DeleteLightningNode(testPub))
162+
require.NoError(t, graph.DeleteLightningNode(ctx, testPub))
163163
assertNodeNotInCache(t, graph, testPub)
164164

165165
// Attempting to delete the node again should return an error since
166166
// the node is no longer known.
167167
require.ErrorIs(
168-
t, graph.DeleteLightningNode(testPub), ErrGraphNodeNotFound,
168+
t, graph.DeleteLightningNode(ctx, testPub),
169+
ErrGraphNodeNotFound,
169170
)
170171

171172
// Finally, attempt to fetch the node again. This should fail as the
@@ -318,7 +319,7 @@ func TestPartialNode(t *testing.T) {
318319

319320
// Next, delete the node from the graph, this should purge all data
320321
// related to the node.
321-
require.NoError(t, graph.DeleteLightningNode(pubKey1))
322+
require.NoError(t, graph.DeleteLightningNode(ctx, pubKey1))
322323
assertNodeNotInCache(t, graph, testPub)
323324

324325
// Finally, attempt to fetch the node again. This should fail as the
@@ -3416,9 +3417,8 @@ func TestNodePruningUpdateIndexDeletion(t *testing.T) {
34163417

34173418
// We'll now delete the node from the graph, this should result in it
34183419
// being removed from the update index as well.
3419-
if err := graph.DeleteLightningNode(node1.PubKeyBytes); err != nil {
3420-
t.Fatalf("unable to delete node: %v", err)
3421-
}
3420+
err = graph.DeleteLightningNode(ctx, node1.PubKeyBytes)
3421+
require.NoError(t, err)
34223422

34233423
// Now that the node has been deleted, we'll again query the nodes in
34243424
// the horizon. This time we should have no nodes at all.

graph/db/interfaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ type V1Store interface { //nolint:interfacebloat
114114

115115
// DeleteLightningNode starts a new database transaction to remove a
116116
// vertex/node from the database according to the node's public key.
117-
DeleteLightningNode(nodePub route.Vertex) error
117+
DeleteLightningNode(ctx context.Context, nodePub route.Vertex) error
118118

119119
// NodeUpdatesInHorizon returns all the known lightning node which have
120120
// an update timestamp within the passed range. This method can be used

graph/db/kv_store.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,9 @@ func (c *KVStore) LookupAlias(pub *btcec.PublicKey) (string, error) {
10321032

10331033
// DeleteLightningNode starts a new database transaction to remove a vertex/node
10341034
// from the database according to the node's public key.
1035-
func (c *KVStore) DeleteLightningNode(nodePub route.Vertex) error {
1035+
func (c *KVStore) DeleteLightningNode(_ context.Context,
1036+
nodePub route.Vertex) error {
1037+
10361038
// TODO(roasbeef): ensure dangling edges are removed...
10371039
return kvdb.Update(c.db, func(tx kvdb.RwTx) error {
10381040
nodes := tx.ReadWriteBucket(nodeBucket)

graph/db/sql_store.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,8 @@ func (s *SQLStore) AddrsForNode(nodePub *btcec.PublicKey) (bool, []net.Addr,
291291
// from the database according to the node's public key.
292292
//
293293
// NOTE: part of the V1Store interface.
294-
func (s *SQLStore) DeleteLightningNode(pubKey route.Vertex) error {
295-
ctx := context.TODO()
294+
func (s *SQLStore) DeleteLightningNode(ctx context.Context,
295+
pubKey route.Vertex) error {
296296

297297
err := s.db.ExecTx(ctx, sqldb.WriteTxOpt(), func(db SQLQueries) error {
298298
res, err := db.DeleteNodeByPubKey(

0 commit comments

Comments
 (0)