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