graph/db: let IsZombieEdge return an error
This commit is contained in:
5 files changed
+33
-16
No files matched your search
@@ -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
|
||||
|
||||
+14
-7
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in new issue
Block a user