netann+lnd: add netann.ChannelGraph to the GraphSource interface

And let DBSource implement it.
This commit is contained in:
Elle Mouton
2024-11-11 16:48:58 +02:00
parent 6f3d45f5d9
commit 237151d9df
7 changed files with 30 additions and 6 deletions

View File

@@ -4,6 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"github.com/btcsuite/btcd/wire"
graphdb "github.com/lightningnetwork/lnd/graph/db" graphdb "github.com/lightningnetwork/lnd/graph/db"
"github.com/lightningnetwork/lnd/graph/db/models" "github.com/lightningnetwork/lnd/graph/db/models"
"github.com/lightningnetwork/lnd/graph/session" "github.com/lightningnetwork/lnd/graph/session"
@@ -105,6 +106,17 @@ func (s *DBSource) IsPublicNode(_ context.Context,
return s.db.IsPublicNode(pubKey) return s.db.IsPublicNode(pubKey)
} }
// FetchChannelEdgesByOutpoint returns the channel edge info and most recent
// channel edge policies for a given outpoint.
//
// NOTE: this is part of the netann.ChannelGraph interface.
func (s *DBSource) FetchChannelEdgesByOutpoint(_ context.Context,
point *wire.OutPoint) (*models.ChannelEdgeInfo,
*models.ChannelEdgePolicy, *models.ChannelEdgePolicy, error) {
return s.db.FetchChannelEdgesByOutpoint(point)
}
// kvdbRTx is an implementation of graphdb.RTx backed by a KVDB database read // kvdbRTx is an implementation of graphdb.RTx backed by a KVDB database read
// transaction. // transaction.
type kvdbRTx struct { type kvdbRTx struct {

View File

@@ -3,6 +3,7 @@ package sources
import ( import (
"github.com/lightningnetwork/lnd/graph/session" "github.com/lightningnetwork/lnd/graph/session"
"github.com/lightningnetwork/lnd/lnrpc/invoicesrpc" "github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
"github.com/lightningnetwork/lnd/netann"
) )
// GraphSource defines the read-only graph interface required by LND for graph // GraphSource defines the read-only graph interface required by LND for graph
@@ -10,4 +11,5 @@ import (
type GraphSource interface { type GraphSource interface {
session.ReadOnlyGraph session.ReadOnlyGraph
invoicesrpc.GraphSource invoicesrpc.GraphSource
netann.ChannelGraph
} }

View File

@@ -1,6 +1,7 @@
package netann package netann
import ( import (
"context"
"errors" "errors"
"sync" "sync"
"time" "time"
@@ -653,8 +654,12 @@ func (m *ChanStatusManager) signAndSendNextUpdate(outpoint wire.OutPoint,
func (m *ChanStatusManager) fetchLastChanUpdateByOutPoint(op wire.OutPoint) ( func (m *ChanStatusManager) fetchLastChanUpdateByOutPoint(op wire.OutPoint) (
*lnwire.ChannelUpdate1, bool, error) { *lnwire.ChannelUpdate1, bool, error) {
ctx := context.TODO()
// 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(
ctx, &op,
)
if err != nil { if err != nil {
return nil, false, err return nil, false, err
} }

View File

@@ -2,6 +2,7 @@ package netann_test
import ( import (
"bytes" "bytes"
"context"
"crypto/rand" "crypto/rand"
"encoding/binary" "encoding/binary"
"fmt" "fmt"
@@ -160,7 +161,7 @@ func (g *mockGraph) FetchAllOpenChannels() ([]*channeldb.OpenChannel, error) {
return g.chans(), nil return g.chans(), nil
} }
func (g *mockGraph) FetchChannelEdgesByOutpoint( func (g *mockGraph) FetchChannelEdgesByOutpoint(ctx context.Context,
op *wire.OutPoint) (*models.ChannelEdgeInfo, op *wire.OutPoint) (*models.ChannelEdgeInfo,
*models.ChannelEdgePolicy, *models.ChannelEdgePolicy, error) { *models.ChannelEdgePolicy, *models.ChannelEdgePolicy, error) {

View File

@@ -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)
} }

View File

@@ -20,6 +20,7 @@ import (
"github.com/lightningnetwork/lnd/channelnotifier" "github.com/lightningnetwork/lnd/channelnotifier"
"github.com/lightningnetwork/lnd/fn" "github.com/lightningnetwork/lnd/fn"
graphdb "github.com/lightningnetwork/lnd/graph/db" graphdb "github.com/lightningnetwork/lnd/graph/db"
"github.com/lightningnetwork/lnd/graph/sources"
"github.com/lightningnetwork/lnd/htlcswitch" "github.com/lightningnetwork/lnd/htlcswitch"
"github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/keychain" "github.com/lightningnetwork/lnd/keychain"
@@ -628,7 +629,7 @@ func createTestPeer(t *testing.T) *peerTestCtx {
ChanEnableTimeout: chanActiveTimeout, ChanEnableTimeout: chanActiveTimeout,
ChanDisableTimeout: 2 * time.Minute, ChanDisableTimeout: 2 * time.Minute,
DB: dbAliceChannel.ChannelStateDB(), DB: dbAliceChannel.ChannelStateDB(),
Graph: dbAliceGraph, Graph: sources.NewDBGSource(dbAliceGraph),
MessageSigner: nodeSignerAlice, MessageSigner: nodeSignerAlice,
OurPubKey: aliceKeyPub, OurPubKey: aliceKeyPub,
OurKeyLoc: testKeyLoc, OurKeyLoc: testKeyLoc,

View File

@@ -772,7 +772,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
IsChannelActive: s.htlcSwitch.HasActiveLink, IsChannelActive: s.htlcSwitch.HasActiveLink,
ApplyChannelUpdate: s.applyChannelUpdate, ApplyChannelUpdate: s.applyChannelUpdate,
DB: s.chanStateDB, DB: s.chanStateDB,
Graph: dbs.GraphDB, Graph: graphSource,
} }
chanStatusMgr, err := netann.NewChanStatusManager(chanStatusMgrCfg) chanStatusMgr, err := netann.NewChanStatusManager(chanStatusMgrCfg)