diff --git a/graph/builder.go b/graph/builder.go index f16441c9d..497b26329 100644 --- a/graph/builder.go +++ b/graph/builder.go @@ -630,7 +630,7 @@ func (b *Builder) pruneZombieChans() error { log.Tracef("Pruning zombie channel with ChannelID(%v)", chanID) } err := b.v1Graph.DeleteChannelEdges( - b.cfg.StrictZombiePruning, true, toPrune..., + context.TODO(), b.cfg.StrictZombiePruning, true, toPrune..., ) if err != nil { return fmt.Errorf("unable to delete zombie channels: %w", err) diff --git a/graph/db/graph.go b/graph/db/graph.go index 8abca8236..e199ce0b1 100644 --- a/graph/db/graph.go +++ b/graph/db/graph.go @@ -389,11 +389,11 @@ func (c *ChannelGraph) MarkEdgeLive(ctx context.Context, chanID uint64) error { // that we require the node that failed to send the fresh update to be the one // that resurrects the channel from its zombie state. The markZombie bool // denotes whether to mark the channel as a zombie. -func (c *ChannelGraph) DeleteChannelEdges(strictZombiePruning, markZombie bool, - chanIDs ...uint64) error { +func (c *ChannelGraph) DeleteChannelEdges(ctx context.Context, + strictZombiePruning, markZombie bool, chanIDs ...uint64) error { infos, err := c.db.DeleteChannelEdges( - lnwire.GossipVersion1, strictZombiePruning, markZombie, + ctx, lnwire.GossipVersion1, strictZombiePruning, markZombie, chanIDs..., ) if err != nil { @@ -889,11 +889,11 @@ func (c *VersionedGraph) SourceNode(ctx context.Context) (*models.Node, // that we require the node that failed to send the fresh update to be the one // that resurrects the channel from its zombie state. The markZombie bool // denotes whether to mark the channel as a zombie. -func (c *VersionedGraph) DeleteChannelEdges(strictZombiePruning, - markZombie bool, chanIDs ...uint64) error { +func (c *VersionedGraph) DeleteChannelEdges(ctx context.Context, + strictZombiePruning, markZombie bool, chanIDs ...uint64) error { infos, err := c.db.DeleteChannelEdges( - c.v, strictZombiePruning, markZombie, chanIDs..., + ctx, c.v, strictZombiePruning, markZombie, chanIDs..., ) if err != nil { return err diff --git a/graph/db/graph_test.go b/graph/db/graph_test.go index 2503f5870..8572808c4 100644 --- a/graph/db/graph_test.go +++ b/graph/db/graph_test.go @@ -699,7 +699,9 @@ func testEdgeInsertionDeletion(t *testing.T, v lnwire.GossipVersion) { // Next, attempt to delete the edge from the database, again this // should proceed without any issues. - require.NoError(t, graph.DeleteChannelEdges(false, true, chanID)) + require.NoError(t, graph.DeleteChannelEdges( + ctx, false, true, chanID, + )) assertNoEdge(t, graph.ChannelGraph, chanID) // Ensure that any query attempts to lookup the delete channel edge are @@ -720,7 +722,7 @@ func testEdgeInsertionDeletion(t *testing.T, v lnwire.GossipVersion) { // Finally, attempt to delete a (now) non-existent edge within the // database, this should result in an error. - err = graph.DeleteChannelEdges(false, true, chanID) + err = graph.DeleteChannelEdges(ctx, false, true, chanID) require.ErrorIs(t, err, ErrEdgeNotFound) } @@ -3064,7 +3066,9 @@ func TestFilterKnownChanIDs(t *testing.T) { node1, node2, ) require.NoError(t, graph.AddChannelEdge(ctx, channel)) - err := graph.DeleteChannelEdges(false, true, channel.ChannelID) + err := graph.DeleteChannelEdges( + ctx, false, true, channel.ChannelID, + ) require.NoError(t, err) zombieIDs = append( @@ -3403,7 +3407,8 @@ func TestStressTestChannelGraphAPI(t *testing.T) { } err := graph.DeleteChannelEdges( - strictPruning, markZombie, chanIDs..., + ctx, strictPruning, markZombie, + chanIDs..., ) if err != nil && !errors.Is(err, ErrEdgeNotFound) { @@ -3761,7 +3766,9 @@ func testFetchChanInfos(t *testing.T, v lnwire.GossipVersion) { v, 666, 0, 0, 0, node1, node2, ) require.NoError(t, graph.AddChannelEdge(ctx, zombieChan)) - err := graph.DeleteChannelEdges(false, true, zombieChan.ChannelID) + err := graph.DeleteChannelEdges( + ctx, false, true, zombieChan.ChannelID, + ) require.NoError(t, err, "unable to delete and mark edge zombie") edgeQuery = append(edgeQuery, zombieChanID.ToUint64()) @@ -4226,7 +4233,7 @@ func testNodeIsPublic(t *testing.T, v lnwire.GossipVersion) { // has any advertised edges. for _, graph := range graphs { err := graph.DeleteChannelEdges( - false, true, aliceBobEdge.ChannelID, + ctx, false, true, aliceBobEdge.ChannelID, ) require.NoError(t, err, "unable to remove edge") } @@ -4243,7 +4250,7 @@ func testNodeIsPublic(t *testing.T, v lnwire.GossipVersion) { // it without it being advertised. for _, graph := range graphs { err := graph.DeleteChannelEdges( - false, true, bobCarolEdge.ChannelID, + ctx, false, true, bobCarolEdge.ChannelID, ) require.NoError(t, err, "unable to remove edge") @@ -4404,7 +4411,7 @@ func testDisabledChannelIDs(t *testing.T, v lnwire.GossipVersion) { // Delete the channel edge and ensure it is removed from the disabled // list. require.NoError(t, graph.DeleteChannelEdges( - false, true, edgeInfo.ChannelID, + ctx, false, true, edgeInfo.ChannelID, )) disabledChanIds, err = graph.DisabledChannelIDs(ctx) require.NoError(t, err, "unable to get disabled channel ids") @@ -4571,7 +4578,7 @@ func TestGraphZombieIndex(t *testing.T) { // If we delete the edge and mark it as a zombie, then we should expect // to see it within the index. - err = graph.DeleteChannelEdges(false, true, edge.ChannelID) + err = graph.DeleteChannelEdges(ctx, false, true, edge.ChannelID) require.NoError(t, err, "unable to mark edge as zombie") isZombie, pubKey1, pubKey2, err := graph.IsZombieEdge( ctx, edge.ChannelID, diff --git a/graph/db/interfaces.go b/graph/db/interfaces.go index a42836f69..a69818366 100644 --- a/graph/db/interfaces.go +++ b/graph/db/interfaces.go @@ -230,8 +230,8 @@ type Store interface { //nolint:interfacebloat // failed to send the fresh update to be the one that resurrects the // channel from its zombie state. The markZombie bool denotes whether // to mark the channel as a zombie. - DeleteChannelEdges(v lnwire.GossipVersion, strictZombiePruning, - markZombie bool, chanIDs ...uint64) ( + DeleteChannelEdges(ctx context.Context, v lnwire.GossipVersion, + strictZombiePruning, markZombie bool, chanIDs ...uint64) ( []*models.ChannelEdgeInfo, error) // AddEdgeProof sets the proof of an existing edge in the graph diff --git a/graph/db/kv_store.go b/graph/db/kv_store.go index 98308ae4a..09b180b1f 100644 --- a/graph/db/kv_store.go +++ b/graph/db/kv_store.go @@ -1934,8 +1934,9 @@ func (c *KVStore) PruneTip() (*chainhash.Hash, uint32, error) { // that we require the node that failed to send the fresh update to be the one // that resurrects the channel from its zombie state. The markZombie bool // denotes whether or not to mark the channel as a zombie. -func (c *KVStore) DeleteChannelEdges(v lnwire.GossipVersion, - strictZombiePruning, markZombie bool, chanIDs ...uint64) ( +func (c *KVStore) DeleteChannelEdges(_ context.Context, + v lnwire.GossipVersion, strictZombiePruning, markZombie bool, + chanIDs ...uint64) ( []*models.ChannelEdgeInfo, error) { if v != lnwire.GossipVersion1 { diff --git a/graph/db/sql_store.go b/graph/db/sql_store.go index dc8492e78..a534eccf7 100644 --- a/graph/db/sql_store.go +++ b/graph/db/sql_store.go @@ -1946,8 +1946,9 @@ func (s *SQLStore) NumZombies(ctx context.Context) (uint64, error) { // denotes whether to mark the channel as a zombie. // // NOTE: part of the Store interface. -func (s *SQLStore) DeleteChannelEdges(v lnwire.GossipVersion, - strictZombiePruning, markZombie bool, chanIDs ...uint64) ( +func (s *SQLStore) DeleteChannelEdges(ctx context.Context, + v lnwire.GossipVersion, strictZombiePruning, markZombie bool, + chanIDs ...uint64) ( []*models.ChannelEdgeInfo, error) { s.cacheMu.Lock() @@ -1960,10 +1961,7 @@ func (s *SQLStore) DeleteChannelEdges(v lnwire.GossipVersion, chanLookup[chanID] = struct{}{} } - var ( - ctx = context.TODO() - edges []*models.ChannelEdgeInfo - ) + var edges []*models.ChannelEdgeInfo err := s.db.ExecTx(ctx, sqldb.WriteTxOpt(), func(db SQLQueries) error { // First, collect all channel rows. var channelRows []sqlc.GetChannelsBySCIDWithPoliciesRow diff --git a/rpcserver.go b/rpcserver.go index f0eecd4a1..bfe537a14 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -3212,7 +3212,7 @@ func abandonChanFromGraph(chanGraph *graphdb.VersionedGraph, // If the channel ID is still in the graph, then that means the channel // is still open, so we'll now move to purge it from the graph. - return chanGraph.DeleteChannelEdges(false, true, chanID) + return chanGraph.DeleteChannelEdges(context.TODO(), false, true, chanID) } // abandonChan removes a channel from the database, graph and contract court. diff --git a/server.go b/server.go index 91b662463..248a69c6c 100644 --- a/server.go +++ b/server.go @@ -1426,7 +1426,7 @@ func newServer(ctx context.Context, cfg *Config, listenAddrs []net.Addr, } err = s.v1Graph.DeleteChannelEdges( - false, false, scid.ToUint64(), + context.TODO(), false, false, scid.ToUint64(), ) return ourPolicy, err }