graphdb: pass context to HasChannelEdge
This commit is contained in:
7 files changed
+32
-34
No files matched your search
+3
-3
@@ -1050,7 +1050,7 @@ func (b *Builder) addEdge(ctx context.Context, edge *models.ChannelEdgeInfo,
|
|||||||
// Prior to processing the announcement we first check if we
|
// Prior to processing the announcement we first check if we
|
||||||
// already know of this channel, if so, then we can exit early.
|
// already know of this channel, if so, then we can exit early.
|
||||||
exists, isZombie, err := b.cfg.Graph.HasChannelEdge(
|
exists, isZombie, err := b.cfg.Graph.HasChannelEdge(
|
||||||
edge.Version, edge.ChannelID,
|
ctx, edge.Version, edge.ChannelID,
|
||||||
)
|
)
|
||||||
if err != nil && !errors.Is(err, graphdb.ErrGraphNoEdgesFound) {
|
if err != nil && !errors.Is(err, graphdb.ErrGraphNoEdgesFound) {
|
||||||
return fmt.Errorf("unable to check for edge existence: %w",
|
return fmt.Errorf("unable to check for edge existence: %w",
|
||||||
@@ -1340,7 +1340,7 @@ func (b *Builder) IsPublicNode(node route.Vertex) (bool, error) {
|
|||||||
// NOTE: This method is part of the ChannelGraphSource interface.
|
// NOTE: This method is part of the ChannelGraphSource interface.
|
||||||
func (b *Builder) IsKnownEdge(chanID lnwire.ShortChannelID) bool {
|
func (b *Builder) IsKnownEdge(chanID lnwire.ShortChannelID) bool {
|
||||||
exists, isZombie, _ := b.cfg.Graph.HasChannelEdge(
|
exists, isZombie, _ := b.cfg.Graph.HasChannelEdge(
|
||||||
lnwire.GossipVersion1, chanID.ToUint64(),
|
context.TODO(), lnwire.GossipVersion1, chanID.ToUint64(),
|
||||||
)
|
)
|
||||||
|
|
||||||
return exists || isZombie
|
return exists || isZombie
|
||||||
@@ -1352,7 +1352,7 @@ func (b *Builder) IsKnownEdge(chanID lnwire.ShortChannelID) bool {
|
|||||||
// NOTE: This method is part of the ChannelGraphSource interface.
|
// NOTE: This method is part of the ChannelGraphSource interface.
|
||||||
func (b *Builder) IsZombieEdge(chanID lnwire.ShortChannelID) (bool, error) {
|
func (b *Builder) IsZombieEdge(chanID lnwire.ShortChannelID) (bool, error) {
|
||||||
_, isZombie, err := b.cfg.Graph.HasChannelEdge(
|
_, isZombie, err := b.cfg.Graph.HasChannelEdge(
|
||||||
lnwire.GossipVersion1, chanID.ToUint64(),
|
context.TODO(), lnwire.GossipVersion1, chanID.ToUint64(),
|
||||||
)
|
)
|
||||||
|
|
||||||
return isZombie, err
|
return isZombie, err
|
||||||
|
|||||||
+11
-11
@@ -311,12 +311,12 @@ func TestWakeUpOnStaleBranch(t *testing.T) {
|
|||||||
require.NoError(t, ctx.builder.AddEdge(ctxb, edge2))
|
require.NoError(t, ctx.builder.AddEdge(ctxb, edge2))
|
||||||
|
|
||||||
// Check that the fundingTxs are in the graph db.
|
// Check that the fundingTxs are in the graph db.
|
||||||
has, isZombie, err := ctx.graph.HasChannelEdge(chanID1)
|
has, isZombie, err := ctx.graph.HasChannelEdge(t.Context(), chanID1)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.True(t, has)
|
require.True(t, has)
|
||||||
require.False(t, isZombie)
|
require.False(t, isZombie)
|
||||||
|
|
||||||
has, isZombie, err = ctx.graph.HasChannelEdge(chanID2)
|
has, isZombie, err = ctx.graph.HasChannelEdge(t.Context(), chanID2)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.True(t, has)
|
require.True(t, has)
|
||||||
require.False(t, isZombie)
|
require.False(t, isZombie)
|
||||||
@@ -363,12 +363,12 @@ func TestWakeUpOnStaleBranch(t *testing.T) {
|
|||||||
// The channel with chanID2 should not be in the database anymore,
|
// The channel with chanID2 should not be in the database anymore,
|
||||||
// since it is not confirmed on the longest chain. chanID1 should
|
// since it is not confirmed on the longest chain. chanID1 should
|
||||||
// still be.
|
// still be.
|
||||||
has, isZombie, err = ctx.graph.HasChannelEdge(chanID1)
|
has, isZombie, err = ctx.graph.HasChannelEdge(t.Context(), chanID1)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.True(t, has)
|
require.True(t, has)
|
||||||
require.False(t, isZombie)
|
require.False(t, isZombie)
|
||||||
|
|
||||||
has, isZombie, err = ctx.graph.HasChannelEdge(chanID2)
|
has, isZombie, err = ctx.graph.HasChannelEdge(t.Context(), chanID2)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.False(t, has)
|
require.False(t, has)
|
||||||
require.False(t, isZombie)
|
require.False(t, isZombie)
|
||||||
@@ -482,12 +482,12 @@ func TestDisconnectedBlocks(t *testing.T) {
|
|||||||
require.NoError(t, ctx.builder.AddEdge(ctxb, edge2))
|
require.NoError(t, ctx.builder.AddEdge(ctxb, edge2))
|
||||||
|
|
||||||
// Check that the fundingTxs are in the graph db.
|
// Check that the fundingTxs are in the graph db.
|
||||||
has, isZombie, err := ctx.graph.HasChannelEdge(chanID1)
|
has, isZombie, err := ctx.graph.HasChannelEdge(t.Context(), chanID1)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.True(t, has)
|
require.True(t, has)
|
||||||
require.False(t, isZombie)
|
require.False(t, isZombie)
|
||||||
|
|
||||||
has, isZombie, err = ctx.graph.HasChannelEdge(chanID2)
|
has, isZombie, err = ctx.graph.HasChannelEdge(t.Context(), chanID2)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.True(t, has)
|
require.True(t, has)
|
||||||
require.False(t, isZombie)
|
require.False(t, isZombie)
|
||||||
@@ -523,12 +523,12 @@ func TestDisconnectedBlocks(t *testing.T) {
|
|||||||
|
|
||||||
// chanID2 should not be in the database anymore, since it is not
|
// chanID2 should not be in the database anymore, since it is not
|
||||||
// confirmed on the longest chain. chanID1 should still be.
|
// confirmed on the longest chain. chanID1 should still be.
|
||||||
has, isZombie, err = ctx.graph.HasChannelEdge(chanID1)
|
has, isZombie, err = ctx.graph.HasChannelEdge(t.Context(), chanID1)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.True(t, has)
|
require.True(t, has)
|
||||||
require.False(t, isZombie)
|
require.False(t, isZombie)
|
||||||
|
|
||||||
has, isZombie, err = ctx.graph.HasChannelEdge(chanID2)
|
has, isZombie, err = ctx.graph.HasChannelEdge(t.Context(), chanID2)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.False(t, has)
|
require.False(t, has)
|
||||||
require.False(t, isZombie)
|
require.False(t, isZombie)
|
||||||
@@ -594,7 +594,7 @@ func TestChansClosedOfflinePruneGraph(t *testing.T) {
|
|||||||
|
|
||||||
// The router should now be aware of the channel we created above.
|
// The router should now be aware of the channel we created above.
|
||||||
hasChan, isZombie, err := ctx.graph.HasChannelEdge(
|
hasChan, isZombie, err := ctx.graph.HasChannelEdge(
|
||||||
chanID1.ToUint64(),
|
t.Context(), chanID1.ToUint64(),
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.True(t, hasChan)
|
require.True(t, hasChan)
|
||||||
@@ -662,7 +662,7 @@ func TestChansClosedOfflinePruneGraph(t *testing.T) {
|
|||||||
// At this point, the channel that was pruned should no longer be known
|
// At this point, the channel that was pruned should no longer be known
|
||||||
// by the router.
|
// by the router.
|
||||||
hasChan, isZombie, err = ctx.graph.HasChannelEdge(
|
hasChan, isZombie, err = ctx.graph.HasChannelEdge(
|
||||||
chanID1.ToUint64(),
|
t.Context(), chanID1.ToUint64(),
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.False(t, hasChan)
|
require.False(t, hasChan)
|
||||||
@@ -1611,7 +1611,7 @@ func assertChannelsPruned(t *testing.T, graph *graphdb.VersionedGraph,
|
|||||||
for _, channel := range channels {
|
for _, channel := range channels {
|
||||||
_, shouldPrune := pruned[channel.ChannelID]
|
_, shouldPrune := pruned[channel.ChannelID]
|
||||||
exists, isZombie, err := graph.HasChannelEdge(
|
exists, isZombie, err := graph.HasChannelEdge(
|
||||||
channel.ChannelID,
|
t.Context(), channel.ChannelID,
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
if shouldPrune {
|
if shouldPrune {
|
||||||
|
|||||||
+7
-5
@@ -681,10 +681,10 @@ func (c *ChannelGraph) HasV1ChannelEdge(ctx context.Context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// HasChannelEdge returns true if the database knows of a channel edge.
|
// HasChannelEdge returns true if the database knows of a channel edge.
|
||||||
func (c *ChannelGraph) HasChannelEdge(v lnwire.GossipVersion,
|
func (c *ChannelGraph) HasChannelEdge(ctx context.Context,
|
||||||
chanID uint64) (bool, bool, error) {
|
v lnwire.GossipVersion, chanID uint64) (bool, bool, error) {
|
||||||
|
|
||||||
return c.db.HasChannelEdge(v, chanID)
|
return c.db.HasChannelEdge(ctx, v, chanID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddEdgeProof sets the proof of an existing edge in the graph database.
|
// AddEdgeProof sets the proof of an existing edge in the graph database.
|
||||||
@@ -919,8 +919,10 @@ func (c *VersionedGraph) DeleteChannelEdges(ctx context.Context,
|
|||||||
// passed channel ID and this graph's gossip version, and false otherwise. If it
|
// passed channel ID and this graph's gossip version, and false otherwise. If it
|
||||||
// is not found, then the zombie index is checked and its result is returned as
|
// is not found, then the zombie index is checked and its result is returned as
|
||||||
// the second boolean.
|
// the second boolean.
|
||||||
func (c *VersionedGraph) HasChannelEdge(chanID uint64) (bool, bool, error) {
|
func (c *VersionedGraph) HasChannelEdge(ctx context.Context,
|
||||||
return c.db.HasChannelEdge(c.v, chanID)
|
chanID uint64) (bool, bool, error) {
|
||||||
|
|
||||||
|
return c.db.HasChannelEdge(ctx, c.v, chanID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ForEachSourceNodeChannel iterates through all channels of the source node.
|
// ForEachSourceNodeChannel iterates through all channels of the source node.
|
||||||
|
|||||||
@@ -918,13 +918,13 @@ func TestDisconnectBlockAtHeight(t *testing.T) {
|
|||||||
|
|
||||||
// The two first edges should be removed from the db.
|
// The two first edges should be removed from the db.
|
||||||
has, isZombie, err := graph.HasChannelEdge(
|
has, isZombie, err := graph.HasChannelEdge(
|
||||||
lnwire.GossipVersion1, edgeInfo.ChannelID,
|
ctx, lnwire.GossipVersion1, edgeInfo.ChannelID,
|
||||||
)
|
)
|
||||||
require.NoError(t, err, "unable to query for edge")
|
require.NoError(t, err, "unable to query for edge")
|
||||||
require.False(t, has)
|
require.False(t, has)
|
||||||
require.False(t, isZombie)
|
require.False(t, isZombie)
|
||||||
has, isZombie, err = graph.HasChannelEdge(
|
has, isZombie, err = graph.HasChannelEdge(
|
||||||
lnwire.GossipVersion1, edgeInfo2.ChannelID,
|
ctx, lnwire.GossipVersion1, edgeInfo2.ChannelID,
|
||||||
)
|
)
|
||||||
require.NoError(t, err, "unable to query for edge")
|
require.NoError(t, err, "unable to query for edge")
|
||||||
require.False(t, has)
|
require.False(t, has)
|
||||||
@@ -932,7 +932,7 @@ func TestDisconnectBlockAtHeight(t *testing.T) {
|
|||||||
|
|
||||||
// Edge 3 should not be removed.
|
// Edge 3 should not be removed.
|
||||||
has, isZombie, err = graph.HasChannelEdge(
|
has, isZombie, err = graph.HasChannelEdge(
|
||||||
lnwire.GossipVersion1, edgeInfo3.ChannelID,
|
ctx, lnwire.GossipVersion1, edgeInfo3.ChannelID,
|
||||||
)
|
)
|
||||||
require.NoError(t, err, "unable to query for edge")
|
require.NoError(t, err, "unable to query for edge")
|
||||||
require.True(t, has)
|
require.True(t, has)
|
||||||
@@ -1184,7 +1184,7 @@ func testEdgeInfoUpdates(t *testing.T, v lnwire.GossipVersion) {
|
|||||||
|
|
||||||
// Check for existence of the edge within the database, it should be
|
// Check for existence of the edge within the database, it should be
|
||||||
// found.
|
// found.
|
||||||
found, isZombie, err := graph.HasChannelEdge(chanID)
|
found, isZombie, err := graph.HasChannelEdge(ctx, chanID)
|
||||||
require.NoError(t, err, "unable to query for edge")
|
require.NoError(t, err, "unable to query for edge")
|
||||||
require.True(t, found)
|
require.True(t, found)
|
||||||
require.False(t, isZombie)
|
require.False(t, isZombie)
|
||||||
@@ -3360,7 +3360,7 @@ func TestStressTestChannelGraphAPI(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, _, err := graph.HasChannelEdge(
|
_, _, err := graph.HasChannelEdge(
|
||||||
lnwire.GossipVersion1,
|
ctx, lnwire.GossipVersion1,
|
||||||
channel.id.ToUint64(),
|
channel.id.ToUint64(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -218,8 +218,8 @@ type Store interface { //nolint:interfacebloat
|
|||||||
// with the passed channel ID and gossip version, and false otherwise.
|
// with the passed channel ID and gossip version, and false otherwise.
|
||||||
// If it is not found, then the zombie index is checked and its result
|
// If it is not found, then the zombie index is checked and its result
|
||||||
// is returned as the second boolean.
|
// is returned as the second boolean.
|
||||||
HasChannelEdge(v lnwire.GossipVersion, chanID uint64) (bool, bool,
|
HasChannelEdge(ctx context.Context, v lnwire.GossipVersion,
|
||||||
error)
|
chanID uint64) (bool, bool, error)
|
||||||
|
|
||||||
// DeleteChannelEdges removes edges with the given channel IDs from the
|
// DeleteChannelEdges removes edges with the given channel IDs from the
|
||||||
// database and marks them as zombies. This ensures that we're unable to
|
// database and marks them as zombies. This ensures that we're unable to
|
||||||
|
|||||||
@@ -1427,16 +1427,14 @@ func (c *KVStore) HasV1ChannelEdge(_ context.Context,
|
|||||||
// passed channel ID and gossip version, and false otherwise. If it is not
|
// passed channel ID and gossip version, and false otherwise. If it is not
|
||||||
// found, then the zombie index is checked and its result is returned as the
|
// found, then the zombie index is checked and its result is returned as the
|
||||||
// second boolean.
|
// second boolean.
|
||||||
func (c *KVStore) HasChannelEdge(v lnwire.GossipVersion,
|
func (c *KVStore) HasChannelEdge(ctx context.Context, v lnwire.GossipVersion,
|
||||||
chanID uint64) (bool, bool, error) {
|
chanID uint64) (bool, bool, error) {
|
||||||
|
|
||||||
if v != lnwire.GossipVersion1 {
|
if v != lnwire.GossipVersion1 {
|
||||||
return false, false, ErrVersionNotSupportedForKVDB
|
return false, false, ErrVersionNotSupportedForKVDB
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _, exists, isZombie, err := c.HasV1ChannelEdge(
|
_, _, exists, isZombie, err := c.HasV1ChannelEdge(ctx, chanID)
|
||||||
context.TODO(), chanID,
|
|
||||||
)
|
|
||||||
|
|
||||||
return exists, isZombie, err
|
return exists, isZombie, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2361,8 +2361,8 @@ func (s *SQLStore) HasV1ChannelEdge(ctx context.Context,
|
|||||||
// result is returned as the second boolean.
|
// result is returned as the second boolean.
|
||||||
//
|
//
|
||||||
// NOTE: part of the Store interface.
|
// NOTE: part of the Store interface.
|
||||||
func (s *SQLStore) HasChannelEdge(v lnwire.GossipVersion,
|
func (s *SQLStore) HasChannelEdge(ctx context.Context,
|
||||||
chanID uint64) (bool, bool, error) {
|
v lnwire.GossipVersion, chanID uint64) (bool, bool, error) {
|
||||||
|
|
||||||
if !isKnownGossipVersion(v) {
|
if !isKnownGossipVersion(v) {
|
||||||
return false, false, fmt.Errorf(
|
return false, false, fmt.Errorf(
|
||||||
@@ -2370,8 +2370,6 @@ func (s *SQLStore) HasChannelEdge(v lnwire.GossipVersion,
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.TODO()
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
exists bool
|
exists bool
|
||||||
isZombie bool
|
isZombie bool
|
||||||
|
|||||||
Reference in new issue
Block a user