graph/db: let IsZombieEdge return an error

This commit is contained in:
Elle Mouton committed 2025-06-26 10:19:51 +02:00
1 parent e38aa6d1e0
commit cc0be0bca2
5 files changed
+33 -16

No files matched your search

+5
View File
@@ -66,6 +66,11 @@ var (
// ErrUnknownAddressType is returned when a node's addressType is not // ErrUnknownAddressType is returned when a node's addressType is not
// an expected value. // an expected value.
ErrUnknownAddressType = fmt.Errorf("address type cannot be resolved") ErrUnknownAddressType = fmt.Errorf("address type cannot be resolved")
// ErrCantCheckIfZombieEdgeStr is an error returned when we
// attempt to check if an edge is a zombie but encounter an error.
ErrCantCheckIfZombieEdgeStr = fmt.Errorf("unable to check if edge " +
"is a zombie")
) )
// ErrTooManyExtraOpaqueBytes creates an error which should be returned if the // ErrTooManyExtraOpaqueBytes creates an error which should be returned if the
+14 -7
View File
@@ -453,7 +453,8 @@ func TestEdgeInsertionDeletion(t *testing.T) {
require.ErrorIs(t, err, ErrEdgeNotFound) require.ErrorIs(t, err, ErrEdgeNotFound)
_, _, _, err = graph.FetchChannelEdgesByID(chanID) _, _, _, err = graph.FetchChannelEdgesByID(chanID)
require.ErrorIs(t, err, ErrZombieEdge) require.ErrorIs(t, err, ErrZombieEdge)
isZombie, _, _ := graph.IsZombieEdge(chanID) isZombie, _, _, err := graph.IsZombieEdge(chanID)
require.NoError(t, err)
require.True(t, isZombie) require.True(t, isZombie)
// Finally, attempt to delete a (now) non-existent edge within the // Finally, attempt to delete a (now) non-existent edge within the
@@ -2205,7 +2206,9 @@ func TestFilterKnownChanIDsZombieRevival(t *testing.T) {
) )
isZombie := func(scid lnwire.ShortChannelID) bool { isZombie := func(scid lnwire.ShortChannelID) bool {
zombie, _, _ := graph.IsZombieEdge(scid.ToUint64()) zombie, _, _, err := graph.IsZombieEdge(scid.ToUint64())
require.NoError(t, err)
return zombie return zombie
} }
@@ -3844,15 +3847,17 @@ func TestGraphZombieIndex(t *testing.T) {
// Since the edge is known the graph and it isn't a zombie, IsZombieEdge // Since the edge is known the graph and it isn't a zombie, IsZombieEdge
// should not report the channel as a zombie. // should not report the channel as a zombie.
isZombie, _, _ := graph.IsZombieEdge(edge.ChannelID) isZombie, _, _, err := graph.IsZombieEdge(edge.ChannelID)
require.NoError(t, err)
require.False(t, isZombie) require.False(t, isZombie)
assertNumZombies(t, graph, 0) assertNumZombies(t, graph, 0)
// If we delete the edge and mark it as a zombie, then we should expect // If we delete the edge and mark it as a zombie, then we should expect
// to see it within the index. // to see it within the index.
err := graph.DeleteChannelEdges(false, true, edge.ChannelID) err = graph.DeleteChannelEdges(false, true, edge.ChannelID)
require.NoError(t, err, "unable to mark edge as zombie") require.NoError(t, err, "unable to mark edge as zombie")
isZombie, pubKey1, pubKey2 := graph.IsZombieEdge(edge.ChannelID) isZombie, pubKey1, pubKey2, err := graph.IsZombieEdge(edge.ChannelID)
require.NoError(t, err)
require.True(t, isZombie) require.True(t, isZombie)
require.Equal(t, node1.PubKeyBytes, pubKey1) require.Equal(t, node1.PubKeyBytes, pubKey1)
require.Equal(t, node2.PubKeyBytes, pubKey2) require.Equal(t, node2.PubKeyBytes, pubKey2)
@@ -3868,7 +3873,8 @@ func TestGraphZombieIndex(t *testing.T) {
t, graph.MarkEdgeLive(edge.ChannelID), ErrZombieEdgeNotFound, t, graph.MarkEdgeLive(edge.ChannelID), ErrZombieEdgeNotFound,
) )
isZombie, _, _ = graph.IsZombieEdge(edge.ChannelID) isZombie, _, _, err = graph.IsZombieEdge(edge.ChannelID)
require.NoError(t, err)
require.False(t, isZombie) require.False(t, isZombie)
assertNumZombies(t, graph, 0) assertNumZombies(t, graph, 0)
@@ -3880,7 +3886,8 @@ func TestGraphZombieIndex(t *testing.T) {
) )
require.NoError(t, err, "unable to mark edge as zombie") require.NoError(t, err, "unable to mark edge as zombie")
isZombie, _, _ = graph.IsZombieEdge(edge.ChannelID) isZombie, _, _, err = graph.IsZombieEdge(edge.ChannelID)
require.NoError(t, err)
require.True(t, isZombie) require.True(t, isZombie)
assertNumZombies(t, graph, 1) assertNumZombies(t, graph, 1)
} }
+1 -1
View File
@@ -308,7 +308,7 @@ type V1Store interface { //nolint:interfacebloat
// IsZombieEdge returns whether the edge is considered zombie. If it is // IsZombieEdge returns whether the edge is considered zombie. If it is
// a zombie, then the two node public keys corresponding to this edge // a zombie, then the two node public keys corresponding to this edge
// are also returned. // are also returned.
IsZombieEdge(chanID uint64) (bool, [33]byte, [33]byte) IsZombieEdge(chanID uint64) (bool, [33]byte, [33]byte, error)
// NumZombies returns the current number of zombie channels in the // NumZombies returns the current number of zombie channels in the
// graph. // graph.
+6 -3
View File
@@ -3792,7 +3792,9 @@ func (c *KVStore) markEdgeLiveUnsafe(tx kvdb.RwTx, chanID uint64) error {
// IsZombieEdge returns whether the edge is considered zombie. If it is a // IsZombieEdge returns whether the edge is considered zombie. If it is a
// zombie, then the two node public keys corresponding to this edge are also // zombie, then the two node public keys corresponding to this edge are also
// returned. // returned.
func (c *KVStore) IsZombieEdge(chanID uint64) (bool, [33]byte, [33]byte) { func (c *KVStore) IsZombieEdge(chanID uint64) (bool, [33]byte, [33]byte,
error) {
var ( var (
isZombie bool isZombie bool
pubKey1, pubKey2 [33]byte pubKey1, pubKey2 [33]byte
@@ -3817,10 +3819,11 @@ func (c *KVStore) IsZombieEdge(chanID uint64) (bool, [33]byte, [33]byte) {
pubKey2 = [33]byte{} pubKey2 = [33]byte{}
}) })
if err != nil { if err != nil {
return false, [33]byte{}, [33]byte{} return false, [33]byte{}, [33]byte{}, fmt.Errorf("%w: %w "+
"(chanID=%d)", ErrCantCheckIfZombieEdgeStr, err, chanID)
} }
return isZombie, pubKey1, pubKey2 return isZombie, pubKey1, pubKey2, nil
} }
// isZombieEdge returns whether an entry exists for the given channel in the // isZombieEdge returns whether an entry exists for the given channel in the
+7 -5
View File
@@ -1636,7 +1636,9 @@ func (s *SQLStore) MarkEdgeLive(chanID uint64) error {
// returned. // returned.
// //
// NOTE: part of the V1Store interface. // NOTE: part of the V1Store interface.
func (s *SQLStore) IsZombieEdge(chanID uint64) (bool, [33]byte, [33]byte) { func (s *SQLStore) IsZombieEdge(chanID uint64) (bool, [33]byte, [33]byte,
error) {
var ( var (
ctx = context.TODO() ctx = context.TODO()
isZombie bool isZombie bool
@@ -1666,12 +1668,12 @@ func (s *SQLStore) IsZombieEdge(chanID uint64) (bool, [33]byte, [33]byte) {
return nil return nil
}, sqldb.NoOpReset) }, sqldb.NoOpReset)
if err != nil { if err != nil {
// TODO(elle): update the IsZombieEdge method to return an return false, route.Vertex{}, route.Vertex{},
// error. fmt.Errorf("%w: %w (chanID=%d)",
return false, route.Vertex{}, route.Vertex{} ErrCantCheckIfZombieEdgeStr, err, chanID)
} }
return isZombie, pubKey1, pubKey2 return isZombie, pubKey1, pubKey2, nil
} }
// NumZombies returns the current number of zombie channels in the graph. // NumZombies returns the current number of zombie channels in the graph.