graph/db: thread context through FetchChannelEdgesByOutpoint
This commit is contained in:
10 files changed
+33
-19
No files matched your search
+6
-4
@@ -729,12 +729,13 @@ func (c *ChannelGraph) FetchChanInfos(v lnwire.GossipVersion,
|
||||
|
||||
// FetchChannelEdgesByOutpoint attempts to lookup directed edges by funding
|
||||
// outpoint.
|
||||
func (c *ChannelGraph) FetchChannelEdgesByOutpoint(op *wire.OutPoint) (
|
||||
func (c *ChannelGraph) FetchChannelEdgesByOutpoint(ctx context.Context,
|
||||
op *wire.OutPoint) (
|
||||
*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||
*models.ChannelEdgePolicy, error) {
|
||||
|
||||
return c.db.FetchChannelEdgesByOutpoint(
|
||||
lnwire.GossipVersion1, op,
|
||||
ctx, lnwire.GossipVersion1, op,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -823,11 +824,12 @@ func (c *VersionedGraph) FetchChannelEdgesByID(ctx context.Context,
|
||||
|
||||
// FetchChannelEdgesByOutpoint attempts to lookup directed edges by funding
|
||||
// outpoint.
|
||||
func (c *VersionedGraph) FetchChannelEdgesByOutpoint(op *wire.OutPoint) (
|
||||
func (c *VersionedGraph) FetchChannelEdgesByOutpoint(ctx context.Context,
|
||||
op *wire.OutPoint) (
|
||||
*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||
*models.ChannelEdgePolicy, error) {
|
||||
|
||||
return c.db.FetchChannelEdgesByOutpoint(c.v, op)
|
||||
return c.db.FetchChannelEdgesByOutpoint(ctx, c.v, op)
|
||||
}
|
||||
|
||||
// IsZombieEdge returns whether the edge is considered zombie for this version.
|
||||
|
||||
@@ -693,7 +693,9 @@ func testEdgeInsertionDeletion(t *testing.T, v lnwire.GossipVersion) {
|
||||
}
|
||||
|
||||
// Also verify fetching by outpoint returns the same data.
|
||||
dbEdge2, _, _, err := graph.FetchChannelEdgesByOutpoint(&outpoint)
|
||||
dbEdge2, _, _, err := graph.FetchChannelEdgesByOutpoint(
|
||||
ctx, &outpoint,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, dbEdge.ChannelID, dbEdge2.ChannelID)
|
||||
|
||||
@@ -706,7 +708,7 @@ func testEdgeInsertionDeletion(t *testing.T, v lnwire.GossipVersion) {
|
||||
|
||||
// Ensure that any query attempts to lookup the delete channel edge are
|
||||
// properly deleted.
|
||||
_, _, _, err = graph.FetchChannelEdgesByOutpoint(&outpoint)
|
||||
_, _, _, err = graph.FetchChannelEdgesByOutpoint(ctx, &outpoint)
|
||||
require.ErrorIs(t, err, ErrEdgeNotFound)
|
||||
|
||||
// Assert that if the edge is a zombie, then FetchChannelEdgesByID
|
||||
@@ -1206,7 +1208,7 @@ func testEdgeInfoUpdates(t *testing.T, v lnwire.GossipVersion) {
|
||||
// Next, attempt to query the channel edges according to the outpoint
|
||||
// of the channel.
|
||||
dbEdgeInfo, dbEdge1, dbEdge2, err = graph.FetchChannelEdgesByOutpoint(
|
||||
&outpoint,
|
||||
ctx, &outpoint,
|
||||
)
|
||||
require.NoError(t, err, "unable to fetch channel by ID")
|
||||
compareEdgePolicies(t, dbEdge1, edge1)
|
||||
|
||||
@@ -296,7 +296,8 @@ type Store interface { //nolint:interfacebloat
|
||||
// houses the general information for the channel itself is returned as
|
||||
// well as two structs that contain the routing policies for the channel
|
||||
// in either direction.
|
||||
FetchChannelEdgesByOutpoint(v lnwire.GossipVersion, op *wire.OutPoint) (
|
||||
FetchChannelEdgesByOutpoint(ctx context.Context,
|
||||
v lnwire.GossipVersion, op *wire.OutPoint) (
|
||||
*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||
*models.ChannelEdgePolicy, error)
|
||||
|
||||
|
||||
@@ -3899,8 +3899,9 @@ func computeEdgePolicyKeys(info *models.ChannelEdgeInfo) ([]byte, []byte) {
|
||||
// found, then ErrEdgeNotFound is returned. A struct which houses the general
|
||||
// information for the channel itself is returned as well as two structs that
|
||||
// contain the routing policies for the channel in either direction.
|
||||
func (c *KVStore) FetchChannelEdgesByOutpoint(v lnwire.GossipVersion,
|
||||
op *wire.OutPoint) (*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||
func (c *KVStore) FetchChannelEdgesByOutpoint(_ context.Context,
|
||||
v lnwire.GossipVersion, op *wire.OutPoint) (
|
||||
*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||
*models.ChannelEdgePolicy, error) {
|
||||
|
||||
var (
|
||||
|
||||
@@ -2167,12 +2167,12 @@ func (s *SQLStore) FetchChannelEdgesByID(ctx context.Context,
|
||||
// contain the routing policies for the channel in either direction.
|
||||
//
|
||||
// NOTE: part of the Store interface.
|
||||
func (s *SQLStore) FetchChannelEdgesByOutpoint(v lnwire.GossipVersion,
|
||||
op *wire.OutPoint) (*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||
func (s *SQLStore) FetchChannelEdgesByOutpoint(ctx context.Context,
|
||||
v lnwire.GossipVersion, op *wire.OutPoint) (
|
||||
*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||
*models.ChannelEdgePolicy, error) {
|
||||
|
||||
var (
|
||||
ctx = context.TODO()
|
||||
edge *models.ChannelEdgeInfo
|
||||
policy1, policy2 *models.ChannelEdgePolicy
|
||||
)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package netann
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -654,7 +655,9 @@ func (m *ChanStatusManager) fetchLastChanUpdateByOutPoint(op wire.OutPoint) (
|
||||
*lnwire.ChannelUpdate1, bool, error) {
|
||||
|
||||
// Get the edge info and policies for this channel from the graph.
|
||||
info, edge1, edge2, err := m.cfg.Graph.FetchChannelEdgesByOutpoint(&op)
|
||||
info, edge1, edge2, err := m.cfg.Graph.FetchChannelEdgesByOutpoint(
|
||||
context.TODO(), &op,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package netann_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
@@ -173,7 +174,8 @@ func (g *mockGraph) FetchAllOpenChannels() ([]*channeldb.OpenChannel, error) {
|
||||
}
|
||||
|
||||
func (g *mockGraph) FetchChannelEdgesByOutpoint(
|
||||
op *wire.OutPoint) (*models.ChannelEdgeInfo,
|
||||
_ context.Context, op *wire.OutPoint) (
|
||||
*models.ChannelEdgeInfo,
|
||||
*models.ChannelEdgePolicy, *models.ChannelEdgePolicy, error) {
|
||||
|
||||
g.mu.Lock()
|
||||
|
||||
+5
-2
@@ -1,6 +1,8 @@
|
||||
package netann
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||
@@ -19,6 +21,7 @@ type DB interface {
|
||||
type ChannelGraph interface {
|
||||
// FetchChannelEdgesByOutpoint returns the channel edge info and most
|
||||
// recent channel edge policies for a given outpoint.
|
||||
FetchChannelEdgesByOutpoint(*wire.OutPoint) (*models.ChannelEdgeInfo,
|
||||
*models.ChannelEdgePolicy, *models.ChannelEdgePolicy, error)
|
||||
FetchChannelEdgesByOutpoint(context.Context, *wire.OutPoint) (
|
||||
*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||
*models.ChannelEdgePolicy, error)
|
||||
}
|
||||
+1
-1
@@ -1217,7 +1217,7 @@ func (p *Brontide) loadActiveChannels(chans []*channeldb.OpenChannel) (
|
||||
// the database.
|
||||
graph := p.cfg.ChannelGraph
|
||||
info, p1, p2, err := graph.FetchChannelEdgesByOutpoint(
|
||||
&chanPoint,
|
||||
context.TODO(), &chanPoint,
|
||||
)
|
||||
if err != nil && !errors.Is(err, graphdb.ErrEdgeNotFound) {
|
||||
return nil, err
|
||||
|
||||
+1
-1
@@ -7132,7 +7132,7 @@ func (r *rpcServer) GetChanInfo(ctx context.Context,
|
||||
return nil, err
|
||||
}
|
||||
edgeInfo, edge1, edge2, err = graph.FetchChannelEdgesByOutpoint(
|
||||
chanPoint,
|
||||
ctx, chanPoint,
|
||||
)
|
||||
|
||||
default:
|
||||
|
||||
Reference in new issue
Block a user