graph/db: thread context through FetchChannelEdgesByID
This commit is contained in:
14 files changed
+93
-42
No files matched your search
+6
-4
@@ -739,12 +739,13 @@ func (c *ChannelGraph) FetchChannelEdgesByOutpoint(op *wire.OutPoint) (
|
||||
}
|
||||
|
||||
// FetchChannelEdgesByID attempts to lookup directed edges by channel ID.
|
||||
func (c *ChannelGraph) FetchChannelEdgesByID(chanID uint64) (
|
||||
func (c *ChannelGraph) FetchChannelEdgesByID(ctx context.Context,
|
||||
chanID uint64) (
|
||||
*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||
*models.ChannelEdgePolicy, error) {
|
||||
|
||||
return c.db.FetchChannelEdgesByID(
|
||||
lnwire.GossipVersion1, chanID,
|
||||
ctx, lnwire.GossipVersion1, chanID,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -812,11 +813,12 @@ func (c *VersionedGraph) FetchNode(ctx context.Context,
|
||||
}
|
||||
|
||||
// FetchChannelEdgesByID attempts to lookup directed edges by channel ID.
|
||||
func (c *VersionedGraph) FetchChannelEdgesByID(chanID uint64) (
|
||||
func (c *VersionedGraph) FetchChannelEdgesByID(ctx context.Context,
|
||||
chanID uint64) (
|
||||
*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||
*models.ChannelEdgePolicy, error) {
|
||||
|
||||
return c.db.FetchChannelEdgesByID(c.v, chanID)
|
||||
return c.db.FetchChannelEdgesByID(ctx, c.v, chanID)
|
||||
}
|
||||
|
||||
// FetchChannelEdgesByOutpoint attempts to lookup directed edges by funding
|
||||
|
||||
+20
-8
@@ -643,7 +643,7 @@ func testEdgeInsertionDeletion(t *testing.T, v lnwire.GossipVersion) {
|
||||
|
||||
// Ensure that both policies are returned as unknown (nil) and that
|
||||
// the edge info round-trips correctly.
|
||||
dbEdge, e1, e2, err := graph.FetchChannelEdgesByID(chanID)
|
||||
dbEdge, e1, e2, err := graph.FetchChannelEdgesByID(ctx, chanID)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, e1)
|
||||
require.Nil(t, e2)
|
||||
@@ -712,7 +712,7 @@ func testEdgeInsertionDeletion(t *testing.T, v lnwire.GossipVersion) {
|
||||
// Assert that if the edge is a zombie, then FetchChannelEdgesByID
|
||||
// still returns a populated models.ChannelEdgeInfo as its comment
|
||||
// description promises.
|
||||
edge, _, _, err := graph.FetchChannelEdgesByID(chanID)
|
||||
edge, _, _, err := graph.FetchChannelEdgesByID(ctx, chanID)
|
||||
require.ErrorIs(t, err, ErrZombieEdge)
|
||||
require.NotNil(t, edge)
|
||||
|
||||
@@ -1195,7 +1195,9 @@ func testEdgeInfoUpdates(t *testing.T, v lnwire.GossipVersion) {
|
||||
|
||||
// With the edges inserted, perform some queries to ensure that they've
|
||||
// been inserted properly.
|
||||
dbEdgeInfo, dbEdge1, dbEdge2, err := graph.FetchChannelEdgesByID(chanID)
|
||||
dbEdgeInfo, dbEdge1, dbEdge2, err := graph.FetchChannelEdgesByID(
|
||||
ctx, chanID,
|
||||
)
|
||||
require.NoError(t, err, "unable to fetch channel by ID")
|
||||
compareEdgePolicies(t, dbEdge1, edge1)
|
||||
compareEdgePolicies(t, dbEdge2, edge2)
|
||||
@@ -1578,7 +1580,9 @@ func testAddEdgeProof(t *testing.T, v lnwire.GossipVersion) {
|
||||
require.NoError(t, graph.AddChannelEdge(ctx, edge1))
|
||||
|
||||
// Fetch the edge and assert that the proof is nil.
|
||||
dbEdge, _, _, err := graph.FetchChannelEdgesByID(edge1.ChannelID)
|
||||
dbEdge, _, _, err := graph.FetchChannelEdgesByID(
|
||||
ctx, edge1.ChannelID,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, dbEdge.AuthProof)
|
||||
|
||||
@@ -1608,7 +1612,9 @@ func testAddEdgeProof(t *testing.T, v lnwire.GossipVersion) {
|
||||
require.NoError(t, graph.AddEdgeProof(scid1, proof))
|
||||
|
||||
// Fetch the edge again and assert that the proof is now set.
|
||||
dbEdge, _, _, err = graph.FetchChannelEdgesByID(edge1.ChannelID)
|
||||
dbEdge, _, _, err = graph.FetchChannelEdgesByID(
|
||||
ctx, edge1.ChannelID,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, dbEdge.AuthProof)
|
||||
|
||||
@@ -1618,7 +1624,9 @@ func testAddEdgeProof(t *testing.T, v lnwire.GossipVersion) {
|
||||
require.NoError(t, graph.AddChannelEdge(ctx, edge2))
|
||||
|
||||
// Fetch the edge and assert that the proof is set.
|
||||
dbEdge2, _, _, err := graph.FetchChannelEdgesByID(edge2.ChannelID)
|
||||
dbEdge2, _, _, err := graph.FetchChannelEdgesByID(
|
||||
ctx, edge2.ChannelID,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, dbEdge2.AuthProof)
|
||||
}
|
||||
@@ -4486,7 +4494,9 @@ func TestEdgePolicyMissingMaxHTLC(t *testing.T) {
|
||||
// we added is invalid according to the new format, it should be as we
|
||||
// are not aware of the policy (indicated by the policy returned being
|
||||
// nil)
|
||||
dbEdgeInfo, dbEdge1, dbEdge2, err := graph.FetchChannelEdgesByID(chanID)
|
||||
dbEdgeInfo, dbEdge1, dbEdge2, err := graph.FetchChannelEdgesByID(
|
||||
ctx, chanID,
|
||||
)
|
||||
require.NoError(t, err, "unable to fetch channel by ID")
|
||||
|
||||
// The first edge should have a nil-policy returned
|
||||
@@ -4498,7 +4508,9 @@ func TestEdgePolicyMissingMaxHTLC(t *testing.T) {
|
||||
// policies then become fully populated.
|
||||
require.NoError(t, graph.UpdateEdgePolicy(ctx, edge1))
|
||||
|
||||
dbEdgeInfo, dbEdge1, dbEdge2, err = graph.FetchChannelEdgesByID(chanID)
|
||||
dbEdgeInfo, dbEdge1, dbEdge2, err = graph.FetchChannelEdgesByID(
|
||||
ctx, chanID,
|
||||
)
|
||||
require.NoError(t, err, "unable to fetch channel by ID")
|
||||
compareEdgePolicies(t, dbEdge1, edge1)
|
||||
compareEdgePolicies(t, dbEdge2, edge2)
|
||||
|
||||
@@ -311,7 +311,8 @@ type Store interface { //nolint:interfacebloat
|
||||
// zombie within the database. In this case, the ChannelEdgePolicy's
|
||||
// will be nil, and the ChannelEdgeInfo will only include the public
|
||||
// keys of each node.
|
||||
FetchChannelEdgesByID(v lnwire.GossipVersion, chanID uint64) (
|
||||
FetchChannelEdgesByID(ctx context.Context, v lnwire.GossipVersion,
|
||||
chanID uint64) (
|
||||
*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||
*models.ChannelEdgePolicy, error)
|
||||
|
||||
|
||||
@@ -3989,8 +3989,9 @@ func (c *KVStore) FetchChannelEdgesByOutpoint(v lnwire.GossipVersion,
|
||||
// ErrZombieEdge an be returned if the edge is currently marked as a zombie
|
||||
// within the database. In this case, the ChannelEdgePolicy's will be nil, and
|
||||
// the ChannelEdgeInfo will only include the public keys of each node.
|
||||
func (c *KVStore) FetchChannelEdgesByID(v lnwire.GossipVersion,
|
||||
chanID uint64) (*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||
func (c *KVStore) FetchChannelEdgesByID(_ context.Context,
|
||||
v lnwire.GossipVersion, chanID uint64) (
|
||||
*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||
*models.ChannelEdgePolicy, error) {
|
||||
|
||||
if v != lnwire.GossipVersion1 {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package graphdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"image/color"
|
||||
@@ -412,7 +413,9 @@ func (c *ChannelGraph) addToTopologyChange(update *TopologyChange,
|
||||
// We'll need to fetch the edge's information from the database
|
||||
// in order to get the information concerning which nodes are
|
||||
// being connected.
|
||||
edgeInfo, _, _, err := c.FetchChannelEdgesByID(m.ChannelID)
|
||||
edgeInfo, _, _, err := c.FetchChannelEdgesByID(
|
||||
context.TODO(), m.ChannelID,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable fetch channel edge: %w", err)
|
||||
}
|
||||
|
||||
@@ -2050,12 +2050,12 @@ func (s *SQLStore) DeleteChannelEdges(ctx context.Context,
|
||||
// the ChannelEdgeInfo will only include the public keys of each node.
|
||||
//
|
||||
// NOTE: part of the Store interface.
|
||||
func (s *SQLStore) FetchChannelEdgesByID(v lnwire.GossipVersion,
|
||||
chanID uint64) (*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||
func (s *SQLStore) FetchChannelEdgesByID(ctx context.Context,
|
||||
v lnwire.GossipVersion, chanID uint64) (
|
||||
*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||
*models.ChannelEdgePolicy, error) {
|
||||
|
||||
var (
|
||||
ctx = context.TODO()
|
||||
edge *models.ChannelEdgeInfo
|
||||
policy1, policy2 *models.ChannelEdgePolicy
|
||||
chanIDB = channelIDToBytes(chanID)
|
||||
|
||||
Reference in new issue
Block a user