From b3cf9a806f336ad0f02ff8fa334e2ad6a983c2d8 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Wed, 19 Nov 2025 17:39:58 +0200 Subject: [PATCH] multi: add DeleteChannelEdges to VersionedGraph Add version-aware DeleteChannelEdges method to VersionedGraph and update call sites in graph builder, rpcserver, and server to use versioned graphs. This ensures channel deletion operations are properly scoped to the correct gossip version. --- graph/builder.go | 2 +- graph/db/graph.go | 30 ++++++++++++++++++++++++++++++ graph/db/graph_test.go | 1 + rpcserver.go | 5 +++-- server.go | 2 +- 5 files changed, 36 insertions(+), 4 deletions(-) diff --git a/graph/builder.go b/graph/builder.go index 3e1571396..96a7582eb 100644 --- a/graph/builder.go +++ b/graph/builder.go @@ -625,7 +625,7 @@ func (b *Builder) pruneZombieChans() error { toPrune = append(toPrune, chanID) log.Tracef("Pruning zombie channel with ChannelID(%v)", chanID) } - err := b.cfg.Graph.DeleteChannelEdges( + err := b.v1Graph.DeleteChannelEdges( b.cfg.StrictZombiePruning, true, toPrune..., ) if err != nil { diff --git a/graph/db/graph.go b/graph/db/graph.go index f2a5ffb0e..302813f49 100644 --- a/graph/db/graph.go +++ b/graph/db/graph.go @@ -831,6 +831,36 @@ func (c *VersionedGraph) SourceNode(ctx context.Context) (*models.Node, return c.db.SourceNode(ctx, c.v) } +// DeleteChannelEdges removes edges with the given channel IDs from the +// database and marks them as zombies. This ensures that we're unable to re-add +// it to our database once again. If an edge does not exist within the +// database, then ErrEdgeNotFound will be returned. If strictZombiePruning is +// true, then when we mark these edges as zombies, we'll set up the keys such +// 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 { + + infos, err := c.db.DeleteChannelEdges( + c.v, strictZombiePruning, markZombie, chanIDs..., + ) + if err != nil { + return err + } + + if c.graphCache != nil { + for _, info := range infos { + c.graphCache.RemoveChannel( + info.NodeKey1Bytes, info.NodeKey2Bytes, + info.ChannelID, + ) + } + } + + return err +} + // MakeTestGraph creates a new instance of the ChannelGraph for testing // purposes. The backing Store implementation depends on the version of // NewTestDB included in the current build. diff --git a/graph/db/graph_test.go b/graph/db/graph_test.go index 6584e123b..ed6a5f580 100644 --- a/graph/db/graph_test.go +++ b/graph/db/graph_test.go @@ -153,6 +153,7 @@ var versionedTests = []versionedTest{ func TestVersionedDBs(t *testing.T) { t.Parallel() + // Run all v1 tests. for _, vt := range versionedTests { vt := vt diff --git a/rpcserver.go b/rpcserver.go index 0c496397b..927635a84 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -3196,7 +3196,7 @@ func createRPCCloseUpdate( // abandonChanFromGraph attempts to remove a channel from the channel graph. If // we can't find the chanID in the graph, then we assume it has already been // removed, and will return a nop. -func abandonChanFromGraph(chanGraph *graphdb.ChannelGraph, +func abandonChanFromGraph(chanGraph *graphdb.VersionedGraph, chanPoint *wire.OutPoint) error { // First, we'll obtain the channel ID. If we can't locate this, then @@ -3237,7 +3237,8 @@ func (r *rpcServer) abandonChan(chanPoint *wire.OutPoint, if err != nil { return err } - err = abandonChanFromGraph(r.server.graphDB, chanPoint) + // TODO: update to support deletions for v2 channels. + err = abandonChanFromGraph(r.server.v1Graph, chanPoint) if err != nil { return err } diff --git a/server.go b/server.go index 78b1971e1..7ba74176a 100644 --- a/server.go +++ b/server.go @@ -1422,7 +1422,7 @@ func newServer(ctx context.Context, cfg *Config, listenAddrs []net.Addr, return nil, fmt.Errorf("we don't have an edge") } - err = s.graphDB.DeleteChannelEdges( + err = s.v1Graph.DeleteChannelEdges( false, false, scid.ToUint64(), ) return ourPolicy, err