Skip to content

Commit cc0be0b

Browse files
committed
graph/db: let IsZombieEdge return an error
1 parent e38aa6d commit cc0be0b

File tree

5 files changed

+33
-16
lines changed

5 files changed

+33
-16
lines changed

graph/db/errors.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ var (
6666
// ErrUnknownAddressType is returned when a node's addressType is not
6767
// an expected value.
6868
ErrUnknownAddressType = fmt.Errorf("address type cannot be resolved")
69+
70+
// ErrCantCheckIfZombieEdgeStr is an error returned when we
71+
// attempt to check if an edge is a zombie but encounter an error.
72+
ErrCantCheckIfZombieEdgeStr = fmt.Errorf("unable to check if edge " +
73+
"is a zombie")
6974
)
7075

7176
// ErrTooManyExtraOpaqueBytes creates an error which should be returned if the

graph/db/graph_test.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,8 @@ func TestEdgeInsertionDeletion(t *testing.T) {
453453
require.ErrorIs(t, err, ErrEdgeNotFound)
454454
_, _, _, err = graph.FetchChannelEdgesByID(chanID)
455455
require.ErrorIs(t, err, ErrZombieEdge)
456-
isZombie, _, _ := graph.IsZombieEdge(chanID)
456+
isZombie, _, _, err := graph.IsZombieEdge(chanID)
457+
require.NoError(t, err)
457458
require.True(t, isZombie)
458459

459460
// Finally, attempt to delete a (now) non-existent edge within the
@@ -2205,7 +2206,9 @@ func TestFilterKnownChanIDsZombieRevival(t *testing.T) {
22052206
)
22062207

22072208
isZombie := func(scid lnwire.ShortChannelID) bool {
2208-
zombie, _, _ := graph.IsZombieEdge(scid.ToUint64())
2209+
zombie, _, _, err := graph.IsZombieEdge(scid.ToUint64())
2210+
require.NoError(t, err)
2211+
22092212
return zombie
22102213
}
22112214

@@ -3844,15 +3847,17 @@ func TestGraphZombieIndex(t *testing.T) {
38443847

38453848
// Since the edge is known the graph and it isn't a zombie, IsZombieEdge
38463849
// should not report the channel as a zombie.
3847-
isZombie, _, _ := graph.IsZombieEdge(edge.ChannelID)
3850+
isZombie, _, _, err := graph.IsZombieEdge(edge.ChannelID)
3851+
require.NoError(t, err)
38483852
require.False(t, isZombie)
38493853
assertNumZombies(t, graph, 0)
38503854

38513855
// If we delete the edge and mark it as a zombie, then we should expect
38523856
// to see it within the index.
3853-
err := graph.DeleteChannelEdges(false, true, edge.ChannelID)
3857+
err = graph.DeleteChannelEdges(false, true, edge.ChannelID)
38543858
require.NoError(t, err, "unable to mark edge as zombie")
3855-
isZombie, pubKey1, pubKey2 := graph.IsZombieEdge(edge.ChannelID)
3859+
isZombie, pubKey1, pubKey2, err := graph.IsZombieEdge(edge.ChannelID)
3860+
require.NoError(t, err)
38563861
require.True(t, isZombie)
38573862
require.Equal(t, node1.PubKeyBytes, pubKey1)
38583863
require.Equal(t, node2.PubKeyBytes, pubKey2)
@@ -3868,7 +3873,8 @@ func TestGraphZombieIndex(t *testing.T) {
38683873
t, graph.MarkEdgeLive(edge.ChannelID), ErrZombieEdgeNotFound,
38693874
)
38703875

3871-
isZombie, _, _ = graph.IsZombieEdge(edge.ChannelID)
3876+
isZombie, _, _, err = graph.IsZombieEdge(edge.ChannelID)
3877+
require.NoError(t, err)
38723878
require.False(t, isZombie)
38733879

38743880
assertNumZombies(t, graph, 0)
@@ -3880,7 +3886,8 @@ func TestGraphZombieIndex(t *testing.T) {
38803886
)
38813887
require.NoError(t, err, "unable to mark edge as zombie")
38823888

3883-
isZombie, _, _ = graph.IsZombieEdge(edge.ChannelID)
3889+
isZombie, _, _, err = graph.IsZombieEdge(edge.ChannelID)
3890+
require.NoError(t, err)
38843891
require.True(t, isZombie)
38853892
assertNumZombies(t, graph, 1)
38863893
}

graph/db/interfaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ type V1Store interface { //nolint:interfacebloat
308308
// IsZombieEdge returns whether the edge is considered zombie. If it is
309309
// a zombie, then the two node public keys corresponding to this edge
310310
// are also returned.
311-
IsZombieEdge(chanID uint64) (bool, [33]byte, [33]byte)
311+
IsZombieEdge(chanID uint64) (bool, [33]byte, [33]byte, error)
312312

313313
// NumZombies returns the current number of zombie channels in the
314314
// graph.

graph/db/kv_store.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3792,7 +3792,9 @@ func (c *KVStore) markEdgeLiveUnsafe(tx kvdb.RwTx, chanID uint64) error {
37923792
// IsZombieEdge returns whether the edge is considered zombie. If it is a
37933793
// zombie, then the two node public keys corresponding to this edge are also
37943794
// returned.
3795-
func (c *KVStore) IsZombieEdge(chanID uint64) (bool, [33]byte, [33]byte) {
3795+
func (c *KVStore) IsZombieEdge(chanID uint64) (bool, [33]byte, [33]byte,
3796+
error) {
3797+
37963798
var (
37973799
isZombie bool
37983800
pubKey1, pubKey2 [33]byte
@@ -3817,10 +3819,11 @@ func (c *KVStore) IsZombieEdge(chanID uint64) (bool, [33]byte, [33]byte) {
38173819
pubKey2 = [33]byte{}
38183820
})
38193821
if err != nil {
3820-
return false, [33]byte{}, [33]byte{}
3822+
return false, [33]byte{}, [33]byte{}, fmt.Errorf("%w: %w "+
3823+
"(chanID=%d)", ErrCantCheckIfZombieEdgeStr, err, chanID)
38213824
}
38223825

3823-
return isZombie, pubKey1, pubKey2
3826+
return isZombie, pubKey1, pubKey2, nil
38243827
}
38253828

38263829
// isZombieEdge returns whether an entry exists for the given channel in the

graph/db/sql_store.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,7 +1636,9 @@ func (s *SQLStore) MarkEdgeLive(chanID uint64) error {
16361636
// returned.
16371637
//
16381638
// NOTE: part of the V1Store interface.
1639-
func (s *SQLStore) IsZombieEdge(chanID uint64) (bool, [33]byte, [33]byte) {
1639+
func (s *SQLStore) IsZombieEdge(chanID uint64) (bool, [33]byte, [33]byte,
1640+
error) {
1641+
16401642
var (
16411643
ctx = context.TODO()
16421644
isZombie bool
@@ -1666,12 +1668,12 @@ func (s *SQLStore) IsZombieEdge(chanID uint64) (bool, [33]byte, [33]byte) {
16661668
return nil
16671669
}, sqldb.NoOpReset)
16681670
if err != nil {
1669-
// TODO(elle): update the IsZombieEdge method to return an
1670-
// error.
1671-
return false, route.Vertex{}, route.Vertex{}
1671+
return false, route.Vertex{}, route.Vertex{},
1672+
fmt.Errorf("%w: %w (chanID=%d)",
1673+
ErrCantCheckIfZombieEdgeStr, err, chanID)
16721674
}
16731675

1674-
return isZombie, pubKey1, pubKey2
1676+
return isZombie, pubKey1, pubKey2, nil
16751677
}
16761678

16771679
// NumZombies returns the current number of zombie channels in the graph.

0 commit comments

Comments
 (0)