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.
This commit is contained in:
5 files changed
+36
-4
No files matched your search
+1
-1
@@ -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 {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -153,6 +153,7 @@ var versionedTests = []versionedTest{
|
||||
func TestVersionedDBs(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Run all v1 tests.
|
||||
for _, vt := range versionedTests {
|
||||
vt := vt
|
||||
|
||||
|
||||
+3
-2
@@ -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
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user