diff --git a/graph/db/errors.go b/graph/db/errors.go index 8201980aa..433592153 100644 --- a/graph/db/errors.go +++ b/graph/db/errors.go @@ -66,6 +66,11 @@ var ( // ErrUnknownAddressType is returned when a node's addressType is not // an expected value. 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 diff --git a/graph/db/graph_test.go b/graph/db/graph_test.go index d86a2f65c..918369a9c 100644 --- a/graph/db/graph_test.go +++ b/graph/db/graph_test.go @@ -453,7 +453,8 @@ func TestEdgeInsertionDeletion(t *testing.T) { require.ErrorIs(t, err, ErrEdgeNotFound) _, _, _, err = graph.FetchChannelEdgesByID(chanID) require.ErrorIs(t, err, ErrZombieEdge) - isZombie, _, _ := graph.IsZombieEdge(chanID) + isZombie, _, _, err := graph.IsZombieEdge(chanID) + require.NoError(t, err) require.True(t, isZombie) // 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 { - zombie, _, _ := graph.IsZombieEdge(scid.ToUint64()) + zombie, _, _, err := graph.IsZombieEdge(scid.ToUint64()) + require.NoError(t, err) + 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 // 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) assertNumZombies(t, graph, 0) // 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(false, true, edge.ChannelID) 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.Equal(t, node1.PubKeyBytes, pubKey1) require.Equal(t, node2.PubKeyBytes, pubKey2) @@ -3868,7 +3873,8 @@ func TestGraphZombieIndex(t *testing.T) { 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) assertNumZombies(t, graph, 0) @@ -3880,7 +3886,8 @@ func TestGraphZombieIndex(t *testing.T) { ) 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) assertNumZombies(t, graph, 1) } diff --git a/graph/db/interfaces.go b/graph/db/interfaces.go index 0759637fd..7140553b7 100644 --- a/graph/db/interfaces.go +++ b/graph/db/interfaces.go @@ -308,7 +308,7 @@ type V1Store interface { //nolint:interfacebloat // 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 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 // graph. diff --git a/graph/db/kv_store.go b/graph/db/kv_store.go index 66fb93ba6..87651e461 100644 --- a/graph/db/kv_store.go +++ b/graph/db/kv_store.go @@ -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 // zombie, then the two node public keys corresponding to this edge are also // 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 ( isZombie bool pubKey1, pubKey2 [33]byte @@ -3817,10 +3819,11 @@ func (c *KVStore) IsZombieEdge(chanID uint64) (bool, [33]byte, [33]byte) { pubKey2 = [33]byte{} }) 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 diff --git a/graph/db/sql_store.go b/graph/db/sql_store.go index c8f222b29..698c47771 100644 --- a/graph/db/sql_store.go +++ b/graph/db/sql_store.go @@ -1636,7 +1636,9 @@ func (s *SQLStore) MarkEdgeLive(chanID uint64) error { // returned. // // 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 ( ctx = context.TODO() isZombie bool @@ -1666,12 +1668,12 @@ func (s *SQLStore) IsZombieEdge(chanID uint64) (bool, [33]byte, [33]byte) { return nil }, sqldb.NoOpReset) if err != nil { - // TODO(elle): update the IsZombieEdge method to return an - // error. - return false, route.Vertex{}, route.Vertex{} + return false, route.Vertex{}, route.Vertex{}, + fmt.Errorf("%w: %w (chanID=%d)", + ErrCantCheckIfZombieEdgeStr, err, chanID) } - return isZombie, pubKey1, pubKey2 + return isZombie, pubKey1, pubKey2, nil } // NumZombies returns the current number of zombie channels in the graph.