From 00f5fd9b7ff766ac6220e71d241e215a9a57d893 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Thu, 30 Jan 2025 13:47:37 +0200 Subject: [PATCH] graph: add IsZombieEdge method This is in preparation for the commit where we move across all the funding tx validation so that we can test that we are correctly updating the zombie index. --- discovery/gossiper_test.go | 11 +++++++++++ graph/builder.go | 10 ++++++++++ graph/interfaces.go | 4 ++++ 3 files changed, 25 insertions(+) diff --git a/discovery/gossiper_test.go b/discovery/gossiper_test.go index 94d7d426e..ca4645ede 100644 --- a/discovery/gossiper_test.go +++ b/discovery/gossiper_test.go @@ -113,6 +113,17 @@ func (r *mockGraphSource) MarkZombieEdge(scid uint64) error { ) } +func (r *mockGraphSource) IsZombieEdge(chanID lnwire.ShortChannelID) (bool, + error) { + + r.mu.Lock() + defer r.mu.Unlock() + + _, ok := r.zombies[chanID.ToUint64()] + + return ok, nil +} + func (r *mockGraphSource) AddEdge(info *models.ChannelEdgeInfo, _ ...batch.SchedulerOption) error { diff --git a/graph/builder.go b/graph/builder.go index 8f1d4bbc0..946e9a904 100644 --- a/graph/builder.go +++ b/graph/builder.go @@ -1630,6 +1630,16 @@ func (b *Builder) IsKnownEdge(chanID lnwire.ShortChannelID) bool { return exists || isZombie } +// IsZombieEdge returns true if the graph source has marked the given channel ID +// as a zombie edge. +// +// NOTE: This method is part of the ChannelGraphSource interface. +func (b *Builder) IsZombieEdge(chanID lnwire.ShortChannelID) (bool, error) { + _, _, _, isZombie, err := b.cfg.Graph.HasChannelEdge(chanID.ToUint64()) + + return isZombie, err +} + // IsStaleEdgePolicy returns true if the graph source has a channel edge for // the passed channel ID (and flags) that have a more recent timestamp. // diff --git a/graph/interfaces.go b/graph/interfaces.go index afa0ef687..87a004d25 100644 --- a/graph/interfaces.go +++ b/graph/interfaces.go @@ -88,6 +88,10 @@ type ChannelGraphSource interface { // MarkZombieEdge marks the channel with the given ID as a zombie edge. MarkZombieEdge(chanID uint64) error + + // IsZombieEdge returns true if the edge with the given channel ID is + // currently marked as a zombie edge. + IsZombieEdge(chanID lnwire.ShortChannelID) (bool, error) } // DB is an interface describing a persisted Lightning Network graph.