graph/db: thread context through to DeleteLightningNode

This commit is contained in:
Elle Mouton committed 2025-06-17 19:20:59 +02:00
1 parent dc6259fcc3
commit d1fa5701eb
5 files changed
+16 -12

No files matched your search

+4 -2
View File
@@ -286,8 +286,10 @@ func (c *ChannelGraph) AddLightningNode(ctx context.Context,
// DeleteLightningNode starts a new database transaction to remove a vertex/node // DeleteLightningNode starts a new database transaction to remove a vertex/node
// from the database according to the node's public key. // from the database according to the node's public key.
func (c *ChannelGraph) DeleteLightningNode(nodePub route.Vertex) error { func (c *ChannelGraph) DeleteLightningNode(ctx context.Context,
err := c.V1Store.DeleteLightningNode(nodePub) nodePub route.Vertex) error {
err := c.V1Store.DeleteLightningNode(ctx, nodePub)
if err != nil { if err != nil {
return err return err
} }
+6 -6
View File
@@ -159,13 +159,14 @@ func TestNodeInsertionAndDeletion(t *testing.T) {
// Next, delete the node from the graph, this should purge all data // Next, delete the node from the graph, this should purge all data
// related to the node. // related to the node.
require.NoError(t, graph.DeleteLightningNode(testPub)) require.NoError(t, graph.DeleteLightningNode(ctx, testPub))
assertNodeNotInCache(t, graph, testPub) assertNodeNotInCache(t, graph, testPub)
// Attempting to delete the node again should return an error since // Attempting to delete the node again should return an error since
// the node is no longer known. // the node is no longer known.
require.ErrorIs( 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 // 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 // Next, delete the node from the graph, this should purge all data
// related to the node. // related to the node.
require.NoError(t, graph.DeleteLightningNode(pubKey1)) require.NoError(t, graph.DeleteLightningNode(ctx, pubKey1))
assertNodeNotInCache(t, graph, testPub) assertNodeNotInCache(t, graph, testPub)
// Finally, attempt to fetch the node again. This should fail as the // 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 // We'll now delete the node from the graph, this should result in it
// being removed from the update index as well. // being removed from the update index as well.
if err := graph.DeleteLightningNode(node1.PubKeyBytes); err != nil { err = graph.DeleteLightningNode(ctx, node1.PubKeyBytes)
t.Fatalf("unable to delete node: %v", err) require.NoError(t, err)
}
// Now that the node has been deleted, we'll again query the nodes in // 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. // the horizon. This time we should have no nodes at all.
+1 -1
View File
@@ -114,7 +114,7 @@ type V1Store interface { //nolint:interfacebloat
// DeleteLightningNode starts a new database transaction to remove a // DeleteLightningNode starts a new database transaction to remove a
// vertex/node from the database according to the node's public key. // 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 // NodeUpdatesInHorizon returns all the known lightning node which have
// an update timestamp within the passed range. This method can be used // an update timestamp within the passed range. This method can be used
+3 -1
View File
@@ -1032,7 +1032,9 @@ func (c *KVStore) LookupAlias(pub *btcec.PublicKey) (string, error) {
// DeleteLightningNode starts a new database transaction to remove a vertex/node // DeleteLightningNode starts a new database transaction to remove a vertex/node
// from the database according to the node's public key. // 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... // TODO(roasbeef): ensure dangling edges are removed...
return kvdb.Update(c.db, func(tx kvdb.RwTx) error { return kvdb.Update(c.db, func(tx kvdb.RwTx) error {
nodes := tx.ReadWriteBucket(nodeBucket) nodes := tx.ReadWriteBucket(nodeBucket)
+2 -2
View File
@@ -291,8 +291,8 @@ func (s *SQLStore) AddrsForNode(nodePub *btcec.PublicKey) (bool, []net.Addr,
// from the database according to the node's public key. // from the database according to the node's public key.
// //
// NOTE: part of the V1Store interface. // NOTE: part of the V1Store interface.
func (s *SQLStore) DeleteLightningNode(pubKey route.Vertex) error { func (s *SQLStore) DeleteLightningNode(ctx context.Context,
ctx := context.TODO() pubKey route.Vertex) error {
err := s.db.ExecTx(ctx, sqldb.WriteTxOpt(), func(db SQLQueries) error { err := s.db.ExecTx(ctx, sqldb.WriteTxOpt(), func(db SQLQueries) error {
res, err := db.DeleteNodeByPubKey( res, err := db.DeleteNodeByPubKey(