graph/db: thread context through to DeleteLightningNode
This commit is contained in:
5 files changed
+16
-12
No files matched your search
+4
-2
@@ -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
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in new issue
Block a user