mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-04-09 20:49:08 +02:00
refactor: move graph related DB code to graph/db from channeldb
This is a pure refactor commit. It moves over all the graph related CRUD code from `channeldb` to `graph/db`.
This commit is contained in:
parent
9f54ec90aa
commit
74a4b1922b
@ -11,7 +11,7 @@ import (
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
|
||||
"github.com/btcsuite/btcd/btcutil"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||
"github.com/lightningnetwork/lnd/kvdb"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
@ -35,7 +35,7 @@ var (
|
||||
//
|
||||
// TODO(roasbeef): move inmpl to main package?
|
||||
type databaseChannelGraph struct {
|
||||
db *channeldb.ChannelGraph
|
||||
db *graphdb.ChannelGraph
|
||||
}
|
||||
|
||||
// A compile time assertion to ensure databaseChannelGraph meets the
|
||||
@ -44,7 +44,7 @@ var _ ChannelGraph = (*databaseChannelGraph)(nil)
|
||||
|
||||
// ChannelGraphFromDatabase returns an instance of the autopilot.ChannelGraph
|
||||
// backed by a live, open channeldb instance.
|
||||
func ChannelGraphFromDatabase(db *channeldb.ChannelGraph) ChannelGraph {
|
||||
func ChannelGraphFromDatabase(db *graphdb.ChannelGraph) ChannelGraph {
|
||||
return &databaseChannelGraph{
|
||||
db: db,
|
||||
}
|
||||
@ -54,11 +54,11 @@ func ChannelGraphFromDatabase(db *channeldb.ChannelGraph) ChannelGraph {
|
||||
// channeldb.LightningNode. The wrapper method implement the autopilot.Node
|
||||
// interface.
|
||||
type dbNode struct {
|
||||
db *channeldb.ChannelGraph
|
||||
db *graphdb.ChannelGraph
|
||||
|
||||
tx kvdb.RTx
|
||||
|
||||
node *channeldb.LightningNode
|
||||
node *graphdb.LightningNode
|
||||
}
|
||||
|
||||
// A compile time assertion to ensure dbNode meets the autopilot.Node
|
||||
@ -134,7 +134,7 @@ func (d *dbNode) ForEachChannel(cb func(ChannelEdge) error) error {
|
||||
//
|
||||
// NOTE: Part of the autopilot.ChannelGraph interface.
|
||||
func (d *databaseChannelGraph) ForEachNode(cb func(Node) error) error {
|
||||
return d.db.ForEachNode(func(tx kvdb.RTx, n *channeldb.LightningNode) error {
|
||||
return d.db.ForEachNode(func(tx kvdb.RTx, n *graphdb.LightningNode) error {
|
||||
// We'll skip over any node that doesn't have any advertised
|
||||
// addresses. As we won't be able to reach them to actually
|
||||
// open any channels.
|
||||
@ -157,7 +157,7 @@ func (d *databaseChannelGraph) ForEachNode(cb func(Node) error) error {
|
||||
func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
|
||||
capacity btcutil.Amount) (*ChannelEdge, *ChannelEdge, error) {
|
||||
|
||||
fetchNode := func(pub *btcec.PublicKey) (*channeldb.LightningNode, error) {
|
||||
fetchNode := func(pub *btcec.PublicKey) (*graphdb.LightningNode, error) {
|
||||
if pub != nil {
|
||||
vertex, err := route.NewVertexFromBytes(
|
||||
pub.SerializeCompressed(),
|
||||
@ -168,10 +168,10 @@ func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
|
||||
|
||||
dbNode, err := d.db.FetchLightningNode(vertex)
|
||||
switch {
|
||||
case err == channeldb.ErrGraphNodeNotFound:
|
||||
case err == graphdb.ErrGraphNodeNotFound:
|
||||
fallthrough
|
||||
case err == channeldb.ErrGraphNotFound:
|
||||
graphNode := &channeldb.LightningNode{
|
||||
case err == graphdb.ErrGraphNotFound:
|
||||
graphNode := &graphdb.LightningNode{
|
||||
HaveNodeAnnouncement: true,
|
||||
Addresses: []net.Addr{
|
||||
&net.TCPAddr{
|
||||
@ -198,7 +198,7 @@ func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dbNode := &channeldb.LightningNode{
|
||||
dbNode := &graphdb.LightningNode{
|
||||
HaveNodeAnnouncement: true,
|
||||
Addresses: []net.Addr{
|
||||
&net.TCPAddr{
|
||||
@ -302,7 +302,7 @@ func (d *databaseChannelGraph) addRandNode() (*btcec.PublicKey, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dbNode := &channeldb.LightningNode{
|
||||
dbNode := &graphdb.LightningNode{
|
||||
HaveNodeAnnouncement: true,
|
||||
Addresses: []net.Addr{
|
||||
&net.TCPAddr{
|
||||
@ -478,7 +478,7 @@ func (m *memChannelGraph) addRandNode() (*btcec.PublicKey, error) {
|
||||
// databaseChannelGraphCached wraps a channeldb.ChannelGraph instance with the
|
||||
// necessary API to properly implement the autopilot.ChannelGraph interface.
|
||||
type databaseChannelGraphCached struct {
|
||||
db *channeldb.ChannelGraph
|
||||
db *graphdb.ChannelGraph
|
||||
}
|
||||
|
||||
// A compile time assertion to ensure databaseChannelGraphCached meets the
|
||||
@ -487,7 +487,7 @@ var _ ChannelGraph = (*databaseChannelGraphCached)(nil)
|
||||
|
||||
// ChannelGraphFromCachedDatabase returns an instance of the
|
||||
// autopilot.ChannelGraph backed by a live, open channeldb instance.
|
||||
func ChannelGraphFromCachedDatabase(db *channeldb.ChannelGraph) ChannelGraph {
|
||||
func ChannelGraphFromCachedDatabase(db *graphdb.ChannelGraph) ChannelGraph {
|
||||
return &databaseChannelGraphCached{
|
||||
db: db,
|
||||
}
|
||||
@ -498,7 +498,7 @@ func ChannelGraphFromCachedDatabase(db *channeldb.ChannelGraph) ChannelGraph {
|
||||
// interface.
|
||||
type dbNodeCached struct {
|
||||
node route.Vertex
|
||||
channels map[uint64]*channeldb.DirectedChannel
|
||||
channels map[uint64]*graphdb.DirectedChannel
|
||||
}
|
||||
|
||||
// A compile time assertion to ensure dbNodeCached meets the autopilot.Node
|
||||
@ -552,7 +552,7 @@ func (nc dbNodeCached) ForEachChannel(cb func(ChannelEdge) error) error {
|
||||
// NOTE: Part of the autopilot.ChannelGraph interface.
|
||||
func (dc *databaseChannelGraphCached) ForEachNode(cb func(Node) error) error {
|
||||
return dc.db.ForEachNodeCached(func(n route.Vertex,
|
||||
channels map[uint64]*channeldb.DirectedChannel) error {
|
||||
channels map[uint64]*graphdb.DirectedChannel) error {
|
||||
|
||||
if len(channels) > 0 {
|
||||
node := dbNodeCached{
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
"github.com/btcsuite/btcwallet/chain"
|
||||
"github.com/btcsuite/btcwallet/waddrmgr"
|
||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||
"github.com/lightningnetwork/lnd/routing/chainview"
|
||||
)
|
||||
@ -94,7 +94,7 @@ func (n *NoChainBackend) DisconnectedBlocks() <-chan *chainview.FilteredBlock {
|
||||
return make(chan *chainview.FilteredBlock)
|
||||
}
|
||||
|
||||
func (n *NoChainBackend) UpdateFilter([]channeldb.EdgePoint, uint32) error {
|
||||
func (n *NoChainBackend) UpdateFilter([]graphdb.EdgePoint, uint32) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ package channeldb
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"math/rand"
|
||||
"net"
|
||||
"reflect"
|
||||
@ -10,6 +11,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
|
||||
"github.com/btcsuite/btcd/btcutil"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
@ -24,6 +26,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/lntest/channels"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/routing/route"
|
||||
"github.com/lightningnetwork/lnd/shachain"
|
||||
"github.com/lightningnetwork/lnd/tlv"
|
||||
"github.com/stretchr/testify/require"
|
||||
@ -43,8 +46,20 @@ var (
|
||||
}
|
||||
privKey, pubKey = btcec.PrivKeyFromBytes(key[:])
|
||||
|
||||
testRBytes, _ = hex.DecodeString("8ce2bc69281ce27da07e6683571319d18e" +
|
||||
"949ddfa2965fb6caa1bf0314f882d7")
|
||||
testSBytes, _ = hex.DecodeString("299105481d63e0f4bc2a88121167221b67" +
|
||||
"00d72a0ead154c03be696a292d24ae")
|
||||
testRScalar = new(btcec.ModNScalar)
|
||||
testSScalar = new(btcec.ModNScalar)
|
||||
_ = testRScalar.SetByteSlice(testRBytes)
|
||||
_ = testSScalar.SetByteSlice(testSBytes)
|
||||
testSig = ecdsa.NewSignature(testRScalar, testSScalar)
|
||||
|
||||
wireSig, _ = lnwire.NewSigFromSignature(testSig)
|
||||
|
||||
testPub = route.Vertex{2, 202, 4}
|
||||
|
||||
testClock = clock.NewTestClock(testNow)
|
||||
|
||||
// defaultPendingHeight is the default height at which we set
|
||||
|
@ -336,7 +336,7 @@ type DB struct {
|
||||
channelStateDB *ChannelStateDB
|
||||
|
||||
dbPath string
|
||||
graph *ChannelGraph
|
||||
graph *graphdb.ChannelGraph
|
||||
clock clock.Clock
|
||||
dryRun bool
|
||||
keepFailedPaymentAttempts bool
|
||||
@ -410,7 +410,7 @@ func CreateWithBackend(backend kvdb.Backend,
|
||||
chanDB.channelStateDB.parent = chanDB
|
||||
|
||||
var err error
|
||||
chanDB.graph, err = NewChannelGraph(
|
||||
chanDB.graph, err = graphdb.NewChannelGraph(
|
||||
backend, opts.RejectCacheSize, opts.ChannelCacheSize,
|
||||
opts.BatchCommitInterval, opts.PreAllocCacheNumNodes,
|
||||
opts.UseGraphCache, opts.NoMigration,
|
||||
@ -1370,12 +1370,12 @@ func (d *DB) AddrsForNode(nodePub *btcec.PublicKey) ([]net.Addr,
|
||||
return nil, err
|
||||
}
|
||||
graphNode, err := d.graph.FetchLightningNode(pubKey)
|
||||
if err != nil && err != ErrGraphNodeNotFound {
|
||||
if err != nil && err != graphdb.ErrGraphNodeNotFound {
|
||||
return nil, err
|
||||
} else if err == ErrGraphNodeNotFound {
|
||||
} else if err == graphdb.ErrGraphNodeNotFound {
|
||||
// If the node isn't found, then that's OK, as we still have the
|
||||
// link node data. But any other error needs to be returned.
|
||||
graphNode = &LightningNode{}
|
||||
graphNode = &graphdb.LightningNode{}
|
||||
}
|
||||
|
||||
// Now that we have both sources of addrs for this node, we'll use a
|
||||
@ -1647,7 +1647,7 @@ func (d *DB) applyOptionalVersions(cfg OptionalMiragtionConfig) error {
|
||||
}
|
||||
|
||||
// ChannelGraph returns the current instance of the directed channel graph.
|
||||
func (d *DB) ChannelGraph() *ChannelGraph {
|
||||
func (d *DB) ChannelGraph() *graphdb.ChannelGraph {
|
||||
return d.graph
|
||||
}
|
||||
|
||||
|
@ -1,17 +1,20 @@
|
||||
package channeldb
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
"math"
|
||||
"math/rand"
|
||||
"net"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
"github.com/btcsuite/btcd/btcutil"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/keychain"
|
||||
"github.com/lightningnetwork/lnd/kvdb"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
@ -20,6 +23,16 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var (
|
||||
testAddr = &net.TCPAddr{IP: (net.IP)([]byte{0xA, 0x0, 0x0, 0x1}),
|
||||
Port: 9000}
|
||||
anotherAddr, _ = net.ResolveTCPAddr("tcp",
|
||||
"[2001:db8:85a3:0:0:8a2e:370:7334]:80")
|
||||
testAddrs = []net.Addr{testAddr}
|
||||
|
||||
testFeatures = lnwire.NewFeatureVector(nil, lnwire.Features)
|
||||
)
|
||||
|
||||
func TestOpenWithCreate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
@ -179,7 +192,7 @@ func TestAddrsForNode(t *testing.T) {
|
||||
// We'll make a test vertex to insert into the database, as the source
|
||||
// node, but this node will only have half the number of addresses it
|
||||
// usually does.
|
||||
testNode, err := createTestVertex(fullDB)
|
||||
testNode := createTestVertex(t)
|
||||
require.NoError(t, err, "unable to create test node")
|
||||
testNode.Addresses = []net.Addr{testAddr}
|
||||
if err := graph.SetSourceNode(testNode); err != nil {
|
||||
@ -711,3 +724,28 @@ func TestFetchHistoricalChannel(t *testing.T) {
|
||||
t.Fatalf("expected chan not found, got: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func createLightningNode(priv *btcec.PrivateKey) *graphdb.LightningNode {
|
||||
updateTime := rand.Int63()
|
||||
|
||||
pub := priv.PubKey().SerializeCompressed()
|
||||
n := &graphdb.LightningNode{
|
||||
HaveNodeAnnouncement: true,
|
||||
AuthSigBytes: testSig.Serialize(),
|
||||
LastUpdate: time.Unix(updateTime, 0),
|
||||
Color: color.RGBA{1, 2, 3, 0},
|
||||
Alias: "kek" + string(pub[:]),
|
||||
Features: testFeatures,
|
||||
Addresses: testAddrs,
|
||||
}
|
||||
copy(n.PubKeyBytes[:], priv.PubKey().SerializeCompressed())
|
||||
|
||||
return n
|
||||
}
|
||||
|
||||
func createTestVertex(t *testing.T) *graphdb.LightningNode {
|
||||
priv, err := btcec.NewPrivateKey()
|
||||
require.NoError(t, err)
|
||||
|
||||
return createLightningNode(priv)
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package channeldb
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
@ -43,53 +42,6 @@ var (
|
||||
// created.
|
||||
ErrMetaNotFound = fmt.Errorf("unable to locate meta information")
|
||||
|
||||
// ErrClosedScidsNotFound is returned when the closed scid bucket
|
||||
// hasn't been created.
|
||||
ErrClosedScidsNotFound = fmt.Errorf("closed scid bucket doesn't exist")
|
||||
|
||||
// ErrGraphNotFound is returned when at least one of the components of
|
||||
// graph doesn't exist.
|
||||
ErrGraphNotFound = fmt.Errorf("graph bucket not initialized")
|
||||
|
||||
// ErrGraphNeverPruned is returned when graph was never pruned.
|
||||
ErrGraphNeverPruned = fmt.Errorf("graph never pruned")
|
||||
|
||||
// ErrSourceNodeNotSet is returned if the source node of the graph
|
||||
// hasn't been added The source node is the center node within a
|
||||
// star-graph.
|
||||
ErrSourceNodeNotSet = fmt.Errorf("source node does not exist")
|
||||
|
||||
// ErrGraphNodesNotFound is returned in case none of the nodes has
|
||||
// been added in graph node bucket.
|
||||
ErrGraphNodesNotFound = fmt.Errorf("no graph nodes exist")
|
||||
|
||||
// ErrGraphNoEdgesFound is returned in case of none of the channel/edges
|
||||
// has been added in graph edge bucket.
|
||||
ErrGraphNoEdgesFound = fmt.Errorf("no graph edges exist")
|
||||
|
||||
// ErrGraphNodeNotFound is returned when we're unable to find the target
|
||||
// node.
|
||||
ErrGraphNodeNotFound = fmt.Errorf("unable to find node")
|
||||
|
||||
// ErrEdgeNotFound is returned when an edge for the target chanID
|
||||
// can't be found.
|
||||
ErrEdgeNotFound = fmt.Errorf("edge not found")
|
||||
|
||||
// ErrZombieEdge is an error returned when we attempt to look up an edge
|
||||
// but it is marked as a zombie within the zombie index.
|
||||
ErrZombieEdge = errors.New("edge marked as zombie")
|
||||
|
||||
// ErrZombieEdgeNotFound is an error returned when we attempt to find an
|
||||
// edge in the zombie index which is not there.
|
||||
ErrZombieEdgeNotFound = errors.New("edge not found in zombie index")
|
||||
|
||||
// ErrEdgeAlreadyExist is returned when edge with specific
|
||||
// channel id can't be added because it already exist.
|
||||
ErrEdgeAlreadyExist = fmt.Errorf("edge already exist")
|
||||
|
||||
// ErrNodeAliasNotFound is returned when alias for node can't be found.
|
||||
ErrNodeAliasNotFound = fmt.Errorf("alias for node not found")
|
||||
|
||||
// ErrNoClosedChannels is returned when a node is queries for all the
|
||||
// channels it has closed, but it hasn't yet closed any channels.
|
||||
ErrNoClosedChannels = fmt.Errorf("no channel have been closed yet")
|
||||
@ -98,24 +50,8 @@ var (
|
||||
// to the log not having any recorded events.
|
||||
ErrNoForwardingEvents = fmt.Errorf("no recorded forwarding events")
|
||||
|
||||
// ErrEdgePolicyOptionalFieldNotFound is an error returned if a channel
|
||||
// policy field is not found in the db even though its message flags
|
||||
// indicate it should be.
|
||||
ErrEdgePolicyOptionalFieldNotFound = fmt.Errorf("optional field not " +
|
||||
"present")
|
||||
|
||||
// ErrChanAlreadyExists is return when the caller attempts to create a
|
||||
// channel with a channel point that is already present in the
|
||||
// database.
|
||||
ErrChanAlreadyExists = fmt.Errorf("channel already exists")
|
||||
)
|
||||
|
||||
// ErrTooManyExtraOpaqueBytes creates an error which should be returned if the
|
||||
// caller attempts to write an announcement message which bares too many extra
|
||||
// opaque bytes. We limit this value in order to ensure that we don't waste
|
||||
// disk space due to nodes unnecessarily padding out their announcements with
|
||||
// garbage data.
|
||||
func ErrTooManyExtraOpaqueBytes(numBytes int) error {
|
||||
return fmt.Errorf("max allowed number of opaque bytes is %v, received "+
|
||||
"%v bytes", MaxAllowedExtraOpaqueBytes, numBytes)
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package graphsession
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/kvdb"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/routing"
|
||||
@ -84,7 +84,7 @@ func (g *session) close() error {
|
||||
//
|
||||
// NOTE: Part of the routing.Graph interface.
|
||||
func (g *session) ForEachNodeChannel(nodePub route.Vertex,
|
||||
cb func(channel *channeldb.DirectedChannel) error) error {
|
||||
cb func(channel *graphdb.DirectedChannel) error) error {
|
||||
|
||||
return g.graph.ForEachNodeDirectedChannel(g.tx, nodePub, cb)
|
||||
}
|
||||
@ -129,7 +129,7 @@ type graph interface {
|
||||
// NOTE: if a nil tx is provided, then it is expected that the
|
||||
// implementation create a read only tx.
|
||||
ForEachNodeDirectedChannel(tx kvdb.RTx, node route.Vertex,
|
||||
cb func(channel *channeldb.DirectedChannel) error) error
|
||||
cb func(channel *graphdb.DirectedChannel) error) error
|
||||
|
||||
// FetchNodeFeatures returns the features of a given node. If no
|
||||
// features are known for the node, an empty feature vector is returned.
|
||||
@ -138,4 +138,4 @@ type graph interface {
|
||||
|
||||
// A compile-time check to ensure that *channeldb.ChannelGraph implements the
|
||||
// graph interface.
|
||||
var _ graph = (*channeldb.ChannelGraph)(nil)
|
||||
var _ graph = (*graphdb.ChannelGraph)(nil)
|
||||
|
@ -22,10 +22,8 @@ func applyMigration(t *testing.T, beforeMigration, afterMigration func(d *DB),
|
||||
cdb.dryRun = dryRun
|
||||
|
||||
// Create a test node that will be our source node.
|
||||
testNode, err := createTestVertex(cdb)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
testNode := createTestVertex(t)
|
||||
|
||||
graph := cdb.ChannelGraph()
|
||||
if err := graph.SetSourceNode(testNode); err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/netann"
|
||||
"github.com/lightningnetwork/lnd/routing/route"
|
||||
@ -36,7 +36,7 @@ type ChannelGraphTimeSeries interface {
|
||||
// ID's represents the ID's that we don't know of which were in the
|
||||
// passed superSet.
|
||||
FilterKnownChanIDs(chain chainhash.Hash,
|
||||
superSet []channeldb.ChannelUpdateInfo,
|
||||
superSet []graphdb.ChannelUpdateInfo,
|
||||
isZombieChan func(time.Time, time.Time) bool) (
|
||||
[]lnwire.ShortChannelID, error)
|
||||
|
||||
@ -45,7 +45,7 @@ type ChannelGraphTimeSeries interface {
|
||||
// grouped by their common block height. We'll use this to to a remote
|
||||
// peer's QueryChannelRange message.
|
||||
FilterChannelRange(chain chainhash.Hash, startHeight, endHeight uint32,
|
||||
withTimestamps bool) ([]channeldb.BlockChannelRange, error)
|
||||
withTimestamps bool) ([]graphdb.BlockChannelRange, error)
|
||||
|
||||
// FetchChanAnns returns a full set of channel announcements as well as
|
||||
// their updates that match the set of specified short channel ID's.
|
||||
@ -70,12 +70,12 @@ type ChannelGraphTimeSeries interface {
|
||||
// in-protocol channel range queries to quickly and efficiently synchronize our
|
||||
// channel state with all peers.
|
||||
type ChanSeries struct {
|
||||
graph *channeldb.ChannelGraph
|
||||
graph *graphdb.ChannelGraph
|
||||
}
|
||||
|
||||
// NewChanSeries constructs a new ChanSeries backed by a channeldb.ChannelGraph.
|
||||
// The returned ChanSeries implements the ChannelGraphTimeSeries interface.
|
||||
func NewChanSeries(graph *channeldb.ChannelGraph) *ChanSeries {
|
||||
func NewChanSeries(graph *graphdb.ChannelGraph) *ChanSeries {
|
||||
return &ChanSeries{
|
||||
graph: graph,
|
||||
}
|
||||
@ -200,7 +200,7 @@ func (c *ChanSeries) UpdatesInHorizon(chain chainhash.Hash,
|
||||
//
|
||||
// NOTE: This is part of the ChannelGraphTimeSeries interface.
|
||||
func (c *ChanSeries) FilterKnownChanIDs(_ chainhash.Hash,
|
||||
superSet []channeldb.ChannelUpdateInfo,
|
||||
superSet []graphdb.ChannelUpdateInfo,
|
||||
isZombieChan func(time.Time, time.Time) bool) (
|
||||
[]lnwire.ShortChannelID, error) {
|
||||
|
||||
@ -226,7 +226,7 @@ func (c *ChanSeries) FilterKnownChanIDs(_ chainhash.Hash,
|
||||
//
|
||||
// NOTE: This is part of the ChannelGraphTimeSeries interface.
|
||||
func (c *ChanSeries) FilterChannelRange(_ chainhash.Hash, startHeight,
|
||||
endHeight uint32, withTimestamps bool) ([]channeldb.BlockChannelRange,
|
||||
endHeight uint32, withTimestamps bool) ([]graphdb.BlockChannelRange,
|
||||
error) {
|
||||
|
||||
return c.graph.FilterChannelRange(
|
||||
|
@ -21,6 +21,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/fn"
|
||||
"github.com/lightningnetwork/lnd/graph"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||
"github.com/lightningnetwork/lnd/keychain"
|
||||
"github.com/lightningnetwork/lnd/kvdb"
|
||||
@ -1686,7 +1687,7 @@ func (d *AuthenticatedGossiper) retransmitStaleAnns(now time.Time) error {
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil && err != channeldb.ErrGraphNoEdgesFound {
|
||||
if err != nil && err != graphdb.ErrGraphNoEdgesFound {
|
||||
return fmt.Errorf("unable to retrieve outgoing channels: %w",
|
||||
err)
|
||||
}
|
||||
@ -1963,7 +1964,7 @@ func (d *AuthenticatedGossiper) addNode(msg *lnwire.NodeAnnouncement,
|
||||
|
||||
timestamp := time.Unix(int64(msg.Timestamp), 0)
|
||||
features := lnwire.NewFeatureVector(msg.Features, lnwire.Features)
|
||||
node := &channeldb.LightningNode{
|
||||
node := &graphdb.LightningNode{
|
||||
HaveNodeAnnouncement: true,
|
||||
LastUpdate: timestamp,
|
||||
Addresses: msg.Addresses,
|
||||
@ -2121,7 +2122,7 @@ func (d *AuthenticatedGossiper) processZombieUpdate(
|
||||
// come through again.
|
||||
err = d.cfg.Graph.MarkEdgeLive(scid)
|
||||
switch {
|
||||
case errors.Is(err, channeldb.ErrZombieEdgeNotFound):
|
||||
case errors.Is(err, graphdb.ErrZombieEdgeNotFound):
|
||||
log.Errorf("edge with chan_id=%v was not found in the "+
|
||||
"zombie index: %v", err)
|
||||
|
||||
@ -2166,7 +2167,7 @@ func (d *AuthenticatedGossiper) isMsgStale(msg lnwire.Message) bool {
|
||||
// If the channel cannot be found, it is most likely a leftover
|
||||
// message for a channel that was closed, so we can consider it
|
||||
// stale.
|
||||
if errors.Is(err, channeldb.ErrEdgeNotFound) {
|
||||
if errors.Is(err, graphdb.ErrEdgeNotFound) {
|
||||
return true
|
||||
}
|
||||
if err != nil {
|
||||
@ -2186,7 +2187,7 @@ func (d *AuthenticatedGossiper) isMsgStale(msg lnwire.Message) bool {
|
||||
// If the channel cannot be found, it is most likely a leftover
|
||||
// message for a channel that was closed, so we can consider it
|
||||
// stale.
|
||||
if errors.Is(err, channeldb.ErrEdgeNotFound) {
|
||||
if errors.Is(err, graphdb.ErrEdgeNotFound) {
|
||||
return true
|
||||
}
|
||||
if err != nil {
|
||||
@ -2936,7 +2937,7 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
|
||||
case err == nil:
|
||||
break
|
||||
|
||||
case errors.Is(err, channeldb.ErrZombieEdge):
|
||||
case errors.Is(err, graphdb.ErrZombieEdge):
|
||||
err = d.processZombieUpdate(chanInfo, graphScid, upd)
|
||||
if err != nil {
|
||||
log.Debug(err)
|
||||
@ -2949,11 +2950,11 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
|
||||
// needed to ensure the edge exists in the graph before
|
||||
// applying the update.
|
||||
fallthrough
|
||||
case errors.Is(err, channeldb.ErrGraphNotFound):
|
||||
case errors.Is(err, graphdb.ErrGraphNotFound):
|
||||
fallthrough
|
||||
case errors.Is(err, channeldb.ErrGraphNoEdgesFound):
|
||||
case errors.Is(err, graphdb.ErrGraphNoEdgesFound):
|
||||
fallthrough
|
||||
case errors.Is(err, channeldb.ErrEdgeNotFound):
|
||||
case errors.Is(err, graphdb.ErrEdgeNotFound):
|
||||
// If the edge corresponding to this ChannelUpdate was not
|
||||
// found in the graph, this might be a channel in the process
|
||||
// of being opened, and we haven't processed our own
|
||||
|
@ -26,6 +26,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/fn"
|
||||
"github.com/lightningnetwork/lnd/graph"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||
"github.com/lightningnetwork/lnd/keychain"
|
||||
"github.com/lightningnetwork/lnd/kvdb"
|
||||
@ -92,7 +93,7 @@ type mockGraphSource struct {
|
||||
bestHeight uint32
|
||||
|
||||
mu sync.Mutex
|
||||
nodes []channeldb.LightningNode
|
||||
nodes []graphdb.LightningNode
|
||||
infos map[uint64]models.ChannelEdgeInfo
|
||||
edges map[uint64][]models.ChannelEdgePolicy
|
||||
zombies map[uint64][][33]byte
|
||||
@ -112,7 +113,7 @@ func newMockRouter(height uint32) *mockGraphSource {
|
||||
|
||||
var _ graph.ChannelGraphSource = (*mockGraphSource)(nil)
|
||||
|
||||
func (r *mockGraphSource) AddNode(node *channeldb.LightningNode,
|
||||
func (r *mockGraphSource) AddNode(node *graphdb.LightningNode,
|
||||
_ ...batch.SchedulerOption) error {
|
||||
|
||||
r.mu.Lock()
|
||||
@ -202,7 +203,7 @@ func (r *mockGraphSource) AddProof(chanID lnwire.ShortChannelID,
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *mockGraphSource) ForEachNode(func(node *channeldb.LightningNode) error) error {
|
||||
func (r *mockGraphSource) ForEachNode(func(node *graphdb.LightningNode) error) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -213,7 +214,7 @@ func (r *mockGraphSource) ForAllOutgoingChannels(cb func(tx kvdb.RTx,
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
|
||||
chans := make(map[uint64]channeldb.ChannelEdge)
|
||||
chans := make(map[uint64]graphdb.ChannelEdge)
|
||||
for _, info := range r.infos {
|
||||
info := info
|
||||
|
||||
@ -251,13 +252,13 @@ func (r *mockGraphSource) GetChannelByID(chanID lnwire.ShortChannelID) (
|
||||
if !ok {
|
||||
pubKeys, isZombie := r.zombies[chanIDInt]
|
||||
if !isZombie {
|
||||
return nil, nil, nil, channeldb.ErrEdgeNotFound
|
||||
return nil, nil, nil, graphdb.ErrEdgeNotFound
|
||||
}
|
||||
|
||||
return &models.ChannelEdgeInfo{
|
||||
NodeKey1Bytes: pubKeys[0],
|
||||
NodeKey2Bytes: pubKeys[1],
|
||||
}, nil, nil, channeldb.ErrZombieEdge
|
||||
}, nil, nil, graphdb.ErrZombieEdge
|
||||
}
|
||||
|
||||
edges := r.edges[chanID.ToUint64()]
|
||||
@ -279,7 +280,7 @@ func (r *mockGraphSource) GetChannelByID(chanID lnwire.ShortChannelID) (
|
||||
}
|
||||
|
||||
func (r *mockGraphSource) FetchLightningNode(
|
||||
nodePub route.Vertex) (*channeldb.LightningNode, error) {
|
||||
nodePub route.Vertex) (*graphdb.LightningNode, error) {
|
||||
|
||||
for _, node := range r.nodes {
|
||||
if bytes.Equal(nodePub[:], node.PubKeyBytes[:]) {
|
||||
@ -287,7 +288,7 @@ func (r *mockGraphSource) FetchLightningNode(
|
||||
}
|
||||
}
|
||||
|
||||
return nil, channeldb.ErrGraphNodeNotFound
|
||||
return nil, graphdb.ErrGraphNodeNotFound
|
||||
}
|
||||
|
||||
// IsStaleNode returns true if the graph source has a node announcement for the
|
||||
@ -2319,7 +2320,7 @@ func TestProcessZombieEdgeNowLive(t *testing.T) {
|
||||
|
||||
// At this point, the channel should still be considered a zombie.
|
||||
_, _, _, err = ctx.router.GetChannelByID(chanID)
|
||||
if err != channeldb.ErrZombieEdge {
|
||||
if err != graphdb.ErrZombieEdge {
|
||||
t.Fatalf("channel should still be a zombie")
|
||||
}
|
||||
|
||||
@ -2442,7 +2443,7 @@ func TestReceiveRemoteChannelUpdateFirst(t *testing.T) {
|
||||
// to the map of premature ChannelUpdates. Check that nothing
|
||||
// was added to the graph.
|
||||
chanInfo, e1, e2, err := ctx.router.GetChannelByID(batch.chanUpdAnn1.ShortChannelID)
|
||||
if err != channeldb.ErrEdgeNotFound {
|
||||
if err != graphdb.ErrEdgeNotFound {
|
||||
t.Fatalf("Expected ErrEdgeNotFound, got: %v", err)
|
||||
}
|
||||
if chanInfo != nil {
|
||||
|
@ -11,8 +11,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/graph"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/lnpeer"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"golang.org/x/time/rate"
|
||||
@ -373,7 +373,7 @@ type GossipSyncer struct {
|
||||
|
||||
// bufferedChanRangeReplies is used in the waitingQueryChanReply to
|
||||
// buffer all the chunked response to our query.
|
||||
bufferedChanRangeReplies []channeldb.ChannelUpdateInfo
|
||||
bufferedChanRangeReplies []graphdb.ChannelUpdateInfo
|
||||
|
||||
// numChanRangeRepliesRcvd is used to track the number of replies
|
||||
// received as part of a QueryChannelRange. This field is primarily used
|
||||
@ -837,7 +837,7 @@ func (g *GossipSyncer) processChanRangeReply(msg *lnwire.ReplyChannelRange) erro
|
||||
g.prevReplyChannelRange = msg
|
||||
|
||||
for i, scid := range msg.ShortChanIDs {
|
||||
info := channeldb.NewChannelUpdateInfo(
|
||||
info := graphdb.NewChannelUpdateInfo(
|
||||
scid, time.Time{}, time.Time{},
|
||||
)
|
||||
|
||||
@ -1115,7 +1115,7 @@ func (g *GossipSyncer) replyChanRangeQuery(query *lnwire.QueryChannelRange) erro
|
||||
// this as there's a transport message size limit which we'll need to
|
||||
// adhere to. We also need to make sure all of our replies cover the
|
||||
// expected range of the query.
|
||||
sendReplyForChunk := func(channelChunk []channeldb.ChannelUpdateInfo,
|
||||
sendReplyForChunk := func(channelChunk []graphdb.ChannelUpdateInfo,
|
||||
firstHeight, lastHeight uint32, finalChunk bool) error {
|
||||
|
||||
// The number of blocks contained in the current chunk (the
|
||||
@ -1164,7 +1164,7 @@ func (g *GossipSyncer) replyChanRangeQuery(query *lnwire.QueryChannelRange) erro
|
||||
var (
|
||||
firstHeight = query.FirstBlockHeight
|
||||
lastHeight uint32
|
||||
channelChunk []channeldb.ChannelUpdateInfo
|
||||
channelChunk []graphdb.ChannelUpdateInfo
|
||||
)
|
||||
|
||||
// chunkSize is the maximum number of SCIDs that we can safely put in a
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@ -42,7 +42,7 @@ type mockChannelGraphTimeSeries struct {
|
||||
horizonReq chan horizonQuery
|
||||
horizonResp chan []lnwire.Message
|
||||
|
||||
filterReq chan []channeldb.ChannelUpdateInfo
|
||||
filterReq chan []graphdb.ChannelUpdateInfo
|
||||
filterResp chan []lnwire.ShortChannelID
|
||||
|
||||
filterRangeReqs chan filterRangeReq
|
||||
@ -64,7 +64,7 @@ func newMockChannelGraphTimeSeries(
|
||||
horizonReq: make(chan horizonQuery, 1),
|
||||
horizonResp: make(chan []lnwire.Message, 1),
|
||||
|
||||
filterReq: make(chan []channeldb.ChannelUpdateInfo, 1),
|
||||
filterReq: make(chan []graphdb.ChannelUpdateInfo, 1),
|
||||
filterResp: make(chan []lnwire.ShortChannelID, 1),
|
||||
|
||||
filterRangeReqs: make(chan filterRangeReq, 1),
|
||||
@ -92,7 +92,7 @@ func (m *mockChannelGraphTimeSeries) UpdatesInHorizon(chain chainhash.Hash,
|
||||
}
|
||||
|
||||
func (m *mockChannelGraphTimeSeries) FilterKnownChanIDs(chain chainhash.Hash,
|
||||
superSet []channeldb.ChannelUpdateInfo,
|
||||
superSet []graphdb.ChannelUpdateInfo,
|
||||
isZombieChan func(time.Time, time.Time) bool) (
|
||||
[]lnwire.ShortChannelID, error) {
|
||||
|
||||
@ -102,16 +102,16 @@ func (m *mockChannelGraphTimeSeries) FilterKnownChanIDs(chain chainhash.Hash,
|
||||
}
|
||||
func (m *mockChannelGraphTimeSeries) FilterChannelRange(chain chainhash.Hash,
|
||||
startHeight, endHeight uint32, withTimestamps bool) (
|
||||
[]channeldb.BlockChannelRange, error) {
|
||||
[]graphdb.BlockChannelRange, error) {
|
||||
|
||||
m.filterRangeReqs <- filterRangeReq{startHeight, endHeight}
|
||||
reply := <-m.filterRangeResp
|
||||
|
||||
channelsPerBlock := make(map[uint32][]channeldb.ChannelUpdateInfo)
|
||||
channelsPerBlock := make(map[uint32][]graphdb.ChannelUpdateInfo)
|
||||
for _, cid := range reply {
|
||||
channelsPerBlock[cid.BlockHeight] = append(
|
||||
channelsPerBlock[cid.BlockHeight],
|
||||
channeldb.ChannelUpdateInfo{
|
||||
graphdb.ChannelUpdateInfo{
|
||||
ShortChannelID: cid,
|
||||
},
|
||||
)
|
||||
@ -127,11 +127,11 @@ func (m *mockChannelGraphTimeSeries) FilterChannelRange(chain chainhash.Hash,
|
||||
})
|
||||
|
||||
channelRanges := make(
|
||||
[]channeldb.BlockChannelRange, 0, len(channelsPerBlock),
|
||||
[]graphdb.BlockChannelRange, 0, len(channelsPerBlock),
|
||||
)
|
||||
for _, block := range blocks {
|
||||
channelRanges = append(
|
||||
channelRanges, channeldb.BlockChannelRange{
|
||||
channelRanges, graphdb.BlockChannelRange{
|
||||
Height: block,
|
||||
Channels: channelsPerBlock[block],
|
||||
},
|
||||
|
@ -16,8 +16,8 @@ import (
|
||||
"github.com/go-errors/errors"
|
||||
"github.com/lightningnetwork/lnd/batch"
|
||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/fn"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/kvdb"
|
||||
@ -201,10 +201,10 @@ func (b *Builder) Start() error {
|
||||
// then we don't treat this as an explicit error.
|
||||
if _, _, err := b.cfg.Graph.PruneTip(); err != nil {
|
||||
switch {
|
||||
case errors.Is(err, channeldb.ErrGraphNeverPruned):
|
||||
case errors.Is(err, graphdb.ErrGraphNeverPruned):
|
||||
fallthrough
|
||||
|
||||
case errors.Is(err, channeldb.ErrGraphNotFound):
|
||||
case errors.Is(err, graphdb.ErrGraphNotFound):
|
||||
// If the graph has never been pruned, then we'll set
|
||||
// the prune height to the current best height of the
|
||||
// chain backend.
|
||||
@ -256,7 +256,7 @@ func (b *Builder) Start() error {
|
||||
// been applied.
|
||||
channelView, err := b.cfg.Graph.ChannelView()
|
||||
if err != nil && !errors.Is(
|
||||
err, channeldb.ErrGraphNoEdgesFound,
|
||||
err, graphdb.ErrGraphNoEdgesFound,
|
||||
) {
|
||||
|
||||
return err
|
||||
@ -294,7 +294,7 @@ func (b *Builder) Start() error {
|
||||
// of "useful" nodes.
|
||||
err = b.cfg.Graph.PruneGraphNodes()
|
||||
if err != nil &&
|
||||
!errors.Is(err, channeldb.ErrGraphNodesNotFound) {
|
||||
!errors.Is(err, graphdb.ErrGraphNodesNotFound) {
|
||||
|
||||
return err
|
||||
}
|
||||
@ -352,8 +352,8 @@ func (b *Builder) syncGraphWithChain() error {
|
||||
switch {
|
||||
// If the graph has never been pruned, or hasn't fully been
|
||||
// created yet, then we don't treat this as an explicit error.
|
||||
case errors.Is(err, channeldb.ErrGraphNeverPruned):
|
||||
case errors.Is(err, channeldb.ErrGraphNotFound):
|
||||
case errors.Is(err, graphdb.ErrGraphNeverPruned):
|
||||
case errors.Is(err, graphdb.ErrGraphNotFound):
|
||||
default:
|
||||
return err
|
||||
}
|
||||
@ -400,10 +400,10 @@ func (b *Builder) syncGraphWithChain() error {
|
||||
// as this entails we are back to the point where it hasn't seen
|
||||
// any block or created channels, alas there's nothing left to
|
||||
// prune.
|
||||
case errors.Is(err, channeldb.ErrGraphNeverPruned):
|
||||
case errors.Is(err, graphdb.ErrGraphNeverPruned):
|
||||
return nil
|
||||
|
||||
case errors.Is(err, channeldb.ErrGraphNotFound):
|
||||
case errors.Is(err, graphdb.ErrGraphNotFound):
|
||||
return nil
|
||||
|
||||
case err != nil:
|
||||
@ -658,7 +658,7 @@ func (b *Builder) pruneZombieChans() error {
|
||||
// With the channels pruned, we'll also attempt to prune any nodes that
|
||||
// were a part of them.
|
||||
err = b.cfg.Graph.PruneGraphNodes()
|
||||
if err != nil && !errors.Is(err, channeldb.ErrGraphNodesNotFound) {
|
||||
if err != nil && !errors.Is(err, graphdb.ErrGraphNodesNotFound) {
|
||||
return fmt.Errorf("unable to prune graph nodes: %w", err)
|
||||
}
|
||||
|
||||
@ -1165,7 +1165,7 @@ func (b *Builder) processUpdate(msg interface{},
|
||||
op ...batch.SchedulerOption) error {
|
||||
|
||||
switch msg := msg.(type) {
|
||||
case *channeldb.LightningNode:
|
||||
case *graphdb.LightningNode:
|
||||
// Before we add the node to the database, we'll check to see
|
||||
// if the announcement is "fresh" or not. If it isn't, then
|
||||
// we'll return an error.
|
||||
@ -1192,7 +1192,7 @@ func (b *Builder) processUpdate(msg interface{},
|
||||
msg.ChannelID,
|
||||
)
|
||||
if err != nil &&
|
||||
!errors.Is(err, channeldb.ErrGraphNoEdgesFound) {
|
||||
!errors.Is(err, graphdb.ErrGraphNoEdgesFound) {
|
||||
|
||||
return errors.Errorf("unable to check for edge "+
|
||||
"existence: %v", err)
|
||||
@ -1344,7 +1344,7 @@ func (b *Builder) processUpdate(msg interface{},
|
||||
// update the current UTXO filter within our active
|
||||
// FilteredChainView so we are notified if/when this channel is
|
||||
// closed.
|
||||
filterUpdate := []channeldb.EdgePoint{
|
||||
filterUpdate := []graphdb.EdgePoint{
|
||||
{
|
||||
FundingPkScript: fundingPkScript,
|
||||
OutPoint: *fundingPoint,
|
||||
@ -1371,7 +1371,7 @@ func (b *Builder) processUpdate(msg interface{},
|
||||
edge1Timestamp, edge2Timestamp, exists, isZombie, err :=
|
||||
b.cfg.Graph.HasChannelEdge(msg.ChannelID)
|
||||
if err != nil && !errors.Is(
|
||||
err, channeldb.ErrGraphNoEdgesFound,
|
||||
err, graphdb.ErrGraphNoEdgesFound,
|
||||
) {
|
||||
|
||||
return errors.Errorf("unable to check for edge "+
|
||||
@ -1517,7 +1517,7 @@ func (b *Builder) ApplyChannelUpdate(msg *lnwire.ChannelUpdate1) bool {
|
||||
// be ignored.
|
||||
//
|
||||
// NOTE: This method is part of the ChannelGraphSource interface.
|
||||
func (b *Builder) AddNode(node *channeldb.LightningNode,
|
||||
func (b *Builder) AddNode(node *graphdb.LightningNode,
|
||||
op ...batch.SchedulerOption) error {
|
||||
|
||||
rMsg := &routingMsg{
|
||||
@ -1619,12 +1619,12 @@ func (b *Builder) GetChannelByID(chanID lnwire.ShortChannelID) (
|
||||
}
|
||||
|
||||
// FetchLightningNode attempts to look up a target node by its identity public
|
||||
// key. channeldb.ErrGraphNodeNotFound is returned if the node doesn't exist
|
||||
// key. graphdb.ErrGraphNodeNotFound is returned if the node doesn't exist
|
||||
// within the graph.
|
||||
//
|
||||
// NOTE: This method is part of the ChannelGraphSource interface.
|
||||
func (b *Builder) FetchLightningNode(
|
||||
node route.Vertex) (*channeldb.LightningNode, error) {
|
||||
node route.Vertex) (*graphdb.LightningNode, error) {
|
||||
|
||||
return b.cfg.Graph.FetchLightningNode(node)
|
||||
}
|
||||
@ -1633,10 +1633,10 @@ func (b *Builder) FetchLightningNode(
|
||||
//
|
||||
// NOTE: This method is part of the ChannelGraphSource interface.
|
||||
func (b *Builder) ForEachNode(
|
||||
cb func(*channeldb.LightningNode) error) error {
|
||||
cb func(*graphdb.LightningNode) error) error {
|
||||
|
||||
return b.cfg.Graph.ForEachNode(
|
||||
func(_ kvdb.RTx, n *channeldb.LightningNode) error {
|
||||
func(_ kvdb.RTx, n *graphdb.LightningNode) error {
|
||||
return cb(n)
|
||||
})
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ import (
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/go-errors/errors"
|
||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||
"github.com/lightningnetwork/lnd/lntest/wait"
|
||||
@ -93,7 +93,7 @@ func TestIgnoreNodeAnnouncement(t *testing.T) {
|
||||
ctx := createTestCtxFromFile(t, startingBlockHeight, basicGraphFilePath)
|
||||
|
||||
pub := priv1.PubKey()
|
||||
node := &channeldb.LightningNode{
|
||||
node := &graphdb.LightningNode{
|
||||
HaveNodeAnnouncement: true,
|
||||
LastUpdate: time.Unix(123, 0),
|
||||
Addresses: testAddrs,
|
||||
@ -1038,7 +1038,7 @@ func TestIsStaleNode(t *testing.T) {
|
||||
|
||||
// With the node stub in the database, we'll add the fully node
|
||||
// announcement to the database.
|
||||
n1 := &channeldb.LightningNode{
|
||||
n1 := &graphdb.LightningNode{
|
||||
HaveNodeAnnouncement: true,
|
||||
LastUpdate: updateTimeStamp,
|
||||
Addresses: testAddrs,
|
||||
@ -1453,7 +1453,7 @@ func parseTestGraph(t *testing.T, useCache bool, path string) (
|
||||
privKeyMap := make(map[string]*btcec.PrivateKey)
|
||||
channelIDs := make(map[route.Vertex]map[route.Vertex]uint64)
|
||||
links := make(map[lnwire.ShortChannelID]htlcswitch.ChannelLink)
|
||||
var source *channeldb.LightningNode
|
||||
var source *graphdb.LightningNode
|
||||
|
||||
// First we insert all the nodes within the graph as vertexes.
|
||||
for _, node := range g.Nodes {
|
||||
@ -1462,7 +1462,7 @@ func parseTestGraph(t *testing.T, useCache bool, path string) (
|
||||
return nil, err
|
||||
}
|
||||
|
||||
dbNode := &channeldb.LightningNode{
|
||||
dbNode := &graphdb.LightningNode{
|
||||
HaveNodeAnnouncement: true,
|
||||
AuthSigBytes: testSig.Serialize(),
|
||||
LastUpdate: testTime,
|
||||
@ -1593,10 +1593,7 @@ func parseTestGraph(t *testing.T, useCache bool, path string) (
|
||||
}
|
||||
|
||||
err = graph.AddChannelEdge(&edgeInfo)
|
||||
if err != nil && !errors.Is(
|
||||
err, channeldb.ErrEdgeAlreadyExist,
|
||||
) {
|
||||
|
||||
if err != nil && !errors.Is(err, graphdb.ErrEdgeAlreadyExist) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -1753,7 +1750,7 @@ func asymmetricTestChannel(alias1, alias2 string, capacity btcutil.Amount,
|
||||
|
||||
// assertChannelsPruned ensures that only the given channels are pruned from the
|
||||
// graph out of the set of all channels.
|
||||
func assertChannelsPruned(t *testing.T, graph *channeldb.ChannelGraph,
|
||||
func assertChannelsPruned(t *testing.T, graph *graphdb.ChannelGraph,
|
||||
channels []*testChannel, prunedChanIDs ...uint64) {
|
||||
|
||||
t.Helper()
|
||||
@ -1835,7 +1832,7 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
|
||||
|
||||
nodeIndex := byte(0)
|
||||
addNodeWithAlias := func(alias string, features *lnwire.FeatureVector) (
|
||||
*channeldb.LightningNode, error) {
|
||||
*graphdb.LightningNode, error) {
|
||||
|
||||
keyBytes := []byte{
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
@ -1850,7 +1847,7 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
|
||||
features = lnwire.EmptyFeatureVector()
|
||||
}
|
||||
|
||||
dbNode := &channeldb.LightningNode{
|
||||
dbNode := &graphdb.LightningNode{
|
||||
HaveNodeAnnouncement: true,
|
||||
AuthSigBytes: testSig.Serialize(),
|
||||
LastUpdate: testTime,
|
||||
@ -1959,7 +1956,7 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
|
||||
|
||||
err = graph.AddChannelEdge(&edgeInfo)
|
||||
if err != nil &&
|
||||
!errors.Is(err, channeldb.ErrEdgeAlreadyExist) {
|
||||
!errors.Is(err, graphdb.ErrEdgeAlreadyExist) {
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package channeldb
|
||||
package graphdb
|
||||
|
||||
// channelCache is an in-memory cache used to improve the performance of
|
||||
// ChanUpdatesInHorizon. It caches the chan info and edge policies for a
|
@ -1,4 +1,4 @@
|
||||
package channeldb
|
||||
package graphdb
|
||||
|
||||
import (
|
||||
"reflect"
|
@ -1,9 +1,75 @@
|
||||
package graphdb
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrEdgePolicyOptionalFieldNotFound is an error returned if a channel
|
||||
// policy field is not found in the db even though its message flags
|
||||
// indicate it should be.
|
||||
ErrEdgePolicyOptionalFieldNotFound = fmt.Errorf("optional field not " +
|
||||
"present")
|
||||
|
||||
// ErrGraphNotFound is returned when at least one of the components of
|
||||
// graph doesn't exist.
|
||||
ErrGraphNotFound = fmt.Errorf("graph bucket not initialized")
|
||||
|
||||
// ErrGraphNeverPruned is returned when graph was never pruned.
|
||||
ErrGraphNeverPruned = fmt.Errorf("graph never pruned")
|
||||
|
||||
// ErrSourceNodeNotSet is returned if the source node of the graph
|
||||
// hasn't been added The source node is the center node within a
|
||||
// star-graph.
|
||||
ErrSourceNodeNotSet = fmt.Errorf("source node does not exist")
|
||||
|
||||
// ErrGraphNodesNotFound is returned in case none of the nodes has
|
||||
// been added in graph node bucket.
|
||||
ErrGraphNodesNotFound = fmt.Errorf("no graph nodes exist")
|
||||
|
||||
// ErrGraphNoEdgesFound is returned in case of none of the channel/edges
|
||||
// has been added in graph edge bucket.
|
||||
ErrGraphNoEdgesFound = fmt.Errorf("no graph edges exist")
|
||||
|
||||
// ErrGraphNodeNotFound is returned when we're unable to find the target
|
||||
// node.
|
||||
ErrGraphNodeNotFound = fmt.Errorf("unable to find node")
|
||||
|
||||
// ErrZombieEdge is an error returned when we attempt to look up an edge
|
||||
// but it is marked as a zombie within the zombie index.
|
||||
ErrZombieEdge = errors.New("edge marked as zombie")
|
||||
|
||||
// ErrEdgeNotFound is returned when an edge for the target chanID
|
||||
// can't be found.
|
||||
ErrEdgeNotFound = fmt.Errorf("edge not found")
|
||||
|
||||
// ErrEdgeAlreadyExist is returned when edge with specific
|
||||
// channel id can't be added because it already exist.
|
||||
ErrEdgeAlreadyExist = fmt.Errorf("edge already exist")
|
||||
|
||||
// ErrNodeAliasNotFound is returned when alias for node can't be found.
|
||||
ErrNodeAliasNotFound = fmt.Errorf("alias for node not found")
|
||||
|
||||
// ErrClosedScidsNotFound is returned when the closed scid bucket
|
||||
// hasn't been created.
|
||||
ErrClosedScidsNotFound = fmt.Errorf("closed scid bucket doesn't exist")
|
||||
|
||||
// ErrZombieEdgeNotFound is an error returned when we attempt to find an
|
||||
// edge in the zombie index which is not there.
|
||||
ErrZombieEdgeNotFound = errors.New("edge not found in zombie index")
|
||||
|
||||
// ErrUnknownAddressType is returned when a node's addressType is not
|
||||
// an expected value.
|
||||
ErrUnknownAddressType = fmt.Errorf("address type cannot be resolved")
|
||||
)
|
||||
|
||||
// ErrTooManyExtraOpaqueBytes creates an error which should be returned if the
|
||||
// caller attempts to write an announcement message which bares too many extra
|
||||
// opaque bytes. We limit this value in order to ensure that we don't waste
|
||||
// disk space due to nodes unnecessarily padding out their announcements with
|
||||
// garbage data.
|
||||
func ErrTooManyExtraOpaqueBytes(numBytes int) error {
|
||||
return fmt.Errorf("max allowed number of opaque bytes is %v, received "+
|
||||
"%v bytes", MaxAllowedExtraOpaqueBytes, numBytes)
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package channeldb
|
||||
package graphdb
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@ -21,7 +21,6 @@ import (
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/lightningnetwork/lnd/aliasmgr"
|
||||
"github.com/lightningnetwork/lnd/batch"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/kvdb"
|
||||
@ -350,7 +349,7 @@ func (c *ChannelGraph) Wipe() error {
|
||||
return initChannelGraph(c.db)
|
||||
}
|
||||
|
||||
// createChannelDB creates and initializes a fresh version of channeldb. In
|
||||
// createChannelDB creates and initializes a fresh version of In
|
||||
// the case that the target path has not yet been created or doesn't yet exist,
|
||||
// then the path is created. Additionally, all required top-level buckets used
|
||||
// within the database are created.
|
||||
@ -1129,7 +1128,7 @@ func (c *ChannelGraph) addChannelEdge(tx kvdb.RwTx,
|
||||
// Finally we add it to the channel index which maps channel points
|
||||
// (outpoints) to the shorter channel ID's.
|
||||
var b bytes.Buffer
|
||||
if err := graphdb.WriteOutpoint(&b, &edge.ChannelPoint); err != nil {
|
||||
if err := WriteOutpoint(&b, &edge.ChannelPoint); err != nil {
|
||||
return err
|
||||
}
|
||||
return chanIndex.Put(b.Bytes(), chanKey[:])
|
||||
@ -1336,7 +1335,7 @@ func (c *ChannelGraph) PruneGraph(spentOutputs []*wire.OutPoint,
|
||||
// if NOT if filter
|
||||
|
||||
var opBytes bytes.Buffer
|
||||
if err := graphdb.WriteOutpoint(&opBytes, chanPoint); err != nil {
|
||||
if err := WriteOutpoint(&opBytes, chanPoint); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -1808,7 +1807,7 @@ func (c *ChannelGraph) ChannelID(chanPoint *wire.OutPoint) (uint64, error) {
|
||||
// getChanID returns the assigned channel ID for a given channel point.
|
||||
func getChanID(tx kvdb.RTx, chanPoint *wire.OutPoint) (uint64, error) {
|
||||
var b bytes.Buffer
|
||||
if err := graphdb.WriteOutpoint(&b, chanPoint); err != nil {
|
||||
if err := WriteOutpoint(&b, chanPoint); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@ -2636,7 +2635,7 @@ func (c *ChannelGraph) delChannelEdgeUnsafe(edges, edgeIndex, chanIndex,
|
||||
return err
|
||||
}
|
||||
var b bytes.Buffer
|
||||
if err := graphdb.WriteOutpoint(&b, &edgeInfo.ChannelPoint); err != nil {
|
||||
if err := WriteOutpoint(&b, &edgeInfo.ChannelPoint); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := chanIndex.Delete(b.Bytes()); err != nil {
|
||||
@ -3414,7 +3413,7 @@ func (c *ChannelGraph) FetchChannelEdgesByOutpoint(op *wire.OutPoint) (
|
||||
return ErrGraphNoEdgesFound
|
||||
}
|
||||
var b bytes.Buffer
|
||||
if err := graphdb.WriteOutpoint(&b, op); err != nil {
|
||||
if err := WriteOutpoint(&b, op); err != nil {
|
||||
return err
|
||||
}
|
||||
chanID := chanIndex.Get(b.Bytes())
|
||||
@ -3660,7 +3659,7 @@ func (c *ChannelGraph) ChannelView() ([]EdgePoint, error) {
|
||||
chanPointReader := bytes.NewReader(chanPointBytes)
|
||||
|
||||
var chanPoint wire.OutPoint
|
||||
err := graphdb.ReadOutpoint(chanPointReader, &chanPoint)
|
||||
err := ReadOutpoint(chanPointReader, &chanPoint)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -4017,7 +4016,7 @@ func putLightningNode(nodeBucket kvdb.RwBucket, aliasBucket kvdb.RwBucket, // no
|
||||
}
|
||||
|
||||
for _, address := range node.Addresses {
|
||||
if err := graphdb.SerializeAddr(&b, address); err != nil {
|
||||
if err := SerializeAddr(&b, address); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@ -4210,7 +4209,7 @@ func deserializeLightningNode(r io.Reader) (LightningNode, error) {
|
||||
|
||||
var addresses []net.Addr
|
||||
for i := 0; i < numAddresses; i++ {
|
||||
address, err := graphdb.DeserializeAddr(r)
|
||||
address, err := DeserializeAddr(r)
|
||||
if err != nil {
|
||||
return LightningNode{}, err
|
||||
}
|
||||
@ -4282,7 +4281,7 @@ func putChanEdgeInfo(edgeIndex kvdb.RwBucket,
|
||||
return err
|
||||
}
|
||||
|
||||
if err := graphdb.WriteOutpoint(&b, &edgeInfo.ChannelPoint); err != nil {
|
||||
if err := WriteOutpoint(&b, &edgeInfo.ChannelPoint); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := binary.Write(&b, byteOrder, uint64(edgeInfo.Capacity)); err != nil {
|
||||
@ -4366,7 +4365,7 @@ func deserializeChanEdgeInfo(r io.Reader) (models.ChannelEdgeInfo, error) {
|
||||
}
|
||||
|
||||
edgeInfo.ChannelPoint = wire.OutPoint{}
|
||||
if err := graphdb.ReadOutpoint(r, &edgeInfo.ChannelPoint); err != nil {
|
||||
if err := ReadOutpoint(r, &edgeInfo.ChannelPoint); err != nil {
|
||||
return models.ChannelEdgeInfo{}, err
|
||||
}
|
||||
if err := binary.Read(r, byteOrder, &edgeInfo.Capacity); err != nil {
|
@ -1,4 +1,4 @@
|
||||
package channeldb
|
||||
package graphdb
|
||||
|
||||
import (
|
||||
"fmt"
|
@ -1,4 +1,4 @@
|
||||
package channeldb
|
||||
package graphdb
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
@ -1,4 +1,4 @@
|
||||
package channeldb
|
||||
package graphdb
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@ -51,13 +51,25 @@ var (
|
||||
)
|
||||
|
||||
testPub = route.Vertex{2, 202, 4}
|
||||
|
||||
key = [chainhash.HashSize]byte{
|
||||
0x81, 0xb6, 0x37, 0xd8, 0xfc, 0xd2, 0xc6, 0xda,
|
||||
0x68, 0x59, 0xe6, 0x96, 0x31, 0x13, 0xa1, 0x17,
|
||||
0xd, 0xe7, 0x93, 0xe4, 0xb7, 0x25, 0xb8, 0x4d,
|
||||
0x1e, 0xb, 0x4c, 0xf9, 0x9e, 0xc5, 0x8c, 0xe9,
|
||||
}
|
||||
rev = [chainhash.HashSize]byte{
|
||||
0x51, 0xb6, 0x37, 0xd8, 0xfc, 0xd2, 0xc6, 0xda,
|
||||
0x48, 0x59, 0xe6, 0x96, 0x31, 0x13, 0xa1, 0x17,
|
||||
0x2d, 0xe7, 0x93, 0xe4,
|
||||
}
|
||||
)
|
||||
|
||||
// MakeTestGraph creates a new instance of the ChannelGraph for testing purposes.
|
||||
func MakeTestGraph(t testing.TB, modifiers ...OptionModifier) (*ChannelGraph, error) {
|
||||
opts := DefaultOptions()
|
||||
for _, modifier := range modifiers {
|
||||
modifier(&opts)
|
||||
modifier(opts)
|
||||
}
|
||||
|
||||
// Next, create channelgraph for the first time.
|
31
graph/db/log.go
Normal file
31
graph/db/log.go
Normal file
@ -0,0 +1,31 @@
|
||||
package graphdb
|
||||
|
||||
import (
|
||||
"github.com/btcsuite/btclog"
|
||||
"github.com/lightningnetwork/lnd/build"
|
||||
)
|
||||
|
||||
// Subsystem defines the logging code for this subsystem.
|
||||
const Subsystem = "GRDB"
|
||||
|
||||
// log is a logger that is initialized with no output filters. This
|
||||
// means the package will not perform any logging by default until the caller
|
||||
// requests it.
|
||||
var log btclog.Logger
|
||||
|
||||
func init() {
|
||||
UseLogger(build.NewSubLogger(Subsystem, nil))
|
||||
}
|
||||
|
||||
// DisableLog disables all library log output. Logging output is disabled
|
||||
// by default until UseLogger is called.
|
||||
func DisableLog() {
|
||||
UseLogger(btclog.Disabled)
|
||||
}
|
||||
|
||||
// UseLogger uses a specified Logger to output package logging info.
|
||||
// This should be used in preference to SetLogWriter if the caller is also
|
||||
// using btclog.
|
||||
func UseLogger(logger btclog.Logger) {
|
||||
log = logger
|
||||
}
|
93
graph/db/options.go
Normal file
93
graph/db/options.go
Normal file
@ -0,0 +1,93 @@
|
||||
package graphdb
|
||||
|
||||
import "time"
|
||||
|
||||
const (
|
||||
// DefaultRejectCacheSize is the default number of rejectCacheEntries to
|
||||
// cache for use in the rejection cache of incoming gossip traffic. This
|
||||
// produces a cache size of around 1MB.
|
||||
DefaultRejectCacheSize = 50000
|
||||
|
||||
// DefaultChannelCacheSize is the default number of ChannelEdges cached
|
||||
// in order to reply to gossip queries. This produces a cache size of
|
||||
// around 40MB.
|
||||
DefaultChannelCacheSize = 20000
|
||||
|
||||
// DefaultPreAllocCacheNumNodes is the default number of channels we
|
||||
// assume for mainnet for pre-allocating the graph cache. As of
|
||||
// September 2021, there currently are 14k nodes in a strictly pruned
|
||||
// graph, so we choose a number that is slightly higher.
|
||||
DefaultPreAllocCacheNumNodes = 15000
|
||||
)
|
||||
|
||||
// Options holds parameters for tuning and customizing a graph.DB.
|
||||
type Options struct {
|
||||
// RejectCacheSize is the maximum number of rejectCacheEntries to hold
|
||||
// in the rejection cache.
|
||||
RejectCacheSize int
|
||||
|
||||
// ChannelCacheSize is the maximum number of ChannelEdges to hold in the
|
||||
// channel cache.
|
||||
ChannelCacheSize int
|
||||
|
||||
// BatchCommitInterval is the maximum duration the batch schedulers will
|
||||
// wait before attempting to commit a pending set of updates.
|
||||
BatchCommitInterval time.Duration
|
||||
|
||||
// PreAllocCacheNumNodes is the number of nodes we expect to be in the
|
||||
// graph cache, so we can pre-allocate the map accordingly.
|
||||
PreAllocCacheNumNodes int
|
||||
|
||||
// UseGraphCache denotes whether the in-memory graph cache should be
|
||||
// used or a fallback version that uses the underlying database for
|
||||
// path finding.
|
||||
UseGraphCache bool
|
||||
|
||||
// NoMigration specifies that underlying backend was opened in read-only
|
||||
// mode and migrations shouldn't be performed. This can be useful for
|
||||
// applications that use the channeldb package as a library.
|
||||
NoMigration bool
|
||||
}
|
||||
|
||||
// DefaultOptions returns an Options populated with default values.
|
||||
func DefaultOptions() *Options {
|
||||
return &Options{
|
||||
RejectCacheSize: DefaultRejectCacheSize,
|
||||
ChannelCacheSize: DefaultChannelCacheSize,
|
||||
PreAllocCacheNumNodes: DefaultPreAllocCacheNumNodes,
|
||||
UseGraphCache: true,
|
||||
NoMigration: false,
|
||||
}
|
||||
}
|
||||
|
||||
// OptionModifier is a function signature for modifying the default Options.
|
||||
type OptionModifier func(*Options)
|
||||
|
||||
// WithChannelCacheSize sets the ChannelCacheSize to n.
|
||||
func WithChannelCacheSize(n int) OptionModifier {
|
||||
return func(o *Options) {
|
||||
o.ChannelCacheSize = n
|
||||
}
|
||||
}
|
||||
|
||||
// WithPreAllocCacheNumNodes sets the PreAllocCacheNumNodes to n.
|
||||
func WithPreAllocCacheNumNodes(n int) OptionModifier {
|
||||
return func(o *Options) {
|
||||
o.PreAllocCacheNumNodes = n
|
||||
}
|
||||
}
|
||||
|
||||
// WithBatchCommitInterval sets the batch commit interval for the interval batch
|
||||
// schedulers.
|
||||
func WithBatchCommitInterval(interval time.Duration) OptionModifier {
|
||||
return func(o *Options) {
|
||||
o.BatchCommitInterval = interval
|
||||
}
|
||||
}
|
||||
|
||||
// WithUseGraphCache sets the UseGraphCache option to the given value.
|
||||
func WithUseGraphCache(use bool) OptionModifier {
|
||||
return func(o *Options) {
|
||||
o.UseGraphCache = use
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package channeldb
|
||||
package graphdb
|
||||
|
||||
// rejectFlags is a compact representation of various metadata stored by the
|
||||
// reject cache about a particular channel.
|
@ -1,4 +1,4 @@
|
||||
package channeldb
|
||||
package graphdb
|
||||
|
||||
import (
|
||||
"reflect"
|
11
graph/db/setup_test.go
Normal file
11
graph/db/setup_test.go
Normal file
@ -0,0 +1,11 @@
|
||||
package graphdb
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/lightningnetwork/lnd/kvdb"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
kvdb.RunTests(m)
|
||||
}
|
@ -6,7 +6,7 @@ import (
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/lightningnetwork/lnd/batch"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||
"github.com/lightningnetwork/lnd/kvdb"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
@ -23,7 +23,7 @@ type ChannelGraphSource interface {
|
||||
// AddNode is used to add information about a node to the router
|
||||
// database. If the node with this pubkey is not present in an existing
|
||||
// channel, it will be ignored.
|
||||
AddNode(node *channeldb.LightningNode,
|
||||
AddNode(node *graphdb.LightningNode,
|
||||
op ...batch.SchedulerOption) error
|
||||
|
||||
// AddEdge is used to add edge/channel to the topology of the router,
|
||||
@ -85,10 +85,10 @@ type ChannelGraphSource interface {
|
||||
// FetchLightningNode attempts to look up a target node by its identity
|
||||
// public key. channeldb.ErrGraphNodeNotFound is returned if the node
|
||||
// doesn't exist within the graph.
|
||||
FetchLightningNode(route.Vertex) (*channeldb.LightningNode, error)
|
||||
FetchLightningNode(route.Vertex) (*graphdb.LightningNode, error)
|
||||
|
||||
// ForEachNode is used to iterate over every node in the known graph.
|
||||
ForEachNode(func(node *channeldb.LightningNode) error) error
|
||||
ForEachNode(func(node *graphdb.LightningNode) error) error
|
||||
}
|
||||
|
||||
// DB is an interface describing a persisted Lightning Network graph.
|
||||
@ -116,7 +116,7 @@ type DB interface {
|
||||
// channel within the known channel graph. The set of UTXO's (along with
|
||||
// their scripts) returned are the ones that need to be watched on
|
||||
// chain to detect channel closes on the resident blockchain.
|
||||
ChannelView() ([]channeldb.EdgePoint, error)
|
||||
ChannelView() ([]graphdb.EdgePoint, error)
|
||||
|
||||
// PruneGraphNodes is a garbage collection method which attempts to
|
||||
// prune out any nodes from the channel graph that are currently
|
||||
@ -129,7 +129,7 @@ type DB interface {
|
||||
// treated as the center node within a star-graph. This method may be
|
||||
// used to kick off a path finding algorithm in order to explore the
|
||||
// reachability of another node based off the source node.
|
||||
SourceNode() (*channeldb.LightningNode, error)
|
||||
SourceNode() (*graphdb.LightningNode, error)
|
||||
|
||||
// DisabledChannelIDs returns the channel ids of disabled channels.
|
||||
// A channel is disabled when two of the associated ChanelEdgePolicies
|
||||
@ -142,13 +142,13 @@ type DB interface {
|
||||
// edges that exist at the time of the query. This can be used to
|
||||
// respond to peer queries that are seeking to fill in gaps in their
|
||||
// view of the channel graph.
|
||||
FetchChanInfos(chanIDs []uint64) ([]channeldb.ChannelEdge, error)
|
||||
FetchChanInfos(chanIDs []uint64) ([]graphdb.ChannelEdge, error)
|
||||
|
||||
// ChanUpdatesInHorizon returns all the known channel edges which have
|
||||
// at least one edge that has an update timestamp within the specified
|
||||
// horizon.
|
||||
ChanUpdatesInHorizon(startTime, endTime time.Time) (
|
||||
[]channeldb.ChannelEdge, error)
|
||||
[]graphdb.ChannelEdge, error)
|
||||
|
||||
// DeleteChannelEdges removes edges with the given channel IDs from the
|
||||
// database and marks them as zombies. This ensures that we're unable to
|
||||
@ -200,7 +200,7 @@ type DB interface {
|
||||
// update that node's information. Note that this method is expected to
|
||||
// only be called to update an already present node from a node
|
||||
// announcement, or to insert a node found in a channel update.
|
||||
AddLightningNode(node *channeldb.LightningNode,
|
||||
AddLightningNode(node *graphdb.LightningNode,
|
||||
op ...batch.SchedulerOption) error
|
||||
|
||||
// AddChannelEdge adds a new (undirected, blank) edge to the graph
|
||||
@ -239,14 +239,14 @@ type DB interface {
|
||||
// FetchLightningNode attempts to look up a target node by its identity
|
||||
// public key. If the node isn't found in the database, then
|
||||
// ErrGraphNodeNotFound is returned.
|
||||
FetchLightningNode(nodePub route.Vertex) (*channeldb.LightningNode,
|
||||
FetchLightningNode(nodePub route.Vertex) (*graphdb.LightningNode,
|
||||
error)
|
||||
|
||||
// ForEachNode iterates through all the stored vertices/nodes in the
|
||||
// graph, executing the passed callback with each node encountered. If
|
||||
// the callback returns an error, then the transaction is aborted and
|
||||
// the iteration stops early.
|
||||
ForEachNode(cb func(kvdb.RTx, *channeldb.LightningNode) error) error
|
||||
ForEachNode(cb func(kvdb.RTx, *graphdb.LightningNode) error) error
|
||||
|
||||
// ForEachNodeChannel iterates through all channels of the given node,
|
||||
// executing the passed callback with an edge info structure and the
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
"github.com/btcsuite/btcd/btcutil"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/go-errors/errors"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
)
|
||||
@ -318,7 +318,7 @@ func addToTopologyChange(graph DB, update *TopologyChange,
|
||||
|
||||
// Any node announcement maps directly to a NetworkNodeUpdate struct.
|
||||
// No further data munging or db queries are required.
|
||||
case *channeldb.LightningNode:
|
||||
case *graphdb.LightningNode:
|
||||
pubKey, err := m.PubKey()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -18,6 +18,7 @@ import (
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
@ -77,14 +78,14 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func createTestNode(t *testing.T) *channeldb.LightningNode {
|
||||
func createTestNode(t *testing.T) *graphdb.LightningNode {
|
||||
updateTime := prand.Int63()
|
||||
|
||||
priv, err := btcec.NewPrivateKey()
|
||||
require.NoError(t, err)
|
||||
|
||||
pub := priv.PubKey().SerializeCompressed()
|
||||
n := &channeldb.LightningNode{
|
||||
n := &graphdb.LightningNode{
|
||||
HaveNodeAnnouncement: true,
|
||||
LastUpdate: time.Unix(updateTime, 0),
|
||||
Addresses: testAddrs,
|
||||
@ -99,7 +100,7 @@ func createTestNode(t *testing.T) *channeldb.LightningNode {
|
||||
}
|
||||
|
||||
func randEdgePolicy(chanID *lnwire.ShortChannelID,
|
||||
node *channeldb.LightningNode) (*models.ChannelEdgePolicy, error) {
|
||||
node *graphdb.LightningNode) (*models.ChannelEdgePolicy, error) {
|
||||
|
||||
InboundFee := models.InboundFee{
|
||||
Base: prand.Int31() * -1,
|
||||
@ -315,7 +316,7 @@ func (m *mockChainView) Reset() {
|
||||
m.staleBlocks = make(chan *chainview.FilteredBlock, 10)
|
||||
}
|
||||
|
||||
func (m *mockChainView) UpdateFilter(ops []channeldb.EdgePoint, updateHeight uint32) error {
|
||||
func (m *mockChainView) UpdateFilter(ops []graphdb.EdgePoint, updateHeight uint32) error {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
|
||||
@ -686,7 +687,7 @@ func TestNodeUpdateNotification(t *testing.T) {
|
||||
t.Fatalf("unable to add node: %v", err)
|
||||
}
|
||||
|
||||
assertNodeNtfnCorrect := func(t *testing.T, ann *channeldb.LightningNode,
|
||||
assertNodeNtfnCorrect := func(t *testing.T, ann *graphdb.LightningNode,
|
||||
nodeUpdate *NetworkNodeUpdate) {
|
||||
|
||||
nodeKey, _ := ann.PubKey()
|
||||
@ -1019,7 +1020,7 @@ func TestEncodeHexColor(t *testing.T) {
|
||||
type testCtx struct {
|
||||
builder *Builder
|
||||
|
||||
graph *channeldb.ChannelGraph
|
||||
graph *graphdb.ChannelGraph
|
||||
|
||||
aliases map[string]route.Vertex
|
||||
|
||||
@ -1088,7 +1089,7 @@ func (c *testCtx) RestartBuilder(t *testing.T) {
|
||||
|
||||
// makeTestGraph creates a new instance of a channeldb.ChannelGraph for testing
|
||||
// purposes.
|
||||
func makeTestGraph(t *testing.T, useCache bool) (*channeldb.ChannelGraph,
|
||||
func makeTestGraph(t *testing.T, useCache bool) (*graphdb.ChannelGraph,
|
||||
kvdb.Backend, error) {
|
||||
|
||||
// Create channelgraph for the first time.
|
||||
@ -1100,7 +1101,7 @@ func makeTestGraph(t *testing.T, useCache bool) (*channeldb.ChannelGraph,
|
||||
t.Cleanup(backendCleanup)
|
||||
|
||||
opts := channeldb.DefaultOptions()
|
||||
graph, err := channeldb.NewChannelGraph(
|
||||
graph, err := graphdb.NewChannelGraph(
|
||||
backend, opts.RejectCacheSize, opts.ChannelCacheSize,
|
||||
opts.BatchCommitInterval, opts.PreAllocCacheNumNodes,
|
||||
useCache, false,
|
||||
@ -1113,7 +1114,7 @@ func makeTestGraph(t *testing.T, useCache bool) (*channeldb.ChannelGraph,
|
||||
}
|
||||
|
||||
type testGraphInstance struct {
|
||||
graph *channeldb.ChannelGraph
|
||||
graph *graphdb.ChannelGraph
|
||||
graphBackend kvdb.Backend
|
||||
|
||||
// aliasMap is a map from a node's alias to its public key. This type is
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/routing/route"
|
||||
@ -151,7 +151,7 @@ func (v *ValidationBarrier) InitJobDependencies(job interface{}) {
|
||||
case *lnwire.NodeAnnouncement:
|
||||
// TODO(roasbeef): node ann needs to wait on existing channel updates
|
||||
return
|
||||
case *channeldb.LightningNode:
|
||||
case *graphdb.LightningNode:
|
||||
return
|
||||
case *lnwire.AnnounceSignatures1:
|
||||
// TODO(roasbeef): need to wait on chan ann?
|
||||
@ -195,7 +195,7 @@ func (v *ValidationBarrier) WaitForDependants(job interface{}) error {
|
||||
jobDesc = fmt.Sprintf("job=lnwire.ChannelEdgePolicy, scid=%v",
|
||||
msg.ChannelID)
|
||||
|
||||
case *channeldb.LightningNode:
|
||||
case *graphdb.LightningNode:
|
||||
vertex := route.Vertex(msg.PubKeyBytes)
|
||||
signals, ok = v.nodeAnnDependencies[vertex]
|
||||
|
||||
@ -291,7 +291,7 @@ func (v *ValidationBarrier) SignalDependants(job interface{}, allow bool) {
|
||||
// For all other job types, we'll delete the tracking entries from the
|
||||
// map, as if we reach this point, then all dependants have already
|
||||
// finished executing and we can proceed.
|
||||
case *channeldb.LightningNode:
|
||||
case *graphdb.LightningNode:
|
||||
delete(v.nodeAnnDependencies, route.Vertex(msg.PubKeyBytes))
|
||||
case *lnwire.NodeAnnouncement:
|
||||
delete(v.nodeAnnDependencies, route.Vertex(msg.NodeID))
|
||||
|
@ -5,7 +5,7 @@ package devrpc
|
||||
|
||||
import (
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||
)
|
||||
|
||||
@ -16,6 +16,6 @@ import (
|
||||
// also be specified.
|
||||
type Config struct {
|
||||
ActiveNetParams *chaincfg.Params
|
||||
GraphDB *channeldb.ChannelGraph
|
||||
GraphDB *graphdb.ChannelGraph
|
||||
Switch *htlcswitch.Switch
|
||||
}
|
||||
|
@ -16,8 +16,8 @@ import (
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/fn"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||
"github.com/lightningnetwork/lnd/lncfg"
|
||||
"github.com/lightningnetwork/lnd/lnrpc"
|
||||
@ -227,7 +227,7 @@ func (s *Server) ImportGraph(ctx context.Context,
|
||||
|
||||
var err error
|
||||
for _, rpcNode := range graph.Nodes {
|
||||
node := &channeldb.LightningNode{
|
||||
node := &graphdb.LightningNode{
|
||||
HaveNodeAnnouncement: true,
|
||||
LastUpdate: time.Unix(
|
||||
int64(rpcNode.LastUpdate), 0,
|
||||
|
@ -18,6 +18,7 @@ import (
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||
"github.com/lightningnetwork/lnd/invoices"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
@ -75,7 +76,7 @@ type AddInvoiceConfig struct {
|
||||
ChanDB *channeldb.ChannelStateDB
|
||||
|
||||
// Graph holds a reference to the ChannelGraph database.
|
||||
Graph *channeldb.ChannelGraph
|
||||
Graph *graphdb.ChannelGraph
|
||||
|
||||
// GenInvoiceFeatures returns a feature containing feature bits that
|
||||
// should be advertised on freshly generated invoices.
|
||||
|
@ -6,6 +6,7 @@ package invoicesrpc
|
||||
import (
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/invoices"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/macaroons"
|
||||
@ -53,7 +54,7 @@ type Config struct {
|
||||
|
||||
// GraphDB is a global database instance which is needed to access the
|
||||
// channel graph.
|
||||
GraphDB *channeldb.ChannelGraph
|
||||
GraphDB *graphdb.ChannelGraph
|
||||
|
||||
// ChanStateDB is a possibly replicated db instance which contains the
|
||||
// channel state
|
||||
|
2
log.go
2
log.go
@ -21,6 +21,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/discovery"
|
||||
"github.com/lightningnetwork/lnd/funding"
|
||||
"github.com/lightningnetwork/lnd/graph"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/healthcheck"
|
||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||
"github.com/lightningnetwork/lnd/invoices"
|
||||
@ -194,6 +195,7 @@ func SetupLoggers(root *build.SubLoggerManager, interceptor signal.Interceptor)
|
||||
AddSubLogger(
|
||||
root, blindedpath.Subsystem, interceptor, blindedpath.UseLogger,
|
||||
)
|
||||
AddV1SubLogger(root, graphdb.Subsystem, interceptor, graphdb.UseLogger)
|
||||
}
|
||||
|
||||
// AddSubLogger is a helper method to conveniently create and register the
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/keychain"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
@ -195,7 +196,7 @@ func (m *ChanStatusManager) start() error {
|
||||
// have been pruned from the channel graph but not yet from our
|
||||
// set of channels. We'll skip it as we can't determine its
|
||||
// initial state.
|
||||
case errors.Is(err, channeldb.ErrEdgeNotFound):
|
||||
case errors.Is(err, graphdb.ErrEdgeNotFound):
|
||||
log.Warnf("Unable to find channel policies for %v, "+
|
||||
"skipping. This is typical if the channel is "+
|
||||
"in the process of closing.", c.FundingOutpoint)
|
||||
@ -580,7 +581,7 @@ func (m *ChanStatusManager) disableInactiveChannels() {
|
||||
// that the channel has been closed. Thus we remove the
|
||||
// outpoint from the set of tracked outpoints to prevent
|
||||
// further attempts.
|
||||
if errors.Is(err, channeldb.ErrEdgeNotFound) {
|
||||
if errors.Is(err, graphdb.ErrEdgeNotFound) {
|
||||
log.Debugf("Removing channel(%v) from "+
|
||||
"consideration for passive disabling",
|
||||
outpoint)
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||
"github.com/lightningnetwork/lnd/keychain"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
@ -168,7 +169,7 @@ func (g *mockGraph) FetchChannelEdgesByOutpoint(
|
||||
|
||||
info, ok := g.chanInfos[*op]
|
||||
if !ok {
|
||||
return nil, nil, nil, channeldb.ErrEdgeNotFound
|
||||
return nil, nil, nil, graphdb.ErrEdgeNotFound
|
||||
}
|
||||
|
||||
pol1 := g.chanPols1[*op]
|
||||
@ -697,7 +698,7 @@ var stateMachineTests = []stateMachineTest{
|
||||
// Request that they be enabled, which should return an
|
||||
// error as the graph doesn't have an edge for them.
|
||||
h.assertEnables(
|
||||
unknownChans, channeldb.ErrEdgeNotFound, false,
|
||||
unknownChans, graphdb.ErrEdgeNotFound, false,
|
||||
)
|
||||
// No updates should be sent as a result of the failure.
|
||||
h.assertNoUpdates(h.safeDisableTimeout)
|
||||
@ -717,7 +718,7 @@ var stateMachineTests = []stateMachineTest{
|
||||
// Request that they be disabled, which should return an
|
||||
// error as the graph doesn't have an edge for them.
|
||||
h.assertDisables(
|
||||
unknownChans, channeldb.ErrEdgeNotFound, false,
|
||||
unknownChans, graphdb.ErrEdgeNotFound, false,
|
||||
)
|
||||
// No updates should be sent as a result of the failure.
|
||||
h.assertNoUpdates(h.safeDisableTimeout)
|
||||
@ -747,7 +748,7 @@ var stateMachineTests = []stateMachineTest{
|
||||
|
||||
// Check that trying to enable the channel with unknown
|
||||
// edges results in a failure.
|
||||
h.assertEnables(newChans, channeldb.ErrEdgeNotFound, false)
|
||||
h.assertEnables(newChans, graphdb.ErrEdgeNotFound, false)
|
||||
|
||||
// Now, insert edge policies for the channel into the
|
||||
// graph, starting with the channel enabled, and mark
|
||||
@ -794,7 +795,9 @@ var stateMachineTests = []stateMachineTest{
|
||||
|
||||
// Check that trying to enable the channel with unknown
|
||||
// edges results in a failure.
|
||||
h.assertDisables(rmChans, channeldb.ErrEdgeNotFound, false)
|
||||
h.assertDisables(
|
||||
rmChans, graphdb.ErrEdgeNotFound, false,
|
||||
)
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -28,6 +28,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/feature"
|
||||
"github.com/lightningnetwork/lnd/fn"
|
||||
"github.com/lightningnetwork/lnd/funding"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||
"github.com/lightningnetwork/lnd/htlcswitch/hodl"
|
||||
@ -235,7 +236,7 @@ type Config struct {
|
||||
|
||||
// ChannelGraph is a pointer to the channel graph which is used to
|
||||
// query information about the set of known active channels.
|
||||
ChannelGraph *channeldb.ChannelGraph
|
||||
ChannelGraph *graphdb.ChannelGraph
|
||||
|
||||
// ChainArb is used to subscribe to channel events, update contract signals,
|
||||
// and force close channels.
|
||||
@ -1098,7 +1099,7 @@ func (p *Brontide) loadActiveChannels(chans []*channeldb.OpenChannel) (
|
||||
info, p1, p2, err := graph.FetchChannelEdgesByOutpoint(
|
||||
&chanPoint,
|
||||
)
|
||||
if err != nil && !errors.Is(err, channeldb.ErrEdgeNotFound) {
|
||||
if err != nil && !errors.Is(err, graphdb.ErrEdgeNotFound) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -3,8 +3,8 @@ package routing
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/fn"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/routing/route"
|
||||
@ -96,7 +96,7 @@ func newBandwidthManager(graph Graph, sourceNode route.Vertex,
|
||||
// First, we'll collect the set of outbound edges from the target
|
||||
// source node and add them to our bandwidth manager's map of channels.
|
||||
err := graph.ForEachNodeChannel(sourceNode,
|
||||
func(channel *channeldb.DirectedChannel) error {
|
||||
func(channel *graphdb.DirectedChannel) error {
|
||||
shortID := lnwire.NewShortChanIDFromInt(
|
||||
channel.ChannelID,
|
||||
)
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
"github.com/btcsuite/btcwallet/chain"
|
||||
"github.com/btcsuite/btcwallet/wtxmgr"
|
||||
"github.com/lightningnetwork/lnd/blockcache"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
)
|
||||
|
||||
// BitcoindFilteredChainView is an implementation of the FilteredChainView
|
||||
@ -448,7 +448,7 @@ func (b *BitcoindFilteredChainView) chainFilterer() {
|
||||
// rewound to ensure all relevant notifications are dispatched.
|
||||
//
|
||||
// NOTE: This is part of the FilteredChainView interface.
|
||||
func (b *BitcoindFilteredChainView) UpdateFilter(ops []channeldb.EdgePoint,
|
||||
func (b *BitcoindFilteredChainView) UpdateFilter(ops []graphdb.EdgePoint,
|
||||
updateHeight uint32) error {
|
||||
|
||||
newUtxos := make([]wire.OutPoint, len(ops))
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
"github.com/btcsuite/btcd/rpcclient"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/lightningnetwork/lnd/blockcache"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
)
|
||||
|
||||
// BtcdFilteredChainView is an implementation of the FilteredChainView
|
||||
@ -456,7 +456,7 @@ type filterUpdate struct {
|
||||
// rewound to ensure all relevant notifications are dispatched.
|
||||
//
|
||||
// NOTE: This is part of the FilteredChainView interface.
|
||||
func (b *BtcdFilteredChainView) UpdateFilter(ops []channeldb.EdgePoint,
|
||||
func (b *BtcdFilteredChainView) UpdateFilter(ops []graphdb.EdgePoint,
|
||||
updateHeight uint32) error {
|
||||
|
||||
newUtxos := make([]wire.OutPoint, len(ops))
|
||||
|
@ -3,7 +3,7 @@ package chainview
|
||||
import (
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
)
|
||||
|
||||
// FilteredChainView represents a subscription to a certain subset of the
|
||||
@ -43,7 +43,7 @@ type FilteredChainView interface {
|
||||
// relevant notifications are dispatched, meaning blocks with a height
|
||||
// lower than the best known height might be sent over the
|
||||
// FilteredBlocks() channel.
|
||||
UpdateFilter(ops []channeldb.EdgePoint, updateHeight uint32) error
|
||||
UpdateFilter(ops []graphdb.EdgePoint, updateHeight uint32) error
|
||||
|
||||
// FilterBlock takes a block hash, and returns a FilteredBlocks which
|
||||
// is the result of applying the current registered UTXO sub-set on the
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
_ "github.com/btcsuite/btcwallet/walletdb/bdb" // Required to register the boltdb walletdb implementation.
|
||||
"github.com/lightninglabs/neutrino"
|
||||
"github.com/lightningnetwork/lnd/blockcache"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/kvdb"
|
||||
"github.com/lightningnetwork/lnd/lntest/unittest"
|
||||
"github.com/lightningnetwork/lnd/lntest/wait"
|
||||
@ -218,7 +218,7 @@ func testFilterBlockNotifications(node *rpctest.Harness,
|
||||
require.NoError(t, err, "unable to get current height")
|
||||
|
||||
// Now we'll add both outpoints to the current filter.
|
||||
filter := []channeldb.EdgePoint{
|
||||
filter := []graphdb.EdgePoint{
|
||||
{FundingPkScript: targetScript, OutPoint: *outPoint1},
|
||||
{FundingPkScript: targetScript, OutPoint: *outPoint2},
|
||||
}
|
||||
@ -328,7 +328,7 @@ func testUpdateFilterBackTrack(node *rpctest.Harness,
|
||||
|
||||
// After the block has been mined+notified we'll update the filter with
|
||||
// a _prior_ height so a "rewind" occurs.
|
||||
filter := []channeldb.EdgePoint{
|
||||
filter := []graphdb.EdgePoint{
|
||||
{FundingPkScript: testScript, OutPoint: *outPoint},
|
||||
}
|
||||
err = chainView.UpdateFilter(filter, uint32(currentHeight))
|
||||
@ -417,7 +417,7 @@ func testFilterSingleBlock(node *rpctest.Harness, chainView FilteredChainView,
|
||||
|
||||
// Now we'll manually trigger filtering the block generated above.
|
||||
// First, we'll add the two outpoints to our filter.
|
||||
filter := []channeldb.EdgePoint{
|
||||
filter := []graphdb.EdgePoint{
|
||||
{FundingPkScript: testScript, OutPoint: *outPoint1},
|
||||
{FundingPkScript: testScript, OutPoint: *outPoint2},
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/lightninglabs/neutrino"
|
||||
"github.com/lightningnetwork/lnd/blockcache"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
)
|
||||
|
||||
@ -320,7 +320,7 @@ func (c *CfFilteredChainView) FilterBlock(blockHash *chainhash.Hash) (*FilteredB
|
||||
// rewound to ensure all relevant notifications are dispatched.
|
||||
//
|
||||
// NOTE: This is part of the FilteredChainView interface.
|
||||
func (c *CfFilteredChainView) UpdateFilter(ops []channeldb.EdgePoint,
|
||||
func (c *CfFilteredChainView) UpdateFilter(ops []graphdb.EdgePoint,
|
||||
updateHeight uint32) error {
|
||||
|
||||
log.Tracef("Updating chain filter with new UTXO's: %v", ops)
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/btcsuite/btcd/btcutil"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/routing/route"
|
||||
)
|
||||
@ -15,7 +15,7 @@ type Graph interface {
|
||||
// ForEachNodeChannel calls the callback for every channel of the given
|
||||
// node.
|
||||
ForEachNodeChannel(nodePub route.Vertex,
|
||||
cb func(channel *channeldb.DirectedChannel) error) error
|
||||
cb func(channel *graphdb.DirectedChannel) error) error
|
||||
|
||||
// FetchNodeFeatures returns the features of the given node.
|
||||
FetchNodeFeatures(nodePub route.Vertex) (*lnwire.FeatureVector, error)
|
||||
|
@ -7,8 +7,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/fn"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/kvdb"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/routing/route"
|
||||
@ -338,11 +338,11 @@ var _ GraphSessionFactory = (*mockGraphSessionFactory)(nil)
|
||||
var _ Graph = (*mockGraphSessionFactory)(nil)
|
||||
|
||||
type mockGraphSessionFactoryChanDB struct {
|
||||
graph *channeldb.ChannelGraph
|
||||
graph *graphdb.ChannelGraph
|
||||
}
|
||||
|
||||
func newMockGraphSessionFactoryFromChanDB(
|
||||
graph *channeldb.ChannelGraph) *mockGraphSessionFactoryChanDB {
|
||||
graph *graphdb.ChannelGraph) *mockGraphSessionFactoryChanDB {
|
||||
|
||||
return &mockGraphSessionFactoryChanDB{
|
||||
graph: graph,
|
||||
@ -368,11 +368,11 @@ func (g *mockGraphSessionFactoryChanDB) NewGraphSession() (Graph, func() error,
|
||||
var _ GraphSessionFactory = (*mockGraphSessionFactoryChanDB)(nil)
|
||||
|
||||
type mockGraphSessionChanDB struct {
|
||||
graph *channeldb.ChannelGraph
|
||||
graph *graphdb.ChannelGraph
|
||||
tx kvdb.RTx
|
||||
}
|
||||
|
||||
func newMockGraphSessionChanDB(graph *channeldb.ChannelGraph) Graph {
|
||||
func newMockGraphSessionChanDB(graph *graphdb.ChannelGraph) Graph {
|
||||
return &mockGraphSessionChanDB{
|
||||
graph: graph,
|
||||
}
|
||||
@ -392,7 +392,7 @@ func (g *mockGraphSessionChanDB) close() error {
|
||||
}
|
||||
|
||||
func (g *mockGraphSessionChanDB) ForEachNodeChannel(nodePub route.Vertex,
|
||||
cb func(channel *channeldb.DirectedChannel) error) error {
|
||||
cb func(channel *graphdb.DirectedChannel) error) error {
|
||||
|
||||
return g.graph.ForEachNodeDirectedChannel(g.tx, nodePub, cb)
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
"github.com/btcsuite/btcd/btcutil"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/routing/route"
|
||||
@ -166,12 +166,12 @@ func (m *mockGraph) addChannel(id uint64, node1id, node2id byte,
|
||||
//
|
||||
// NOTE: Part of the Graph interface.
|
||||
func (m *mockGraph) ForEachNodeChannel(nodePub route.Vertex,
|
||||
cb func(channel *channeldb.DirectedChannel) error) error {
|
||||
cb func(channel *graphdb.DirectedChannel) error) error {
|
||||
|
||||
// Look up the mock node.
|
||||
node, ok := m.nodes[nodePub]
|
||||
if !ok {
|
||||
return channeldb.ErrGraphNodeNotFound
|
||||
return graphdb.ErrGraphNodeNotFound
|
||||
}
|
||||
|
||||
// Iterate over all of its channels.
|
||||
@ -188,7 +188,7 @@ func (m *mockGraph) ForEachNodeChannel(nodePub route.Vertex,
|
||||
|
||||
// Call the per channel callback.
|
||||
err := cb(
|
||||
&channeldb.DirectedChannel{
|
||||
&graphdb.DirectedChannel{
|
||||
ChannelID: channel.id,
|
||||
IsNode1: nodePub == node1,
|
||||
OtherNode: peer,
|
||||
|
@ -11,9 +11,9 @@ import (
|
||||
|
||||
"github.com/btcsuite/btcd/btcutil"
|
||||
sphinx "github.com/lightningnetwork/lightning-onion"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/feature"
|
||||
"github.com/lightningnetwork/lnd/fn"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||
"github.com/lightningnetwork/lnd/lnutils"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
@ -496,7 +496,7 @@ func getOutgoingBalance(node route.Vertex, outgoingChans map[uint64]struct{},
|
||||
g Graph) (lnwire.MilliSatoshi, lnwire.MilliSatoshi, error) {
|
||||
|
||||
var max, total lnwire.MilliSatoshi
|
||||
cb := func(channel *channeldb.DirectedChannel) error {
|
||||
cb := func(channel *graphdb.DirectedChannel) error {
|
||||
if !channel.OutPolicySet {
|
||||
return nil
|
||||
}
|
||||
@ -1299,7 +1299,7 @@ func processNodeForBlindedPath(g Graph, node route.Vertex,
|
||||
// Now, iterate over the node's channels in search for paths to this
|
||||
// node that can be used for blinded paths
|
||||
err = g.ForEachNodeChannel(node,
|
||||
func(channel *channeldb.DirectedChannel) error {
|
||||
func(channel *graphdb.DirectedChannel) error {
|
||||
// Keep track of how many incoming channels this node
|
||||
// has. We only use a node as an introduction node if it
|
||||
// has channels other than the one that lead us to it.
|
||||
|
@ -23,6 +23,7 @@ import (
|
||||
sphinx "github.com/lightningnetwork/lightning-onion"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/fn"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||
switchhop "github.com/lightningnetwork/lnd/htlcswitch/hop"
|
||||
@ -155,7 +156,7 @@ type testChan struct {
|
||||
|
||||
// makeTestGraph creates a new instance of a channeldb.ChannelGraph for testing
|
||||
// purposes.
|
||||
func makeTestGraph(t *testing.T, useCache bool) (*channeldb.ChannelGraph,
|
||||
func makeTestGraph(t *testing.T, useCache bool) (*graphdb.ChannelGraph,
|
||||
kvdb.Backend, error) {
|
||||
|
||||
// Create channelgraph for the first time.
|
||||
@ -167,7 +168,7 @@ func makeTestGraph(t *testing.T, useCache bool) (*channeldb.ChannelGraph,
|
||||
t.Cleanup(backendCleanup)
|
||||
|
||||
opts := channeldb.DefaultOptions()
|
||||
graph, err := channeldb.NewChannelGraph(
|
||||
graph, err := graphdb.NewChannelGraph(
|
||||
backend, opts.RejectCacheSize, opts.ChannelCacheSize,
|
||||
opts.BatchCommitInterval, opts.PreAllocCacheNumNodes,
|
||||
useCache, false,
|
||||
@ -217,7 +218,7 @@ func parseTestGraph(t *testing.T, useCache bool, path string) (
|
||||
privKeyMap := make(map[string]*btcec.PrivateKey)
|
||||
channelIDs := make(map[route.Vertex]map[route.Vertex]uint64)
|
||||
links := make(map[lnwire.ShortChannelID]htlcswitch.ChannelLink)
|
||||
var source *channeldb.LightningNode
|
||||
var source *graphdb.LightningNode
|
||||
|
||||
// First we insert all the nodes within the graph as vertexes.
|
||||
for _, node := range g.Nodes {
|
||||
@ -226,7 +227,7 @@ func parseTestGraph(t *testing.T, useCache bool, path string) (
|
||||
return nil, err
|
||||
}
|
||||
|
||||
dbNode := &channeldb.LightningNode{
|
||||
dbNode := &graphdb.LightningNode{
|
||||
HaveNodeAnnouncement: true,
|
||||
AuthSigBytes: testSig.Serialize(),
|
||||
LastUpdate: testTime,
|
||||
@ -357,7 +358,7 @@ func parseTestGraph(t *testing.T, useCache bool, path string) (
|
||||
}
|
||||
|
||||
err = graph.AddChannelEdge(&edgeInfo)
|
||||
if err != nil && err != channeldb.ErrEdgeAlreadyExist {
|
||||
if err != nil && err != graphdb.ErrEdgeAlreadyExist {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -477,7 +478,7 @@ type testChannel struct {
|
||||
}
|
||||
|
||||
type testGraphInstance struct {
|
||||
graph *channeldb.ChannelGraph
|
||||
graph *graphdb.ChannelGraph
|
||||
graphBackend kvdb.Backend
|
||||
|
||||
// aliasMap is a map from a node's alias to its public key. This type is
|
||||
@ -539,7 +540,7 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
|
||||
|
||||
nodeIndex := byte(0)
|
||||
addNodeWithAlias := func(alias string, features *lnwire.FeatureVector) (
|
||||
*channeldb.LightningNode, error) {
|
||||
*graphdb.LightningNode, error) {
|
||||
|
||||
keyBytes := []byte{
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
@ -554,7 +555,7 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
|
||||
features = lnwire.EmptyFeatureVector()
|
||||
}
|
||||
|
||||
dbNode := &channeldb.LightningNode{
|
||||
dbNode := &graphdb.LightningNode{
|
||||
HaveNodeAnnouncement: true,
|
||||
AuthSigBytes: testSig.Serialize(),
|
||||
LastUpdate: testTime,
|
||||
@ -665,7 +666,7 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
|
||||
}
|
||||
|
||||
err = graph.AddChannelEdge(&edgeInfo)
|
||||
if err != nil && err != channeldb.ErrEdgeAlreadyExist {
|
||||
if err != nil && err != graphdb.ErrEdgeAlreadyExist {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -1210,7 +1211,7 @@ func runPathFindingWithAdditionalEdges(t *testing.T, useCache bool) {
|
||||
dogePubKey, err := btcec.ParsePubKey(dogePubKeyBytes)
|
||||
require.NoError(t, err, "unable to parse public key from bytes")
|
||||
|
||||
doge := &channeldb.LightningNode{}
|
||||
doge := &graphdb.LightningNode{}
|
||||
doge.AddPubKey(dogePubKey)
|
||||
doge.Alias = "doge"
|
||||
copy(doge.PubKeyBytes[:], dogePubKeyBytes)
|
||||
@ -3026,7 +3027,7 @@ func runInboundFees(t *testing.T, useCache bool) {
|
||||
|
||||
type pathFindingTestContext struct {
|
||||
t *testing.T
|
||||
graph *channeldb.ChannelGraph
|
||||
graph *graphdb.ChannelGraph
|
||||
restrictParams RestrictParams
|
||||
bandwidthHints bandwidthHints
|
||||
pathFindingConfig PathFindingConfig
|
||||
@ -3108,7 +3109,7 @@ func (c *pathFindingTestContext) assertPath(path []*unifiedEdge,
|
||||
|
||||
// dbFindPath calls findPath after getting a db transaction from the database
|
||||
// graph.
|
||||
func dbFindPath(graph *channeldb.ChannelGraph,
|
||||
func dbFindPath(graph *graphdb.ChannelGraph,
|
||||
additionalEdges map[route.Vertex][]AdditionalEdge,
|
||||
bandwidthHints bandwidthHints,
|
||||
r *RestrictParams, cfg *PathFindingConfig,
|
||||
@ -3148,7 +3149,7 @@ func dbFindPath(graph *channeldb.ChannelGraph,
|
||||
|
||||
// dbFindBlindedPaths calls findBlindedPaths after getting a db transaction from
|
||||
// the database graph.
|
||||
func dbFindBlindedPaths(graph *channeldb.ChannelGraph,
|
||||
func dbFindBlindedPaths(graph *graphdb.ChannelGraph,
|
||||
restrictions *blindedPathRestrictions) ([][]blindedHop, error) {
|
||||
|
||||
sourceNode, err := graph.SourceNode()
|
||||
|
@ -2,8 +2,8 @@ package routing
|
||||
|
||||
import (
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/fn"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/routing/route"
|
||||
@ -24,7 +24,7 @@ type SessionSource struct {
|
||||
GraphSessionFactory GraphSessionFactory
|
||||
|
||||
// SourceNode is the graph's source node.
|
||||
SourceNode *channeldb.LightningNode
|
||||
SourceNode *graphdb.LightningNode
|
||||
|
||||
// GetLink is a method that allows querying the lower link layer
|
||||
// to determine the up to date available bandwidth at a prospective link
|
||||
@ -101,7 +101,7 @@ func RouteHintsToEdges(routeHints [][]zpay32.HopHint, target route.Vertex) (
|
||||
// we'll need to look at the next hint's start node. If
|
||||
// we've reached the end of the hints list, we can
|
||||
// assume we've reached the destination.
|
||||
endNode := &channeldb.LightningNode{}
|
||||
endNode := &graphdb.LightningNode{}
|
||||
if i != len(routeHint)-1 {
|
||||
endNode.AddPubKey(routeHint[i+1].NodeID)
|
||||
} else {
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
@ -89,7 +89,7 @@ func TestUpdateAdditionalEdge(t *testing.T) {
|
||||
|
||||
// Create a minimal test node using the private key priv1.
|
||||
pub := priv1.PubKey().SerializeCompressed()
|
||||
testNode := &channeldb.LightningNode{}
|
||||
testNode := &graphdb.LightningNode{}
|
||||
copy(testNode.PubKeyBytes[:], pub)
|
||||
|
||||
nodeID, err := testNode.PubKey()
|
||||
|
@ -25,6 +25,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/clock"
|
||||
"github.com/lightningnetwork/lnd/fn"
|
||||
"github.com/lightningnetwork/lnd/graph"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
@ -68,7 +69,7 @@ type testCtx struct {
|
||||
|
||||
graphBuilder *mockGraphBuilder
|
||||
|
||||
graph *channeldb.ChannelGraph
|
||||
graph *graphdb.ChannelGraph
|
||||
|
||||
aliases map[string]route.Vertex
|
||||
|
||||
@ -191,7 +192,7 @@ func createTestCtxFromGraphInstanceAssumeValid(t *testing.T,
|
||||
return ctx
|
||||
}
|
||||
|
||||
func createTestNode() (*channeldb.LightningNode, error) {
|
||||
func createTestNode() (*graphdb.LightningNode, error) {
|
||||
updateTime := rand.Int63()
|
||||
|
||||
priv, err := btcec.NewPrivateKey()
|
||||
@ -200,7 +201,7 @@ func createTestNode() (*channeldb.LightningNode, error) {
|
||||
}
|
||||
|
||||
pub := priv.PubKey().SerializeCompressed()
|
||||
n := &channeldb.LightningNode{
|
||||
n := &graphdb.LightningNode{
|
||||
HaveNodeAnnouncement: true,
|
||||
LastUpdate: time.Unix(updateTime, 0),
|
||||
Addresses: testAddrs,
|
||||
@ -2898,7 +2899,7 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
|
||||
|
||||
// Now check that we can update the node info for the partial node
|
||||
// without messing up the channel graph.
|
||||
n1 := &channeldb.LightningNode{
|
||||
n1 := &graphdb.LightningNode{
|
||||
HaveNodeAnnouncement: true,
|
||||
LastUpdate: time.Unix(123, 0),
|
||||
Addresses: testAddrs,
|
||||
@ -2911,7 +2912,7 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
|
||||
|
||||
require.NoError(t, ctx.graph.AddLightningNode(n1))
|
||||
|
||||
n2 := &channeldb.LightningNode{
|
||||
n2 := &graphdb.LightningNode{
|
||||
HaveNodeAnnouncement: true,
|
||||
LastUpdate: time.Unix(123, 0),
|
||||
Addresses: testAddrs,
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"math"
|
||||
|
||||
"github.com/btcsuite/btcd/btcutil"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
@ -95,7 +95,7 @@ func (u *nodeEdgeUnifier) addPolicy(fromNode route.Vertex,
|
||||
// addGraphPolicies adds all policies that are known for the toNode in the
|
||||
// graph.
|
||||
func (u *nodeEdgeUnifier) addGraphPolicies(g Graph) error {
|
||||
cb := func(channel *channeldb.DirectedChannel) error {
|
||||
cb := func(channel *graphdb.DirectedChannel) error {
|
||||
// If there is no edge policy for this candidate node, skip.
|
||||
// Note that we are searching backwards so this node would have
|
||||
// come prior to the pivot node in the route.
|
||||
|
15
rpcserver.go
15
rpcserver.go
@ -50,6 +50,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/fn"
|
||||
"github.com/lightningnetwork/lnd/funding"
|
||||
"github.com/lightningnetwork/lnd/graph"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||
"github.com/lightningnetwork/lnd/htlcswitch/hop"
|
||||
@ -3037,7 +3038,7 @@ func createRPCCloseUpdate(
|
||||
// abandonChanFromGraph attempts to remove a channel from the channel graph. If
|
||||
// we can't find the chanID in the graph, then we assume it has already been
|
||||
// removed, and will return a nop.
|
||||
func abandonChanFromGraph(chanGraph *channeldb.ChannelGraph,
|
||||
func abandonChanFromGraph(chanGraph *graphdb.ChannelGraph,
|
||||
chanPoint *wire.OutPoint) error {
|
||||
|
||||
// First, we'll obtain the channel ID. If we can't locate this, then
|
||||
@ -3045,7 +3046,7 @@ func abandonChanFromGraph(chanGraph *channeldb.ChannelGraph,
|
||||
// the graph, so we'll return a nil error.
|
||||
chanID, err := chanGraph.ChannelID(chanPoint)
|
||||
switch {
|
||||
case errors.Is(err, channeldb.ErrEdgeNotFound):
|
||||
case errors.Is(err, graphdb.ErrEdgeNotFound):
|
||||
return nil
|
||||
case err != nil:
|
||||
return err
|
||||
@ -6532,7 +6533,7 @@ func (r *rpcServer) DescribeGraph(ctx context.Context,
|
||||
// First iterate through all the known nodes (connected or unconnected
|
||||
// within the graph), collating their current state into the RPC
|
||||
// response.
|
||||
err := graph.ForEachNode(func(_ kvdb.RTx, node *channeldb.LightningNode) error {
|
||||
err := graph.ForEachNode(func(_ kvdb.RTx, node *graphdb.LightningNode) error {
|
||||
lnNode := marshalNode(node)
|
||||
|
||||
resp.Nodes = append(resp.Nodes, lnNode)
|
||||
@ -6562,7 +6563,7 @@ func (r *rpcServer) DescribeGraph(ctx context.Context,
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil && err != channeldb.ErrGraphNoEdgesFound {
|
||||
if err != nil && err != graphdb.ErrGraphNoEdgesFound {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -6808,7 +6809,7 @@ func (r *rpcServer) GetNodeInfo(ctx context.Context,
|
||||
// be returned.
|
||||
node, err := graph.FetchLightningNode(pubKey)
|
||||
switch {
|
||||
case err == channeldb.ErrGraphNodeNotFound:
|
||||
case err == graphdb.ErrGraphNodeNotFound:
|
||||
return nil, status.Error(codes.NotFound, err.Error())
|
||||
case err != nil:
|
||||
return nil, err
|
||||
@ -6860,7 +6861,7 @@ func (r *rpcServer) GetNodeInfo(ctx context.Context,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func marshalNode(node *channeldb.LightningNode) *lnrpc.LightningNode {
|
||||
func marshalNode(node *graphdb.LightningNode) *lnrpc.LightningNode {
|
||||
nodeAddrs := make([]*lnrpc.NodeAddress, len(node.Addresses))
|
||||
for i, addr := range node.Addresses {
|
||||
nodeAddr := &lnrpc.NodeAddress{
|
||||
@ -6931,7 +6932,7 @@ func (r *rpcServer) GetNetworkInfo(ctx context.Context,
|
||||
// each node so we can measure the graph diameter and degree stats
|
||||
// below.
|
||||
err := graph.ForEachNodeCached(func(node route.Vertex,
|
||||
edges map[uint64]*channeldb.DirectedChannel) error {
|
||||
edges map[uint64]*graphdb.DirectedChannel) error {
|
||||
|
||||
// Increment the total number of nodes with each iteration.
|
||||
numNodes++
|
||||
|
11
server.go
11
server.go
@ -43,6 +43,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/fn"
|
||||
"github.com/lightningnetwork/lnd/funding"
|
||||
"github.com/lightningnetwork/lnd/graph"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||
"github.com/lightningnetwork/lnd/healthcheck"
|
||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||
@ -258,7 +259,7 @@ type server struct {
|
||||
|
||||
fundingMgr *funding.Manager
|
||||
|
||||
graphDB *channeldb.ChannelGraph
|
||||
graphDB *graphdb.ChannelGraph
|
||||
|
||||
chanStateDB *channeldb.ChannelStateDB
|
||||
|
||||
@ -878,7 +879,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selfNode := &channeldb.LightningNode{
|
||||
selfNode := &graphdb.LightningNode{
|
||||
HaveNodeAnnouncement: true,
|
||||
LastUpdate: time.Now(),
|
||||
Addresses: selfAddrs,
|
||||
@ -1389,7 +1390,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
|
||||
info, e1, e2, err := s.graphDB.FetchChannelEdgesByID(
|
||||
scid.ToUint64(),
|
||||
)
|
||||
if errors.Is(err, channeldb.ErrEdgeNotFound) {
|
||||
if errors.Is(err, graphdb.ErrEdgeNotFound) {
|
||||
// This is unlikely but there is a slim chance of this
|
||||
// being hit if lnd was killed via SIGKILL and the
|
||||
// funding manager was stepping through the delete
|
||||
@ -3185,7 +3186,7 @@ func (s *server) createNewHiddenService() error {
|
||||
|
||||
// Finally, we'll update the on-disk version of our announcement so it
|
||||
// will eventually propagate to nodes in the network.
|
||||
selfNode := &channeldb.LightningNode{
|
||||
selfNode := &graphdb.LightningNode{
|
||||
HaveNodeAnnouncement: true,
|
||||
LastUpdate: time.Unix(int64(newNodeAnn.Timestamp), 0),
|
||||
Addresses: newNodeAnn.Addresses,
|
||||
@ -3448,7 +3449,7 @@ func (s *server) establishPersistentConnections() error {
|
||||
nodeAddrsMap[pubStr] = n
|
||||
return nil
|
||||
})
|
||||
if err != nil && err != channeldb.ErrGraphNoEdgesFound {
|
||||
if err != nil && err != graphdb.ErrGraphNoEdgesFound {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/chainreg"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/fn"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||
"github.com/lightningnetwork/lnd/invoices"
|
||||
"github.com/lightningnetwork/lnd/lncfg"
|
||||
@ -112,7 +113,7 @@ func (s *subRPCServerConfigs) PopulateDependencies(cfg *Config,
|
||||
chanRouter *routing.ChannelRouter,
|
||||
routerBackend *routerrpc.RouterBackend,
|
||||
nodeSigner *netann.NodeSigner,
|
||||
graphDB *channeldb.ChannelGraph,
|
||||
graphDB *graphdb.ChannelGraph,
|
||||
chanStateDB *channeldb.ChannelStateDB,
|
||||
sweeper *sweep.UtxoSweeper,
|
||||
tower *watchtower.Standalone,
|
||||
|
Loading…
x
Reference in New Issue
Block a user