multi: move LightningNode struct to models package
This commit is contained in:
20 files changed
+252
-246
No files matched your search
+6
-6
@@ -58,7 +58,7 @@ type dbNode struct {
|
|||||||
|
|
||||||
tx kvdb.RTx
|
tx kvdb.RTx
|
||||||
|
|
||||||
node *graphdb.LightningNode
|
node *models.LightningNode
|
||||||
}
|
}
|
||||||
|
|
||||||
// A compile time assertion to ensure dbNode meets the autopilot.Node
|
// 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.
|
// NOTE: Part of the autopilot.ChannelGraph interface.
|
||||||
func (d *databaseChannelGraph) ForEachNode(cb func(Node) error) error {
|
func (d *databaseChannelGraph) ForEachNode(cb func(Node) error) error {
|
||||||
return d.db.ForEachNode(func(tx kvdb.RTx, n *graphdb.LightningNode) error {
|
return d.db.ForEachNode(func(tx kvdb.RTx, n *models.LightningNode) error {
|
||||||
// We'll skip over any node that doesn't have any advertised
|
// We'll skip over any node that doesn't have any advertised
|
||||||
// addresses. As we won't be able to reach them to actually
|
// addresses. As we won't be able to reach them to actually
|
||||||
// open any channels.
|
// open any channels.
|
||||||
@@ -157,7 +157,7 @@ func (d *databaseChannelGraph) ForEachNode(cb func(Node) error) error {
|
|||||||
func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
|
func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
|
||||||
capacity btcutil.Amount) (*ChannelEdge, *ChannelEdge, error) {
|
capacity btcutil.Amount) (*ChannelEdge, *ChannelEdge, error) {
|
||||||
|
|
||||||
fetchNode := func(pub *btcec.PublicKey) (*graphdb.LightningNode, error) {
|
fetchNode := func(pub *btcec.PublicKey) (*models.LightningNode, error) {
|
||||||
if pub != nil {
|
if pub != nil {
|
||||||
vertex, err := route.NewVertexFromBytes(
|
vertex, err := route.NewVertexFromBytes(
|
||||||
pub.SerializeCompressed(),
|
pub.SerializeCompressed(),
|
||||||
@@ -171,7 +171,7 @@ func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
|
|||||||
case err == graphdb.ErrGraphNodeNotFound:
|
case err == graphdb.ErrGraphNodeNotFound:
|
||||||
fallthrough
|
fallthrough
|
||||||
case err == graphdb.ErrGraphNotFound:
|
case err == graphdb.ErrGraphNotFound:
|
||||||
graphNode := &graphdb.LightningNode{
|
graphNode := &models.LightningNode{
|
||||||
HaveNodeAnnouncement: true,
|
HaveNodeAnnouncement: true,
|
||||||
Addresses: []net.Addr{
|
Addresses: []net.Addr{
|
||||||
&net.TCPAddr{
|
&net.TCPAddr{
|
||||||
@@ -198,7 +198,7 @@ func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
dbNode := &graphdb.LightningNode{
|
dbNode := &models.LightningNode{
|
||||||
HaveNodeAnnouncement: true,
|
HaveNodeAnnouncement: true,
|
||||||
Addresses: []net.Addr{
|
Addresses: []net.Addr{
|
||||||
&net.TCPAddr{
|
&net.TCPAddr{
|
||||||
@@ -302,7 +302,7 @@ func (d *databaseChannelGraph) addRandNode() (*btcec.PublicKey, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
dbNode := &graphdb.LightningNode{
|
dbNode := &models.LightningNode{
|
||||||
HaveNodeAnnouncement: true,
|
HaveNodeAnnouncement: true,
|
||||||
Addresses: []net.Addr{
|
Addresses: []net.Addr{
|
||||||
&net.TCPAddr{
|
&net.TCPAddr{
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import (
|
|||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||||
|
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||||
"github.com/lightningnetwork/lnd/keychain"
|
"github.com/lightningnetwork/lnd/keychain"
|
||||||
"github.com/lightningnetwork/lnd/kvdb"
|
"github.com/lightningnetwork/lnd/kvdb"
|
||||||
"github.com/lightningnetwork/lnd/lntypes"
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
@@ -724,11 +725,11 @@ func TestFetchHistoricalChannel(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func createLightningNode(priv *btcec.PrivateKey) *graphdb.LightningNode {
|
func createLightningNode(priv *btcec.PrivateKey) *models.LightningNode {
|
||||||
updateTime := rand.Int63()
|
updateTime := rand.Int63()
|
||||||
|
|
||||||
pub := priv.PubKey().SerializeCompressed()
|
pub := priv.PubKey().SerializeCompressed()
|
||||||
n := &graphdb.LightningNode{
|
n := &models.LightningNode{
|
||||||
HaveNodeAnnouncement: true,
|
HaveNodeAnnouncement: true,
|
||||||
AuthSigBytes: testSig.Serialize(),
|
AuthSigBytes: testSig.Serialize(),
|
||||||
LastUpdate: time.Unix(updateTime, 0),
|
LastUpdate: time.Unix(updateTime, 0),
|
||||||
@@ -742,7 +743,7 @@ func createLightningNode(priv *btcec.PrivateKey) *graphdb.LightningNode {
|
|||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
func createTestVertex(t *testing.T) *graphdb.LightningNode {
|
func createTestVertex(t *testing.T) *models.LightningNode {
|
||||||
priv, err := btcec.NewPrivateKey()
|
priv, err := btcec.NewPrivateKey()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
|||||||
@@ -1964,7 +1964,7 @@ func (d *AuthenticatedGossiper) addNode(msg *lnwire.NodeAnnouncement,
|
|||||||
|
|
||||||
timestamp := time.Unix(int64(msg.Timestamp), 0)
|
timestamp := time.Unix(int64(msg.Timestamp), 0)
|
||||||
features := lnwire.NewFeatureVector(msg.Features, lnwire.Features)
|
features := lnwire.NewFeatureVector(msg.Features, lnwire.Features)
|
||||||
node := &graphdb.LightningNode{
|
node := &models.LightningNode{
|
||||||
HaveNodeAnnouncement: true,
|
HaveNodeAnnouncement: true,
|
||||||
LastUpdate: timestamp,
|
LastUpdate: timestamp,
|
||||||
Addresses: msg.Addresses,
|
Addresses: msg.Addresses,
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ type mockGraphSource struct {
|
|||||||
bestHeight uint32
|
bestHeight uint32
|
||||||
|
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
nodes []graphdb.LightningNode
|
nodes []models.LightningNode
|
||||||
infos map[uint64]models.ChannelEdgeInfo
|
infos map[uint64]models.ChannelEdgeInfo
|
||||||
edges map[uint64][]models.ChannelEdgePolicy
|
edges map[uint64][]models.ChannelEdgePolicy
|
||||||
zombies map[uint64][][33]byte
|
zombies map[uint64][][33]byte
|
||||||
@@ -113,7 +113,7 @@ func newMockRouter(height uint32) *mockGraphSource {
|
|||||||
|
|
||||||
var _ graph.ChannelGraphSource = (*mockGraphSource)(nil)
|
var _ graph.ChannelGraphSource = (*mockGraphSource)(nil)
|
||||||
|
|
||||||
func (r *mockGraphSource) AddNode(node *graphdb.LightningNode,
|
func (r *mockGraphSource) AddNode(node *models.LightningNode,
|
||||||
_ ...batch.SchedulerOption) error {
|
_ ...batch.SchedulerOption) error {
|
||||||
|
|
||||||
r.mu.Lock()
|
r.mu.Lock()
|
||||||
@@ -203,7 +203,7 @@ func (r *mockGraphSource) AddProof(chanID lnwire.ShortChannelID,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *mockGraphSource) ForEachNode(func(node *graphdb.LightningNode) error) error {
|
func (r *mockGraphSource) ForEachNode(func(node *models.LightningNode) error) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -280,7 +280,7 @@ func (r *mockGraphSource) GetChannelByID(chanID lnwire.ShortChannelID) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *mockGraphSource) FetchLightningNode(
|
func (r *mockGraphSource) FetchLightningNode(
|
||||||
nodePub route.Vertex) (*graphdb.LightningNode, error) {
|
nodePub route.Vertex) (*models.LightningNode, error) {
|
||||||
|
|
||||||
for _, node := range r.nodes {
|
for _, node := range r.nodes {
|
||||||
if bytes.Equal(nodePub[:], node.PubKeyBytes[:]) {
|
if bytes.Equal(nodePub[:], node.PubKeyBytes[:]) {
|
||||||
|
|||||||
+5
-5
@@ -1165,7 +1165,7 @@ func (b *Builder) processUpdate(msg interface{},
|
|||||||
op ...batch.SchedulerOption) error {
|
op ...batch.SchedulerOption) error {
|
||||||
|
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
case *graphdb.LightningNode:
|
case *models.LightningNode:
|
||||||
// Before we add the node to the database, we'll check to see
|
// 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
|
// if the announcement is "fresh" or not. If it isn't, then
|
||||||
// we'll return an error.
|
// we'll return an error.
|
||||||
@@ -1517,7 +1517,7 @@ func (b *Builder) ApplyChannelUpdate(msg *lnwire.ChannelUpdate1) bool {
|
|||||||
// be ignored.
|
// be ignored.
|
||||||
//
|
//
|
||||||
// NOTE: This method is part of the ChannelGraphSource interface.
|
// NOTE: This method is part of the ChannelGraphSource interface.
|
||||||
func (b *Builder) AddNode(node *graphdb.LightningNode,
|
func (b *Builder) AddNode(node *models.LightningNode,
|
||||||
op ...batch.SchedulerOption) error {
|
op ...batch.SchedulerOption) error {
|
||||||
|
|
||||||
rMsg := &routingMsg{
|
rMsg := &routingMsg{
|
||||||
@@ -1624,7 +1624,7 @@ func (b *Builder) GetChannelByID(chanID lnwire.ShortChannelID) (
|
|||||||
//
|
//
|
||||||
// NOTE: This method is part of the ChannelGraphSource interface.
|
// NOTE: This method is part of the ChannelGraphSource interface.
|
||||||
func (b *Builder) FetchLightningNode(
|
func (b *Builder) FetchLightningNode(
|
||||||
node route.Vertex) (*graphdb.LightningNode, error) {
|
node route.Vertex) (*models.LightningNode, error) {
|
||||||
|
|
||||||
return b.cfg.Graph.FetchLightningNode(node)
|
return b.cfg.Graph.FetchLightningNode(node)
|
||||||
}
|
}
|
||||||
@@ -1633,10 +1633,10 @@ func (b *Builder) FetchLightningNode(
|
|||||||
//
|
//
|
||||||
// NOTE: This method is part of the ChannelGraphSource interface.
|
// NOTE: This method is part of the ChannelGraphSource interface.
|
||||||
func (b *Builder) ForEachNode(
|
func (b *Builder) ForEachNode(
|
||||||
cb func(*graphdb.LightningNode) error) error {
|
cb func(*models.LightningNode) error) error {
|
||||||
|
|
||||||
return b.cfg.Graph.ForEachNode(
|
return b.cfg.Graph.ForEachNode(
|
||||||
func(_ kvdb.RTx, n *graphdb.LightningNode) error {
|
func(_ kvdb.RTx, n *models.LightningNode) error {
|
||||||
return cb(n)
|
return cb(n)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ func TestIgnoreNodeAnnouncement(t *testing.T) {
|
|||||||
ctx := createTestCtxFromFile(t, startingBlockHeight, basicGraphFilePath)
|
ctx := createTestCtxFromFile(t, startingBlockHeight, basicGraphFilePath)
|
||||||
|
|
||||||
pub := priv1.PubKey()
|
pub := priv1.PubKey()
|
||||||
node := &graphdb.LightningNode{
|
node := &models.LightningNode{
|
||||||
HaveNodeAnnouncement: true,
|
HaveNodeAnnouncement: true,
|
||||||
LastUpdate: time.Unix(123, 0),
|
LastUpdate: time.Unix(123, 0),
|
||||||
Addresses: testAddrs,
|
Addresses: testAddrs,
|
||||||
@@ -1038,7 +1038,7 @@ func TestIsStaleNode(t *testing.T) {
|
|||||||
|
|
||||||
// With the node stub in the database, we'll add the fully node
|
// With the node stub in the database, we'll add the fully node
|
||||||
// announcement to the database.
|
// announcement to the database.
|
||||||
n1 := &graphdb.LightningNode{
|
n1 := &models.LightningNode{
|
||||||
HaveNodeAnnouncement: true,
|
HaveNodeAnnouncement: true,
|
||||||
LastUpdate: updateTimeStamp,
|
LastUpdate: updateTimeStamp,
|
||||||
Addresses: testAddrs,
|
Addresses: testAddrs,
|
||||||
@@ -1453,7 +1453,7 @@ func parseTestGraph(t *testing.T, useCache bool, path string) (
|
|||||||
privKeyMap := make(map[string]*btcec.PrivateKey)
|
privKeyMap := make(map[string]*btcec.PrivateKey)
|
||||||
channelIDs := make(map[route.Vertex]map[route.Vertex]uint64)
|
channelIDs := make(map[route.Vertex]map[route.Vertex]uint64)
|
||||||
links := make(map[lnwire.ShortChannelID]htlcswitch.ChannelLink)
|
links := make(map[lnwire.ShortChannelID]htlcswitch.ChannelLink)
|
||||||
var source *graphdb.LightningNode
|
var source *models.LightningNode
|
||||||
|
|
||||||
// First we insert all the nodes within the graph as vertexes.
|
// First we insert all the nodes within the graph as vertexes.
|
||||||
for _, node := range g.Nodes {
|
for _, node := range g.Nodes {
|
||||||
@@ -1462,7 +1462,7 @@ func parseTestGraph(t *testing.T, useCache bool, path string) (
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
dbNode := &graphdb.LightningNode{
|
dbNode := &models.LightningNode{
|
||||||
HaveNodeAnnouncement: true,
|
HaveNodeAnnouncement: true,
|
||||||
AuthSigBytes: testSig.Serialize(),
|
AuthSigBytes: testSig.Serialize(),
|
||||||
LastUpdate: testTime,
|
LastUpdate: testTime,
|
||||||
@@ -1832,7 +1832,7 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
|
|||||||
|
|
||||||
nodeIndex := byte(0)
|
nodeIndex := byte(0)
|
||||||
addNodeWithAlias := func(alias string, features *lnwire.FeatureVector) (
|
addNodeWithAlias := func(alias string, features *lnwire.FeatureVector) (
|
||||||
*graphdb.LightningNode, error) {
|
*models.LightningNode, error) {
|
||||||
|
|
||||||
keyBytes := []byte{
|
keyBytes := []byte{
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
@@ -1847,7 +1847,7 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
|
|||||||
features = lnwire.EmptyFeatureVector()
|
features = lnwire.EmptyFeatureVector()
|
||||||
}
|
}
|
||||||
|
|
||||||
dbNode := &graphdb.LightningNode{
|
dbNode := &models.LightningNode{
|
||||||
HaveNodeAnnouncement: true,
|
HaveNodeAnnouncement: true,
|
||||||
AuthSigBytes: testSig.Serialize(),
|
AuthSigBytes: testSig.Serialize(),
|
||||||
LastUpdate: testTime,
|
LastUpdate: testTime,
|
||||||
|
|||||||
+37
-160
@@ -6,7 +6,6 @@ import (
|
|||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"image/color"
|
|
||||||
"io"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
"net"
|
"net"
|
||||||
@@ -16,7 +15,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcec/v2"
|
"github.com/btcsuite/btcd/btcec/v2"
|
||||||
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
|
|
||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
"github.com/btcsuite/btcd/txscript"
|
"github.com/btcsuite/btcd/txscript"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
@@ -602,7 +600,7 @@ func (c *ChannelGraph) ForEachNodeCached(cb func(node route.Vertex,
|
|||||||
// We'll iterate over each node, then the set of channels for each
|
// We'll iterate over each node, then the set of channels for each
|
||||||
// node, and construct a similar callback functiopn signature as the
|
// node, and construct a similar callback functiopn signature as the
|
||||||
// main funcotin expects.
|
// main funcotin expects.
|
||||||
return c.ForEachNode(func(tx kvdb.RTx, node *LightningNode) error {
|
return c.ForEachNode(func(tx kvdb.RTx, node *models.LightningNode) error {
|
||||||
channels := make(map[uint64]*DirectedChannel)
|
channels := make(map[uint64]*DirectedChannel)
|
||||||
|
|
||||||
err := c.ForEachNodeChannelTx(tx, node.PubKeyBytes,
|
err := c.ForEachNodeChannelTx(tx, node.PubKeyBytes,
|
||||||
@@ -710,7 +708,7 @@ func (c *ChannelGraph) DisabledChannelIDs() ([]uint64, error) {
|
|||||||
// TODO(roasbeef): add iterator interface to allow for memory efficient graph
|
// TODO(roasbeef): add iterator interface to allow for memory efficient graph
|
||||||
// traversal when graph gets mega
|
// traversal when graph gets mega
|
||||||
func (c *ChannelGraph) ForEachNode(
|
func (c *ChannelGraph) ForEachNode(
|
||||||
cb func(kvdb.RTx, *LightningNode) error) error {
|
cb func(kvdb.RTx, *models.LightningNode) error) error {
|
||||||
|
|
||||||
traversal := func(tx kvdb.RTx) error {
|
traversal := func(tx kvdb.RTx) error {
|
||||||
// First grab the nodes bucket which stores the mapping from
|
// First grab the nodes bucket which stores the mapping from
|
||||||
@@ -787,8 +785,8 @@ func (c *ChannelGraph) ForEachNodeCacheable(cb func(kvdb.RTx,
|
|||||||
// as the center node within a star-graph. This method may be used to kick off
|
// 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
|
// a path finding algorithm in order to explore the reachability of another
|
||||||
// node based off the source node.
|
// node based off the source node.
|
||||||
func (c *ChannelGraph) SourceNode() (*LightningNode, error) {
|
func (c *ChannelGraph) SourceNode() (*models.LightningNode, error) {
|
||||||
var source *LightningNode
|
var source *models.LightningNode
|
||||||
err := kvdb.View(c.db, func(tx kvdb.RTx) error {
|
err := kvdb.View(c.db, func(tx kvdb.RTx) error {
|
||||||
// First grab the nodes bucket which stores the mapping from
|
// First grab the nodes bucket which stores the mapping from
|
||||||
// pubKey to node information.
|
// pubKey to node information.
|
||||||
@@ -818,7 +816,7 @@ func (c *ChannelGraph) SourceNode() (*LightningNode, error) {
|
|||||||
// of the graph. The source node is treated as the center node within a
|
// of the graph. The source node is treated as the center node within a
|
||||||
// star-graph. This method may be used to kick off a path finding algorithm in
|
// 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.
|
// order to explore the reachability of another node based off the source node.
|
||||||
func (c *ChannelGraph) sourceNode(nodes kvdb.RBucket) (*LightningNode, error) {
|
func (c *ChannelGraph) sourceNode(nodes kvdb.RBucket) (*models.LightningNode, error) {
|
||||||
selfPub := nodes.Get(sourceKey)
|
selfPub := nodes.Get(sourceKey)
|
||||||
if selfPub == nil {
|
if selfPub == nil {
|
||||||
return nil, ErrSourceNodeNotSet
|
return nil, ErrSourceNodeNotSet
|
||||||
@@ -837,7 +835,7 @@ func (c *ChannelGraph) sourceNode(nodes kvdb.RBucket) (*LightningNode, error) {
|
|||||||
// SetSourceNode sets the source node within the graph database. The source
|
// SetSourceNode sets the source node within the graph database. The source
|
||||||
// node is to be used as the center of a star-graph within path finding
|
// node is to be used as the center of a star-graph within path finding
|
||||||
// algorithms.
|
// algorithms.
|
||||||
func (c *ChannelGraph) SetSourceNode(node *LightningNode) error {
|
func (c *ChannelGraph) SetSourceNode(node *models.LightningNode) error {
|
||||||
nodePubBytes := node.PubKeyBytes[:]
|
nodePubBytes := node.PubKeyBytes[:]
|
||||||
|
|
||||||
return kvdb.Update(c.db, func(tx kvdb.RwTx) error {
|
return kvdb.Update(c.db, func(tx kvdb.RwTx) error {
|
||||||
@@ -868,7 +866,7 @@ func (c *ChannelGraph) SetSourceNode(node *LightningNode) error {
|
|||||||
// channel update.
|
// channel update.
|
||||||
//
|
//
|
||||||
// TODO(roasbeef): also need sig of announcement
|
// TODO(roasbeef): also need sig of announcement
|
||||||
func (c *ChannelGraph) AddLightningNode(node *LightningNode,
|
func (c *ChannelGraph) AddLightningNode(node *models.LightningNode,
|
||||||
op ...batch.SchedulerOption) error {
|
op ...batch.SchedulerOption) error {
|
||||||
|
|
||||||
r := &batch.Request{
|
r := &batch.Request{
|
||||||
@@ -894,7 +892,7 @@ func (c *ChannelGraph) AddLightningNode(node *LightningNode,
|
|||||||
return c.nodeScheduler.Execute(r)
|
return c.nodeScheduler.Execute(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func addLightningNode(tx kvdb.RwTx, node *LightningNode) error {
|
func addLightningNode(tx kvdb.RwTx, node *models.LightningNode) error {
|
||||||
nodes, err := tx.CreateTopLevelBucket(nodeBucket)
|
nodes, err := tx.CreateTopLevelBucket(nodeBucket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -1107,7 +1105,7 @@ func (c *ChannelGraph) addChannelEdge(tx kvdb.RwTx,
|
|||||||
_, node1Err := fetchLightningNode(nodes, edge.NodeKey1Bytes[:])
|
_, node1Err := fetchLightningNode(nodes, edge.NodeKey1Bytes[:])
|
||||||
switch {
|
switch {
|
||||||
case node1Err == ErrGraphNodeNotFound:
|
case node1Err == ErrGraphNodeNotFound:
|
||||||
node1Shell := LightningNode{
|
node1Shell := models.LightningNode{
|
||||||
PubKeyBytes: edge.NodeKey1Bytes,
|
PubKeyBytes: edge.NodeKey1Bytes,
|
||||||
HaveNodeAnnouncement: false,
|
HaveNodeAnnouncement: false,
|
||||||
}
|
}
|
||||||
@@ -1123,7 +1121,7 @@ func (c *ChannelGraph) addChannelEdge(tx kvdb.RwTx,
|
|||||||
_, node2Err := fetchLightningNode(nodes, edge.NodeKey2Bytes[:])
|
_, node2Err := fetchLightningNode(nodes, edge.NodeKey2Bytes[:])
|
||||||
switch {
|
switch {
|
||||||
case node2Err == ErrGraphNodeNotFound:
|
case node2Err == ErrGraphNodeNotFound:
|
||||||
node2Shell := LightningNode{
|
node2Shell := models.LightningNode{
|
||||||
PubKeyBytes: edge.NodeKey2Bytes,
|
PubKeyBytes: edge.NodeKey2Bytes,
|
||||||
HaveNodeAnnouncement: false,
|
HaveNodeAnnouncement: false,
|
||||||
}
|
}
|
||||||
@@ -1922,11 +1920,11 @@ type ChannelEdge struct {
|
|||||||
|
|
||||||
// Node1 is "node 1" in the channel. This is the node that would have
|
// Node1 is "node 1" in the channel. This is the node that would have
|
||||||
// produced Policy1 if it exists.
|
// produced Policy1 if it exists.
|
||||||
Node1 *LightningNode
|
Node1 *models.LightningNode
|
||||||
|
|
||||||
// Node2 is "node 2" in the channel. This is the node that would have
|
// Node2 is "node 2" in the channel. This is the node that would have
|
||||||
// produced Policy2 if it exists.
|
// produced Policy2 if it exists.
|
||||||
Node2 *LightningNode
|
Node2 *models.LightningNode
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChanUpdatesInHorizon returns all the known channel edges which have at least
|
// ChanUpdatesInHorizon returns all the known channel edges which have at least
|
||||||
@@ -2082,9 +2080,9 @@ func (c *ChannelGraph) ChanUpdatesInHorizon(startTime,
|
|||||||
// nodes to quickly determine if they have the same set of up to date node
|
// nodes to quickly determine if they have the same set of up to date node
|
||||||
// announcements.
|
// announcements.
|
||||||
func (c *ChannelGraph) NodeUpdatesInHorizon(startTime,
|
func (c *ChannelGraph) NodeUpdatesInHorizon(startTime,
|
||||||
endTime time.Time) ([]LightningNode, error) {
|
endTime time.Time) ([]models.LightningNode, error) {
|
||||||
|
|
||||||
var nodesInHorizon []LightningNode
|
var nodesInHorizon []models.LightningNode
|
||||||
|
|
||||||
err := kvdb.View(c.db, func(tx kvdb.RTx) error {
|
err := kvdb.View(c.db, func(tx kvdb.RTx) error {
|
||||||
nodes := tx.ReadBucket(nodeBucket)
|
nodes := tx.ReadBucket(nodeBucket)
|
||||||
@@ -2880,127 +2878,6 @@ func updateEdgePolicy(tx kvdb.RwTx, edge *models.ChannelEdgePolicy,
|
|||||||
return isUpdate1, nil
|
return isUpdate1, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// LightningNode represents an individual vertex/node within the channel graph.
|
|
||||||
// A node is connected to other nodes by one or more channel edges emanating
|
|
||||||
// from it. As the graph is directed, a node will also have an incoming edge
|
|
||||||
// attached to it for each outgoing edge.
|
|
||||||
type LightningNode struct {
|
|
||||||
// PubKeyBytes is the raw bytes of the public key of the target node.
|
|
||||||
PubKeyBytes [33]byte
|
|
||||||
pubKey *btcec.PublicKey
|
|
||||||
|
|
||||||
// HaveNodeAnnouncement indicates whether we received a node
|
|
||||||
// announcement for this particular node. If true, the remaining fields
|
|
||||||
// will be set, if false only the PubKey is known for this node.
|
|
||||||
HaveNodeAnnouncement bool
|
|
||||||
|
|
||||||
// LastUpdate is the last time the vertex information for this node has
|
|
||||||
// been updated.
|
|
||||||
LastUpdate time.Time
|
|
||||||
|
|
||||||
// Address is the TCP address this node is reachable over.
|
|
||||||
Addresses []net.Addr
|
|
||||||
|
|
||||||
// Color is the selected color for the node.
|
|
||||||
Color color.RGBA
|
|
||||||
|
|
||||||
// Alias is a nick-name for the node. The alias can be used to confirm
|
|
||||||
// a node's identity or to serve as a short ID for an address book.
|
|
||||||
Alias string
|
|
||||||
|
|
||||||
// AuthSigBytes is the raw signature under the advertised public key
|
|
||||||
// which serves to authenticate the attributes announced by this node.
|
|
||||||
AuthSigBytes []byte
|
|
||||||
|
|
||||||
// Features is the list of protocol features supported by this node.
|
|
||||||
Features *lnwire.FeatureVector
|
|
||||||
|
|
||||||
// ExtraOpaqueData is the set of data that was appended to this
|
|
||||||
// message, some of which we may not actually know how to iterate or
|
|
||||||
// parse. By holding onto this data, we ensure that we're able to
|
|
||||||
// properly validate the set of signatures that cover these new fields,
|
|
||||||
// and ensure we're able to make upgrades to the network in a forwards
|
|
||||||
// compatible manner.
|
|
||||||
ExtraOpaqueData []byte
|
|
||||||
|
|
||||||
// TODO(roasbeef): discovery will need storage to keep it's last IP
|
|
||||||
// address and re-announce if interface changes?
|
|
||||||
|
|
||||||
// TODO(roasbeef): add update method and fetch?
|
|
||||||
}
|
|
||||||
|
|
||||||
// PubKey is the node's long-term identity public key. This key will be used to
|
|
||||||
// authenticated any advertisements/updates sent by the node.
|
|
||||||
//
|
|
||||||
// NOTE: By having this method to access an attribute, we ensure we only need
|
|
||||||
// to fully deserialize the pubkey if absolutely necessary.
|
|
||||||
func (l *LightningNode) PubKey() (*btcec.PublicKey, error) {
|
|
||||||
if l.pubKey != nil {
|
|
||||||
return l.pubKey, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
key, err := btcec.ParsePubKey(l.PubKeyBytes[:])
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
l.pubKey = key
|
|
||||||
|
|
||||||
return key, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// AuthSig is a signature under the advertised public key which serves to
|
|
||||||
// authenticate the attributes announced by this node.
|
|
||||||
//
|
|
||||||
// NOTE: By having this method to access an attribute, we ensure we only need
|
|
||||||
// to fully deserialize the signature if absolutely necessary.
|
|
||||||
func (l *LightningNode) AuthSig() (*ecdsa.Signature, error) {
|
|
||||||
return ecdsa.ParseSignature(l.AuthSigBytes)
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddPubKey is a setter-link method that can be used to swap out the public
|
|
||||||
// key for a node.
|
|
||||||
func (l *LightningNode) AddPubKey(key *btcec.PublicKey) {
|
|
||||||
l.pubKey = key
|
|
||||||
copy(l.PubKeyBytes[:], key.SerializeCompressed())
|
|
||||||
}
|
|
||||||
|
|
||||||
// NodeAnnouncement retrieves the latest node announcement of the node.
|
|
||||||
func (l *LightningNode) NodeAnnouncement(signed bool) (*lnwire.NodeAnnouncement,
|
|
||||||
error) {
|
|
||||||
|
|
||||||
if !l.HaveNodeAnnouncement {
|
|
||||||
return nil, fmt.Errorf("node does not have node announcement")
|
|
||||||
}
|
|
||||||
|
|
||||||
alias, err := lnwire.NewNodeAlias(l.Alias)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
nodeAnn := &lnwire.NodeAnnouncement{
|
|
||||||
Features: l.Features.RawFeatureVector,
|
|
||||||
NodeID: l.PubKeyBytes,
|
|
||||||
RGBColor: l.Color,
|
|
||||||
Alias: alias,
|
|
||||||
Addresses: l.Addresses,
|
|
||||||
Timestamp: uint32(l.LastUpdate.Unix()),
|
|
||||||
ExtraOpaqueData: l.ExtraOpaqueData,
|
|
||||||
}
|
|
||||||
|
|
||||||
if !signed {
|
|
||||||
return nodeAnn, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
sig, err := lnwire.NewSigFromECDSARawSignature(l.AuthSigBytes)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
nodeAnn.Signature = sig
|
|
||||||
|
|
||||||
return nodeAnn, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// isPublic determines whether the node is seen as public within the graph from
|
// isPublic determines whether the node is seen as public within the graph from
|
||||||
// the source node's point of view. An existing database transaction can also be
|
// the source node's point of view. An existing database transaction can also be
|
||||||
// specified.
|
// specified.
|
||||||
@@ -3050,7 +2927,7 @@ func (c *ChannelGraph) isPublic(tx kvdb.RTx, nodePub route.Vertex,
|
|||||||
// ErrGraphNodeNotFound is returned. An optional transaction may be provided.
|
// ErrGraphNodeNotFound is returned. An optional transaction may be provided.
|
||||||
// If none is provided, then a new one will be created.
|
// If none is provided, then a new one will be created.
|
||||||
func (c *ChannelGraph) FetchLightningNodeTx(tx kvdb.RTx, nodePub route.Vertex) (
|
func (c *ChannelGraph) FetchLightningNodeTx(tx kvdb.RTx, nodePub route.Vertex) (
|
||||||
*LightningNode, error) {
|
*models.LightningNode, error) {
|
||||||
|
|
||||||
return c.fetchLightningNode(tx, nodePub)
|
return c.fetchLightningNode(tx, nodePub)
|
||||||
}
|
}
|
||||||
@@ -3058,7 +2935,7 @@ func (c *ChannelGraph) FetchLightningNodeTx(tx kvdb.RTx, nodePub route.Vertex) (
|
|||||||
// FetchLightningNode attempts to look up a target node by its identity public
|
// 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
|
// key. If the node isn't found in the database, then ErrGraphNodeNotFound is
|
||||||
// returned.
|
// returned.
|
||||||
func (c *ChannelGraph) FetchLightningNode(nodePub route.Vertex) (*LightningNode,
|
func (c *ChannelGraph) FetchLightningNode(nodePub route.Vertex) (*models.LightningNode,
|
||||||
error) {
|
error) {
|
||||||
|
|
||||||
return c.fetchLightningNode(nil, nodePub)
|
return c.fetchLightningNode(nil, nodePub)
|
||||||
@@ -3069,9 +2946,9 @@ func (c *ChannelGraph) FetchLightningNode(nodePub route.Vertex) (*LightningNode,
|
|||||||
// returned. An optional transaction may be provided. If none is provided, then
|
// returned. An optional transaction may be provided. If none is provided, then
|
||||||
// a new one will be created.
|
// a new one will be created.
|
||||||
func (c *ChannelGraph) fetchLightningNode(tx kvdb.RTx,
|
func (c *ChannelGraph) fetchLightningNode(tx kvdb.RTx,
|
||||||
nodePub route.Vertex) (*LightningNode, error) {
|
nodePub route.Vertex) (*models.LightningNode, error) {
|
||||||
|
|
||||||
var node *LightningNode
|
var node *models.LightningNode
|
||||||
fetch := func(tx kvdb.RTx) error {
|
fetch := func(tx kvdb.RTx) error {
|
||||||
// First grab the nodes bucket which stores the mapping from
|
// First grab the nodes bucket which stores the mapping from
|
||||||
// pubKey to node information.
|
// pubKey to node information.
|
||||||
@@ -3339,7 +3216,7 @@ func (c *ChannelGraph) ForEachNodeChannelTx(tx kvdb.RTx,
|
|||||||
// one of the nodes, and wishes to obtain the full LightningNode for the other
|
// one of the nodes, and wishes to obtain the full LightningNode for the other
|
||||||
// end of the channel.
|
// end of the channel.
|
||||||
func (c *ChannelGraph) FetchOtherNode(tx kvdb.RTx,
|
func (c *ChannelGraph) FetchOtherNode(tx kvdb.RTx,
|
||||||
channel *models.ChannelEdgeInfo, thisNodeKey []byte) (*LightningNode,
|
channel *models.ChannelEdgeInfo, thisNodeKey []byte) (*models.LightningNode,
|
||||||
error) {
|
error) {
|
||||||
|
|
||||||
// Ensure that the node passed in is actually a member of the channel.
|
// Ensure that the node passed in is actually a member of the channel.
|
||||||
@@ -3353,7 +3230,7 @@ func (c *ChannelGraph) FetchOtherNode(tx kvdb.RTx,
|
|||||||
return nil, fmt.Errorf("node not participating in this channel")
|
return nil, fmt.Errorf("node not participating in this channel")
|
||||||
}
|
}
|
||||||
|
|
||||||
var targetNode *LightningNode
|
var targetNode *models.LightningNode
|
||||||
fetchNodeFunc := func(tx kvdb.RTx) error {
|
fetchNodeFunc := func(tx kvdb.RTx) error {
|
||||||
// First grab the nodes bucket which stores the mapping from
|
// First grab the nodes bucket which stores the mapping from
|
||||||
// pubKey to node information.
|
// pubKey to node information.
|
||||||
@@ -3976,7 +3853,7 @@ func (c *ChannelGraph) IsClosedScid(scid lnwire.ShortChannelID) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func putLightningNode(nodeBucket kvdb.RwBucket, aliasBucket kvdb.RwBucket, // nolint:dupl
|
func putLightningNode(nodeBucket kvdb.RwBucket, aliasBucket kvdb.RwBucket, // nolint:dupl
|
||||||
updateIndex kvdb.RwBucket, node *LightningNode) error {
|
updateIndex kvdb.RwBucket, node *models.LightningNode) error {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
scratch [16]byte
|
scratch [16]byte
|
||||||
@@ -4105,11 +3982,11 @@ func putLightningNode(nodeBucket kvdb.RwBucket, aliasBucket kvdb.RwBucket, // no
|
|||||||
}
|
}
|
||||||
|
|
||||||
func fetchLightningNode(nodeBucket kvdb.RBucket,
|
func fetchLightningNode(nodeBucket kvdb.RBucket,
|
||||||
nodePub []byte) (LightningNode, error) {
|
nodePub []byte) (models.LightningNode, error) {
|
||||||
|
|
||||||
nodeBytes := nodeBucket.Get(nodePub)
|
nodeBytes := nodeBucket.Get(nodePub)
|
||||||
if nodeBytes == nil {
|
if nodeBytes == nil {
|
||||||
return LightningNode{}, ErrGraphNodeNotFound
|
return models.LightningNode{}, ErrGraphNodeNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeReader := bytes.NewReader(nodeBytes)
|
nodeReader := bytes.NewReader(nodeBytes)
|
||||||
@@ -4172,9 +4049,9 @@ func deserializeLightningNodeCacheable(r io.Reader) (*graphCacheNode, error) {
|
|||||||
return node, nil
|
return node, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func deserializeLightningNode(r io.Reader) (LightningNode, error) {
|
func deserializeLightningNode(r io.Reader) (models.LightningNode, error) {
|
||||||
var (
|
var (
|
||||||
node LightningNode
|
node models.LightningNode
|
||||||
scratch [8]byte
|
scratch [8]byte
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
@@ -4184,18 +4061,18 @@ func deserializeLightningNode(r io.Reader) (LightningNode, error) {
|
|||||||
node.Features = lnwire.EmptyFeatureVector()
|
node.Features = lnwire.EmptyFeatureVector()
|
||||||
|
|
||||||
if _, err := r.Read(scratch[:]); err != nil {
|
if _, err := r.Read(scratch[:]); err != nil {
|
||||||
return LightningNode{}, err
|
return models.LightningNode{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
unix := int64(byteOrder.Uint64(scratch[:]))
|
unix := int64(byteOrder.Uint64(scratch[:]))
|
||||||
node.LastUpdate = time.Unix(unix, 0)
|
node.LastUpdate = time.Unix(unix, 0)
|
||||||
|
|
||||||
if _, err := io.ReadFull(r, node.PubKeyBytes[:]); err != nil {
|
if _, err := io.ReadFull(r, node.PubKeyBytes[:]); err != nil {
|
||||||
return LightningNode{}, err
|
return models.LightningNode{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := r.Read(scratch[:2]); err != nil {
|
if _, err := r.Read(scratch[:2]); err != nil {
|
||||||
return LightningNode{}, err
|
return models.LightningNode{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
hasNodeAnn := byteOrder.Uint16(scratch[:2])
|
hasNodeAnn := byteOrder.Uint16(scratch[:2])
|
||||||
@@ -4214,27 +4091,27 @@ func deserializeLightningNode(r io.Reader) (LightningNode, error) {
|
|||||||
// We did get a node announcement for this node, so we'll have the rest
|
// We did get a node announcement for this node, so we'll have the rest
|
||||||
// of the data available.
|
// of the data available.
|
||||||
if err := binary.Read(r, byteOrder, &node.Color.R); err != nil {
|
if err := binary.Read(r, byteOrder, &node.Color.R); err != nil {
|
||||||
return LightningNode{}, err
|
return models.LightningNode{}, err
|
||||||
}
|
}
|
||||||
if err := binary.Read(r, byteOrder, &node.Color.G); err != nil {
|
if err := binary.Read(r, byteOrder, &node.Color.G); err != nil {
|
||||||
return LightningNode{}, err
|
return models.LightningNode{}, err
|
||||||
}
|
}
|
||||||
if err := binary.Read(r, byteOrder, &node.Color.B); err != nil {
|
if err := binary.Read(r, byteOrder, &node.Color.B); err != nil {
|
||||||
return LightningNode{}, err
|
return models.LightningNode{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
node.Alias, err = wire.ReadVarString(r, 0)
|
node.Alias, err = wire.ReadVarString(r, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return LightningNode{}, err
|
return models.LightningNode{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = node.Features.Decode(r)
|
err = node.Features.Decode(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return LightningNode{}, err
|
return models.LightningNode{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := r.Read(scratch[:2]); err != nil {
|
if _, err := r.Read(scratch[:2]); err != nil {
|
||||||
return LightningNode{}, err
|
return models.LightningNode{}, err
|
||||||
}
|
}
|
||||||
numAddresses := int(byteOrder.Uint16(scratch[:2]))
|
numAddresses := int(byteOrder.Uint16(scratch[:2]))
|
||||||
|
|
||||||
@@ -4242,7 +4119,7 @@ func deserializeLightningNode(r io.Reader) (LightningNode, error) {
|
|||||||
for i := 0; i < numAddresses; i++ {
|
for i := 0; i < numAddresses; i++ {
|
||||||
address, err := DeserializeAddr(r)
|
address, err := DeserializeAddr(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return LightningNode{}, err
|
return models.LightningNode{}, err
|
||||||
}
|
}
|
||||||
addresses = append(addresses, address)
|
addresses = append(addresses, address)
|
||||||
}
|
}
|
||||||
@@ -4250,7 +4127,7 @@ func deserializeLightningNode(r io.Reader) (LightningNode, error) {
|
|||||||
|
|
||||||
node.AuthSigBytes, err = wire.ReadVarBytes(r, 0, 80, "sig")
|
node.AuthSigBytes, err = wire.ReadVarBytes(r, 0, 80, "sig")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return LightningNode{}, err
|
return models.LightningNode{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// We'll try and see if there are any opaque bytes left, if not, then
|
// We'll try and see if there are any opaque bytes left, if not, then
|
||||||
@@ -4262,7 +4139,7 @@ func deserializeLightningNode(r io.Reader) (LightningNode, error) {
|
|||||||
case err == io.ErrUnexpectedEOF:
|
case err == io.ErrUnexpectedEOF:
|
||||||
case err == io.EOF:
|
case err == io.EOF:
|
||||||
case err != nil:
|
case err != nil:
|
||||||
return LightningNode{}, err
|
return models.LightningNode{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return node, nil
|
return node, nil
|
||||||
|
|||||||
+24
-24
@@ -65,11 +65,11 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func createLightningNode(db kvdb.Backend, priv *btcec.PrivateKey) (*LightningNode, error) {
|
func createLightningNode(db kvdb.Backend, priv *btcec.PrivateKey) (*models.LightningNode, error) {
|
||||||
updateTime := prand.Int63()
|
updateTime := prand.Int63()
|
||||||
|
|
||||||
pub := priv.PubKey().SerializeCompressed()
|
pub := priv.PubKey().SerializeCompressed()
|
||||||
n := &LightningNode{
|
n := &models.LightningNode{
|
||||||
HaveNodeAnnouncement: true,
|
HaveNodeAnnouncement: true,
|
||||||
AuthSigBytes: testSig.Serialize(),
|
AuthSigBytes: testSig.Serialize(),
|
||||||
LastUpdate: time.Unix(updateTime, 0),
|
LastUpdate: time.Unix(updateTime, 0),
|
||||||
@@ -83,7 +83,7 @@ func createLightningNode(db kvdb.Backend, priv *btcec.PrivateKey) (*LightningNod
|
|||||||
return n, nil
|
return n, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createTestVertex(db kvdb.Backend) (*LightningNode, error) {
|
func createTestVertex(db kvdb.Backend) (*models.LightningNode, error) {
|
||||||
priv, err := btcec.NewPrivateKey()
|
priv, err := btcec.NewPrivateKey()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -100,7 +100,7 @@ func TestNodeInsertionAndDeletion(t *testing.T) {
|
|||||||
|
|
||||||
// We'd like to test basic insertion/deletion for vertexes from the
|
// We'd like to test basic insertion/deletion for vertexes from the
|
||||||
// graph, so we'll create a test vertex to start with.
|
// graph, so we'll create a test vertex to start with.
|
||||||
node := &LightningNode{
|
node := &models.LightningNode{
|
||||||
HaveNodeAnnouncement: true,
|
HaveNodeAnnouncement: true,
|
||||||
AuthSigBytes: testSig.Serialize(),
|
AuthSigBytes: testSig.Serialize(),
|
||||||
LastUpdate: time.Unix(1232342, 0),
|
LastUpdate: time.Unix(1232342, 0),
|
||||||
@@ -160,7 +160,7 @@ func TestPartialNode(t *testing.T) {
|
|||||||
|
|
||||||
// We want to be able to insert nodes into the graph that only has the
|
// We want to be able to insert nodes into the graph that only has the
|
||||||
// PubKey set.
|
// PubKey set.
|
||||||
node := &LightningNode{
|
node := &models.LightningNode{
|
||||||
HaveNodeAnnouncement: false,
|
HaveNodeAnnouncement: false,
|
||||||
PubKeyBytes: testPub,
|
PubKeyBytes: testPub,
|
||||||
}
|
}
|
||||||
@@ -183,7 +183,7 @@ func TestPartialNode(t *testing.T) {
|
|||||||
|
|
||||||
// The two nodes should match exactly! (with default values for
|
// The two nodes should match exactly! (with default values for
|
||||||
// LastUpdate and db set to satisfy compareNodes())
|
// LastUpdate and db set to satisfy compareNodes())
|
||||||
node = &LightningNode{
|
node = &models.LightningNode{
|
||||||
HaveNodeAnnouncement: false,
|
HaveNodeAnnouncement: false,
|
||||||
LastUpdate: time.Unix(0, 0),
|
LastUpdate: time.Unix(0, 0),
|
||||||
PubKeyBytes: testPub,
|
PubKeyBytes: testPub,
|
||||||
@@ -366,7 +366,7 @@ func TestEdgeInsertionDeletion(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createEdge(height, txIndex uint32, txPosition uint16, outPointIndex uint32,
|
func createEdge(height, txIndex uint32, txPosition uint16, outPointIndex uint32,
|
||||||
node1, node2 *LightningNode) (models.ChannelEdgeInfo,
|
node1, node2 *models.LightningNode) (models.ChannelEdgeInfo,
|
||||||
lnwire.ShortChannelID) {
|
lnwire.ShortChannelID) {
|
||||||
|
|
||||||
shortChanID := lnwire.ShortChannelID{
|
shortChanID := lnwire.ShortChannelID{
|
||||||
@@ -598,7 +598,7 @@ func assertEdgeInfoEqual(t *testing.T, e1 *models.ChannelEdgeInfo,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func createChannelEdge(db kvdb.Backend, node1, node2 *LightningNode) (
|
func createChannelEdge(db kvdb.Backend, node1, node2 *models.LightningNode) (
|
||||||
*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||||
*models.ChannelEdgePolicy) {
|
*models.ChannelEdgePolicy) {
|
||||||
|
|
||||||
@@ -770,7 +770,7 @@ func TestEdgeInfoUpdates(t *testing.T) {
|
|||||||
assertEdgeInfoEqual(t, dbEdgeInfo, edgeInfo)
|
assertEdgeInfoEqual(t, dbEdgeInfo, edgeInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
func assertNodeInCache(t *testing.T, g *ChannelGraph, n *LightningNode,
|
func assertNodeInCache(t *testing.T, g *ChannelGraph, n *models.LightningNode,
|
||||||
expectedFeatures *lnwire.FeatureVector) {
|
expectedFeatures *lnwire.FeatureVector) {
|
||||||
|
|
||||||
// Let's check the internal view first.
|
// Let's check the internal view first.
|
||||||
@@ -1089,7 +1089,7 @@ func TestGraphTraversalCacheable(t *testing.T) {
|
|||||||
// Create a map of all nodes with the iteration we know works (because
|
// Create a map of all nodes with the iteration we know works (because
|
||||||
// it is tested in another test).
|
// it is tested in another test).
|
||||||
nodeMap := make(map[route.Vertex]struct{})
|
nodeMap := make(map[route.Vertex]struct{})
|
||||||
err = graph.ForEachNode(func(tx kvdb.RTx, n *LightningNode) error {
|
err = graph.ForEachNode(func(tx kvdb.RTx, n *models.LightningNode) error {
|
||||||
nodeMap[n.PubKeyBytes] = struct{}{}
|
nodeMap[n.PubKeyBytes] = struct{}{}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -1192,9 +1192,9 @@ func TestGraphCacheTraversal(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func fillTestGraph(t require.TestingT, graph *ChannelGraph, numNodes,
|
func fillTestGraph(t require.TestingT, graph *ChannelGraph, numNodes,
|
||||||
numChannels int) (map[uint64]struct{}, []*LightningNode) {
|
numChannels int) (map[uint64]struct{}, []*models.LightningNode) {
|
||||||
|
|
||||||
nodes := make([]*LightningNode, numNodes)
|
nodes := make([]*models.LightningNode, numNodes)
|
||||||
nodeIndex := map[string]struct{}{}
|
nodeIndex := map[string]struct{}{}
|
||||||
for i := 0; i < numNodes; i++ {
|
for i := 0; i < numNodes; i++ {
|
||||||
node, err := createTestVertex(graph.db)
|
node, err := createTestVertex(graph.db)
|
||||||
@@ -1212,7 +1212,7 @@ func fillTestGraph(t require.TestingT, graph *ChannelGraph, numNodes,
|
|||||||
|
|
||||||
// Iterate over each node as returned by the graph, if all nodes are
|
// Iterate over each node as returned by the graph, if all nodes are
|
||||||
// reached, then the map created above should be empty.
|
// reached, then the map created above should be empty.
|
||||||
err := graph.ForEachNode(func(_ kvdb.RTx, node *LightningNode) error {
|
err := graph.ForEachNode(func(_ kvdb.RTx, node *models.LightningNode) error {
|
||||||
delete(nodeIndex, node.Alias)
|
delete(nodeIndex, node.Alias)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
@@ -1320,7 +1320,7 @@ func assertNumChans(t *testing.T, graph *ChannelGraph, n int) {
|
|||||||
|
|
||||||
func assertNumNodes(t *testing.T, graph *ChannelGraph, n int) {
|
func assertNumNodes(t *testing.T, graph *ChannelGraph, n int) {
|
||||||
numNodes := 0
|
numNodes := 0
|
||||||
err := graph.ForEachNode(func(_ kvdb.RTx, _ *LightningNode) error {
|
err := graph.ForEachNode(func(_ kvdb.RTx, _ *models.LightningNode) error {
|
||||||
numNodes++
|
numNodes++
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
@@ -1391,7 +1391,7 @@ func TestGraphPruning(t *testing.T) {
|
|||||||
// and enough edges to create a fully connected graph. The graph will
|
// and enough edges to create a fully connected graph. The graph will
|
||||||
// be rather simple, representing a straight line.
|
// be rather simple, representing a straight line.
|
||||||
const numNodes = 5
|
const numNodes = 5
|
||||||
graphNodes := make([]*LightningNode, numNodes)
|
graphNodes := make([]*models.LightningNode, numNodes)
|
||||||
for i := 0; i < numNodes; i++ {
|
for i := 0; i < numNodes; i++ {
|
||||||
node, err := createTestVertex(graph.db)
|
node, err := createTestVertex(graph.db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1809,7 +1809,7 @@ func TestNodeUpdatesInHorizon(t *testing.T) {
|
|||||||
// We'll create 10 node announcements, each with an update timestamp 10
|
// We'll create 10 node announcements, each with an update timestamp 10
|
||||||
// seconds after the other.
|
// seconds after the other.
|
||||||
const numNodes = 10
|
const numNodes = 10
|
||||||
nodeAnns := make([]LightningNode, 0, numNodes)
|
nodeAnns := make([]models.LightningNode, 0, numNodes)
|
||||||
for i := 0; i < numNodes; i++ {
|
for i := 0; i < numNodes; i++ {
|
||||||
nodeAnn, err := createTestVertex(graph.db)
|
nodeAnn, err := createTestVertex(graph.db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1835,7 +1835,7 @@ func TestNodeUpdatesInHorizon(t *testing.T) {
|
|||||||
start time.Time
|
start time.Time
|
||||||
end time.Time
|
end time.Time
|
||||||
|
|
||||||
resp []LightningNode
|
resp []models.LightningNode
|
||||||
}{
|
}{
|
||||||
// If we query for a time range that's strictly below our set
|
// If we query for a time range that's strictly below our set
|
||||||
// of updates, then we'll get an empty result back.
|
// of updates, then we'll get an empty result back.
|
||||||
@@ -2408,7 +2408,7 @@ func TestFilterChannelRange(t *testing.T) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
updateTimeSeed := time.Now().Unix()
|
updateTimeSeed := time.Now().Unix()
|
||||||
maybeAddPolicy := func(chanID uint64, node *LightningNode,
|
maybeAddPolicy := func(chanID uint64, node *models.LightningNode,
|
||||||
node2 bool) time.Time {
|
node2 bool) time.Time {
|
||||||
|
|
||||||
var chanFlags lnwire.ChanUpdateChanFlags
|
var chanFlags lnwire.ChanUpdateChanFlags
|
||||||
@@ -2725,7 +2725,7 @@ func TestIncompleteChannelPolicies(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ensure that channel is reported with unknown policies.
|
// Ensure that channel is reported with unknown policies.
|
||||||
checkPolicies := func(node *LightningNode, expectedIn, expectedOut bool) {
|
checkPolicies := func(node *models.LightningNode, expectedIn, expectedOut bool) {
|
||||||
calls := 0
|
calls := 0
|
||||||
err := graph.ForEachNodeChannel(node.PubKeyBytes,
|
err := graph.ForEachNodeChannel(node.PubKeyBytes,
|
||||||
func(_ kvdb.RTx, _ *models.ChannelEdgeInfo, outEdge,
|
func(_ kvdb.RTx, _ *models.ChannelEdgeInfo, outEdge,
|
||||||
@@ -3145,7 +3145,7 @@ func TestNodeIsPublic(t *testing.T) {
|
|||||||
|
|
||||||
// After creating all of our nodes and edges, we'll add them to each
|
// After creating all of our nodes and edges, we'll add them to each
|
||||||
// participant's graph.
|
// participant's graph.
|
||||||
nodes := []*LightningNode{aliceNode, bobNode, carolNode}
|
nodes := []*models.LightningNode{aliceNode, bobNode, carolNode}
|
||||||
edges := []*models.ChannelEdgeInfo{&aliceBobEdge, &bobCarolEdge}
|
edges := []*models.ChannelEdgeInfo{&aliceBobEdge, &bobCarolEdge}
|
||||||
graphs := []*ChannelGraph{aliceGraph, bobGraph, carolGraph}
|
graphs := []*ChannelGraph{aliceGraph, bobGraph, carolGraph}
|
||||||
for _, graph := range graphs {
|
for _, graph := range graphs {
|
||||||
@@ -3163,7 +3163,7 @@ func TestNodeIsPublic(t *testing.T) {
|
|||||||
|
|
||||||
// checkNodes is a helper closure that will be used to assert that the
|
// checkNodes is a helper closure that will be used to assert that the
|
||||||
// given nodes are seen as public/private within the given graphs.
|
// given nodes are seen as public/private within the given graphs.
|
||||||
checkNodes := func(nodes []*LightningNode, graphs []*ChannelGraph,
|
checkNodes := func(nodes []*models.LightningNode, graphs []*ChannelGraph,
|
||||||
public bool) {
|
public bool) {
|
||||||
|
|
||||||
t.Helper()
|
t.Helper()
|
||||||
@@ -3204,7 +3204,7 @@ func TestNodeIsPublic(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
checkNodes(
|
checkNodes(
|
||||||
[]*LightningNode{aliceNode},
|
[]*models.LightningNode{aliceNode},
|
||||||
[]*ChannelGraph{bobGraph, carolGraph},
|
[]*ChannelGraph{bobGraph, carolGraph},
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
@@ -3235,7 +3235,7 @@ func TestNodeIsPublic(t *testing.T) {
|
|||||||
// With the modifications above, Bob should now be seen as a private
|
// With the modifications above, Bob should now be seen as a private
|
||||||
// node from both Alice's and Carol's perspective.
|
// node from both Alice's and Carol's perspective.
|
||||||
checkNodes(
|
checkNodes(
|
||||||
[]*LightningNode{bobNode},
|
[]*models.LightningNode{bobNode},
|
||||||
[]*ChannelGraph{aliceGraph, carolGraph},
|
[]*ChannelGraph{aliceGraph, carolGraph},
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
@@ -3554,7 +3554,7 @@ func TestGraphZombieIndex(t *testing.T) {
|
|||||||
// compareNodes is used to compare two LightningNodes while excluding the
|
// compareNodes is used to compare two LightningNodes while excluding the
|
||||||
// Features struct, which cannot be compared as the semantics for reserializing
|
// Features struct, which cannot be compared as the semantics for reserializing
|
||||||
// the featuresMap have not been defined.
|
// the featuresMap have not been defined.
|
||||||
func compareNodes(a, b *LightningNode) error {
|
func compareNodes(a, b *models.LightningNode) error {
|
||||||
if a.LastUpdate != b.LastUpdate {
|
if a.LastUpdate != b.LastUpdate {
|
||||||
return fmt.Errorf("node LastUpdate doesn't match: expected %v, \n"+
|
return fmt.Errorf("node LastUpdate doesn't match: expected %v, \n"+
|
||||||
"got %v", a.LastUpdate, b.LastUpdate)
|
"got %v", a.LastUpdate, b.LastUpdate)
|
||||||
|
|||||||
@@ -0,0 +1,133 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"image/color"
|
||||||
|
"net"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/btcsuite/btcd/btcec/v2"
|
||||||
|
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
|
||||||
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
|
)
|
||||||
|
|
||||||
|
// LightningNode represents an individual vertex/node within the channel graph.
|
||||||
|
// A node is connected to other nodes by one or more channel edges emanating
|
||||||
|
// from it. As the graph is directed, a node will also have an incoming edge
|
||||||
|
// attached to it for each outgoing edge.
|
||||||
|
type LightningNode struct {
|
||||||
|
// PubKeyBytes is the raw bytes of the public key of the target node.
|
||||||
|
PubKeyBytes [33]byte
|
||||||
|
pubKey *btcec.PublicKey
|
||||||
|
|
||||||
|
// HaveNodeAnnouncement indicates whether we received a node
|
||||||
|
// announcement for this particular node. If true, the remaining fields
|
||||||
|
// will be set, if false only the PubKey is known for this node.
|
||||||
|
HaveNodeAnnouncement bool
|
||||||
|
|
||||||
|
// LastUpdate is the last time the vertex information for this node has
|
||||||
|
// been updated.
|
||||||
|
LastUpdate time.Time
|
||||||
|
|
||||||
|
// Address is the TCP address this node is reachable over.
|
||||||
|
Addresses []net.Addr
|
||||||
|
|
||||||
|
// Color is the selected color for the node.
|
||||||
|
Color color.RGBA
|
||||||
|
|
||||||
|
// Alias is a nick-name for the node. The alias can be used to confirm
|
||||||
|
// a node's identity or to serve as a short ID for an address book.
|
||||||
|
Alias string
|
||||||
|
|
||||||
|
// AuthSigBytes is the raw signature under the advertised public key
|
||||||
|
// which serves to authenticate the attributes announced by this node.
|
||||||
|
AuthSigBytes []byte
|
||||||
|
|
||||||
|
// Features is the list of protocol features supported by this node.
|
||||||
|
Features *lnwire.FeatureVector
|
||||||
|
|
||||||
|
// ExtraOpaqueData is the set of data that was appended to this
|
||||||
|
// message, some of which we may not actually know how to iterate or
|
||||||
|
// parse. By holding onto this data, we ensure that we're able to
|
||||||
|
// properly validate the set of signatures that cover these new fields,
|
||||||
|
// and ensure we're able to make upgrades to the network in a forwards
|
||||||
|
// compatible manner.
|
||||||
|
ExtraOpaqueData []byte
|
||||||
|
|
||||||
|
// TODO(roasbeef): discovery will need storage to keep it's last IP
|
||||||
|
// address and re-announce if interface changes?
|
||||||
|
|
||||||
|
// TODO(roasbeef): add update method and fetch?
|
||||||
|
}
|
||||||
|
|
||||||
|
// PubKey is the node's long-term identity public key. This key will be used to
|
||||||
|
// authenticated any advertisements/updates sent by the node.
|
||||||
|
//
|
||||||
|
// NOTE: By having this method to access an attribute, we ensure we only need
|
||||||
|
// to fully deserialize the pubkey if absolutely necessary.
|
||||||
|
func (l *LightningNode) PubKey() (*btcec.PublicKey, error) {
|
||||||
|
if l.pubKey != nil {
|
||||||
|
return l.pubKey, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
key, err := btcec.ParsePubKey(l.PubKeyBytes[:])
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
l.pubKey = key
|
||||||
|
|
||||||
|
return key, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// AuthSig is a signature under the advertised public key which serves to
|
||||||
|
// authenticate the attributes announced by this node.
|
||||||
|
//
|
||||||
|
// NOTE: By having this method to access an attribute, we ensure we only need
|
||||||
|
// to fully deserialize the signature if absolutely necessary.
|
||||||
|
func (l *LightningNode) AuthSig() (*ecdsa.Signature, error) {
|
||||||
|
return ecdsa.ParseSignature(l.AuthSigBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddPubKey is a setter-link method that can be used to swap out the public
|
||||||
|
// key for a node.
|
||||||
|
func (l *LightningNode) AddPubKey(key *btcec.PublicKey) {
|
||||||
|
l.pubKey = key
|
||||||
|
copy(l.PubKeyBytes[:], key.SerializeCompressed())
|
||||||
|
}
|
||||||
|
|
||||||
|
// NodeAnnouncement retrieves the latest node announcement of the node.
|
||||||
|
func (l *LightningNode) NodeAnnouncement(signed bool) (*lnwire.NodeAnnouncement,
|
||||||
|
error) {
|
||||||
|
|
||||||
|
if !l.HaveNodeAnnouncement {
|
||||||
|
return nil, fmt.Errorf("node does not have node announcement")
|
||||||
|
}
|
||||||
|
|
||||||
|
alias, err := lnwire.NewNodeAlias(l.Alias)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
nodeAnn := &lnwire.NodeAnnouncement{
|
||||||
|
Features: l.Features.RawFeatureVector,
|
||||||
|
NodeID: l.PubKeyBytes,
|
||||||
|
RGBColor: l.Color,
|
||||||
|
Alias: alias,
|
||||||
|
Addresses: l.Addresses,
|
||||||
|
Timestamp: uint32(l.LastUpdate.Unix()),
|
||||||
|
ExtraOpaqueData: l.ExtraOpaqueData,
|
||||||
|
}
|
||||||
|
|
||||||
|
if !signed {
|
||||||
|
return nodeAnn, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
sig, err := lnwire.NewSigFromECDSARawSignature(l.AuthSigBytes)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
nodeAnn.Signature = sig
|
||||||
|
|
||||||
|
return nodeAnn, nil
|
||||||
|
}
|
||||||
+7
-7
@@ -23,7 +23,7 @@ type ChannelGraphSource interface {
|
|||||||
// AddNode is used to add information about a node to the router
|
// 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
|
// database. If the node with this pubkey is not present in an existing
|
||||||
// channel, it will be ignored.
|
// channel, it will be ignored.
|
||||||
AddNode(node *graphdb.LightningNode,
|
AddNode(node *models.LightningNode,
|
||||||
op ...batch.SchedulerOption) error
|
op ...batch.SchedulerOption) error
|
||||||
|
|
||||||
// AddEdge is used to add edge/channel to the topology of the router,
|
// 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
|
// FetchLightningNode attempts to look up a target node by its identity
|
||||||
// public key. channeldb.ErrGraphNodeNotFound is returned if the node
|
// public key. channeldb.ErrGraphNodeNotFound is returned if the node
|
||||||
// doesn't exist within the graph.
|
// doesn't exist within the graph.
|
||||||
FetchLightningNode(route.Vertex) (*graphdb.LightningNode, error)
|
FetchLightningNode(route.Vertex) (*models.LightningNode, error)
|
||||||
|
|
||||||
// ForEachNode is used to iterate over every node in the known graph.
|
// ForEachNode is used to iterate over every node in the known graph.
|
||||||
ForEachNode(func(node *graphdb.LightningNode) error) error
|
ForEachNode(func(node *models.LightningNode) error) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// DB is an interface describing a persisted Lightning Network graph.
|
// DB is an interface describing a persisted Lightning Network graph.
|
||||||
@@ -129,7 +129,7 @@ type DB interface {
|
|||||||
// treated as the center node within a star-graph. This method may be
|
// 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
|
// used to kick off a path finding algorithm in order to explore the
|
||||||
// reachability of another node based off the source node.
|
// reachability of another node based off the source node.
|
||||||
SourceNode() (*graphdb.LightningNode, error)
|
SourceNode() (*models.LightningNode, error)
|
||||||
|
|
||||||
// DisabledChannelIDs returns the channel ids of disabled channels.
|
// DisabledChannelIDs returns the channel ids of disabled channels.
|
||||||
// A channel is disabled when two of the associated ChanelEdgePolicies
|
// A channel is disabled when two of the associated ChanelEdgePolicies
|
||||||
@@ -200,7 +200,7 @@ type DB interface {
|
|||||||
// update that node's information. Note that this method is expected to
|
// update that node's information. Note that this method is expected to
|
||||||
// only be called to update an already present node from a node
|
// only be called to update an already present node from a node
|
||||||
// announcement, or to insert a node found in a channel update.
|
// announcement, or to insert a node found in a channel update.
|
||||||
AddLightningNode(node *graphdb.LightningNode,
|
AddLightningNode(node *models.LightningNode,
|
||||||
op ...batch.SchedulerOption) error
|
op ...batch.SchedulerOption) error
|
||||||
|
|
||||||
// AddChannelEdge adds a new (undirected, blank) edge to the graph
|
// 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
|
// FetchLightningNode attempts to look up a target node by its identity
|
||||||
// public key. If the node isn't found in the database, then
|
// public key. If the node isn't found in the database, then
|
||||||
// ErrGraphNodeNotFound is returned.
|
// ErrGraphNodeNotFound is returned.
|
||||||
FetchLightningNode(nodePub route.Vertex) (*graphdb.LightningNode,
|
FetchLightningNode(nodePub route.Vertex) (*models.LightningNode,
|
||||||
error)
|
error)
|
||||||
|
|
||||||
// ForEachNode iterates through all the stored vertices/nodes in the
|
// ForEachNode iterates through all the stored vertices/nodes in the
|
||||||
// graph, executing the passed callback with each node encountered. If
|
// graph, executing the passed callback with each node encountered. If
|
||||||
// the callback returns an error, then the transaction is aborted and
|
// the callback returns an error, then the transaction is aborted and
|
||||||
// the iteration stops early.
|
// the iteration stops early.
|
||||||
ForEachNode(cb func(kvdb.RTx, *graphdb.LightningNode) error) error
|
ForEachNode(cb func(kvdb.RTx, *models.LightningNode) error) error
|
||||||
|
|
||||||
// ForEachNodeChannel iterates through all channels of the given node,
|
// ForEachNodeChannel iterates through all channels of the given node,
|
||||||
// executing the passed callback with an edge info structure and the
|
// executing the passed callback with an edge info structure and the
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import (
|
|||||||
"github.com/btcsuite/btcd/btcutil"
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/go-errors/errors"
|
"github.com/go-errors/errors"
|
||||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
|
||||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
)
|
)
|
||||||
@@ -318,7 +317,7 @@ func addToTopologyChange(graph DB, update *TopologyChange,
|
|||||||
|
|
||||||
// Any node announcement maps directly to a NetworkNodeUpdate struct.
|
// Any node announcement maps directly to a NetworkNodeUpdate struct.
|
||||||
// No further data munging or db queries are required.
|
// No further data munging or db queries are required.
|
||||||
case *graphdb.LightningNode:
|
case *models.LightningNode:
|
||||||
pubKey, err := m.PubKey()
|
pubKey, err := m.PubKey()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -77,14 +77,14 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func createTestNode(t *testing.T) *graphdb.LightningNode {
|
func createTestNode(t *testing.T) *models.LightningNode {
|
||||||
updateTime := prand.Int63()
|
updateTime := prand.Int63()
|
||||||
|
|
||||||
priv, err := btcec.NewPrivateKey()
|
priv, err := btcec.NewPrivateKey()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
pub := priv.PubKey().SerializeCompressed()
|
pub := priv.PubKey().SerializeCompressed()
|
||||||
n := &graphdb.LightningNode{
|
n := &models.LightningNode{
|
||||||
HaveNodeAnnouncement: true,
|
HaveNodeAnnouncement: true,
|
||||||
LastUpdate: time.Unix(updateTime, 0),
|
LastUpdate: time.Unix(updateTime, 0),
|
||||||
Addresses: testAddrs,
|
Addresses: testAddrs,
|
||||||
@@ -99,7 +99,7 @@ func createTestNode(t *testing.T) *graphdb.LightningNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func randEdgePolicy(chanID *lnwire.ShortChannelID,
|
func randEdgePolicy(chanID *lnwire.ShortChannelID,
|
||||||
node *graphdb.LightningNode) (*models.ChannelEdgePolicy, error) {
|
node *models.LightningNode) (*models.ChannelEdgePolicy, error) {
|
||||||
|
|
||||||
InboundFee := models.InboundFee{
|
InboundFee := models.InboundFee{
|
||||||
Base: prand.Int31() * -1,
|
Base: prand.Int31() * -1,
|
||||||
@@ -686,7 +686,7 @@ func TestNodeUpdateNotification(t *testing.T) {
|
|||||||
t.Fatalf("unable to add node: %v", err)
|
t.Fatalf("unable to add node: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
assertNodeNtfnCorrect := func(t *testing.T, ann *graphdb.LightningNode,
|
assertNodeNtfnCorrect := func(t *testing.T, ann *models.LightningNode,
|
||||||
nodeUpdate *NetworkNodeUpdate) {
|
nodeUpdate *NetworkNodeUpdate) {
|
||||||
|
|
||||||
nodeKey, _ := ann.PubKey()
|
nodeKey, _ := ann.PubKey()
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
|
||||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/routing/route"
|
"github.com/lightningnetwork/lnd/routing/route"
|
||||||
@@ -151,7 +150,7 @@ func (v *ValidationBarrier) InitJobDependencies(job interface{}) {
|
|||||||
case *lnwire.NodeAnnouncement:
|
case *lnwire.NodeAnnouncement:
|
||||||
// TODO(roasbeef): node ann needs to wait on existing channel updates
|
// TODO(roasbeef): node ann needs to wait on existing channel updates
|
||||||
return
|
return
|
||||||
case *graphdb.LightningNode:
|
case *models.LightningNode:
|
||||||
return
|
return
|
||||||
case *lnwire.AnnounceSignatures1:
|
case *lnwire.AnnounceSignatures1:
|
||||||
// TODO(roasbeef): need to wait on chan ann?
|
// TODO(roasbeef): need to wait on chan ann?
|
||||||
@@ -195,7 +194,7 @@ func (v *ValidationBarrier) WaitForDependants(job interface{}) error {
|
|||||||
jobDesc = fmt.Sprintf("job=lnwire.ChannelEdgePolicy, scid=%v",
|
jobDesc = fmt.Sprintf("job=lnwire.ChannelEdgePolicy, scid=%v",
|
||||||
msg.ChannelID)
|
msg.ChannelID)
|
||||||
|
|
||||||
case *graphdb.LightningNode:
|
case *models.LightningNode:
|
||||||
vertex := route.Vertex(msg.PubKeyBytes)
|
vertex := route.Vertex(msg.PubKeyBytes)
|
||||||
signals, ok = v.nodeAnnDependencies[vertex]
|
signals, ok = v.nodeAnnDependencies[vertex]
|
||||||
|
|
||||||
@@ -291,7 +290,7 @@ func (v *ValidationBarrier) SignalDependants(job interface{}, allow bool) {
|
|||||||
// For all other job types, we'll delete the tracking entries from the
|
// 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
|
// map, as if we reach this point, then all dependants have already
|
||||||
// finished executing and we can proceed.
|
// finished executing and we can proceed.
|
||||||
case *graphdb.LightningNode:
|
case *models.LightningNode:
|
||||||
delete(v.nodeAnnDependencies, route.Vertex(msg.PubKeyBytes))
|
delete(v.nodeAnnDependencies, route.Vertex(msg.PubKeyBytes))
|
||||||
case *lnwire.NodeAnnouncement:
|
case *lnwire.NodeAnnouncement:
|
||||||
delete(v.nodeAnnDependencies, route.Vertex(msg.NodeID))
|
delete(v.nodeAnnDependencies, route.Vertex(msg.NodeID))
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import (
|
|||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||||
"github.com/lightningnetwork/lnd/fn"
|
"github.com/lightningnetwork/lnd/fn"
|
||||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
|
||||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||||
"github.com/lightningnetwork/lnd/lncfg"
|
"github.com/lightningnetwork/lnd/lncfg"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc"
|
"github.com/lightningnetwork/lnd/lnrpc"
|
||||||
@@ -227,7 +226,7 @@ func (s *Server) ImportGraph(ctx context.Context,
|
|||||||
|
|
||||||
var err error
|
var err error
|
||||||
for _, rpcNode := range graph.Nodes {
|
for _, rpcNode := range graph.Nodes {
|
||||||
node := &graphdb.LightningNode{
|
node := &models.LightningNode{
|
||||||
HaveNodeAnnouncement: true,
|
HaveNodeAnnouncement: true,
|
||||||
LastUpdate: time.Unix(
|
LastUpdate: time.Unix(
|
||||||
int64(rpcNode.LastUpdate), 0,
|
int64(rpcNode.LastUpdate), 0,
|
||||||
|
|||||||
@@ -214,7 +214,7 @@ func parseTestGraph(t *testing.T, useCache bool, path string) (
|
|||||||
privKeyMap := make(map[string]*btcec.PrivateKey)
|
privKeyMap := make(map[string]*btcec.PrivateKey)
|
||||||
channelIDs := make(map[route.Vertex]map[route.Vertex]uint64)
|
channelIDs := make(map[route.Vertex]map[route.Vertex]uint64)
|
||||||
links := make(map[lnwire.ShortChannelID]htlcswitch.ChannelLink)
|
links := make(map[lnwire.ShortChannelID]htlcswitch.ChannelLink)
|
||||||
var source *graphdb.LightningNode
|
var source *models.LightningNode
|
||||||
|
|
||||||
// First we insert all the nodes within the graph as vertexes.
|
// First we insert all the nodes within the graph as vertexes.
|
||||||
for _, node := range g.Nodes {
|
for _, node := range g.Nodes {
|
||||||
@@ -223,7 +223,7 @@ func parseTestGraph(t *testing.T, useCache bool, path string) (
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
dbNode := &graphdb.LightningNode{
|
dbNode := &models.LightningNode{
|
||||||
HaveNodeAnnouncement: true,
|
HaveNodeAnnouncement: true,
|
||||||
AuthSigBytes: testSig.Serialize(),
|
AuthSigBytes: testSig.Serialize(),
|
||||||
LastUpdate: testTime,
|
LastUpdate: testTime,
|
||||||
@@ -536,7 +536,7 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
|
|||||||
|
|
||||||
nodeIndex := byte(0)
|
nodeIndex := byte(0)
|
||||||
addNodeWithAlias := func(alias string, features *lnwire.FeatureVector) (
|
addNodeWithAlias := func(alias string, features *lnwire.FeatureVector) (
|
||||||
*graphdb.LightningNode, error) {
|
*models.LightningNode, error) {
|
||||||
|
|
||||||
keyBytes := []byte{
|
keyBytes := []byte{
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
@@ -551,7 +551,7 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
|
|||||||
features = lnwire.EmptyFeatureVector()
|
features = lnwire.EmptyFeatureVector()
|
||||||
}
|
}
|
||||||
|
|
||||||
dbNode := &graphdb.LightningNode{
|
dbNode := &models.LightningNode{
|
||||||
HaveNodeAnnouncement: true,
|
HaveNodeAnnouncement: true,
|
||||||
AuthSigBytes: testSig.Serialize(),
|
AuthSigBytes: testSig.Serialize(),
|
||||||
LastUpdate: testTime,
|
LastUpdate: testTime,
|
||||||
@@ -1207,7 +1207,7 @@ func runPathFindingWithAdditionalEdges(t *testing.T, useCache bool) {
|
|||||||
dogePubKey, err := btcec.ParsePubKey(dogePubKeyBytes)
|
dogePubKey, err := btcec.ParsePubKey(dogePubKeyBytes)
|
||||||
require.NoError(t, err, "unable to parse public key from bytes")
|
require.NoError(t, err, "unable to parse public key from bytes")
|
||||||
|
|
||||||
doge := &graphdb.LightningNode{}
|
doge := &models.LightningNode{}
|
||||||
doge.AddPubKey(dogePubKey)
|
doge.AddPubKey(dogePubKey)
|
||||||
doge.Alias = "doge"
|
doge.Alias = "doge"
|
||||||
copy(doge.PubKeyBytes[:], dogePubKeyBytes)
|
copy(doge.PubKeyBytes[:], dogePubKeyBytes)
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package routing
|
|||||||
import (
|
import (
|
||||||
"github.com/btcsuite/btcd/btcec/v2"
|
"github.com/btcsuite/btcd/btcec/v2"
|
||||||
"github.com/lightningnetwork/lnd/fn"
|
"github.com/lightningnetwork/lnd/fn"
|
||||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
|
||||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/routing/route"
|
"github.com/lightningnetwork/lnd/routing/route"
|
||||||
@@ -24,7 +23,7 @@ type SessionSource struct {
|
|||||||
GraphSessionFactory GraphSessionFactory
|
GraphSessionFactory GraphSessionFactory
|
||||||
|
|
||||||
// SourceNode is the graph's source node.
|
// SourceNode is the graph's source node.
|
||||||
SourceNode *graphdb.LightningNode
|
SourceNode *models.LightningNode
|
||||||
|
|
||||||
// GetLink is a method that allows querying the lower link layer
|
// GetLink is a method that allows querying the lower link layer
|
||||||
// to determine the up to date available bandwidth at a prospective link
|
// to determine the up to date available bandwidth at a prospective link
|
||||||
@@ -101,7 +100,7 @@ func RouteHintsToEdges(routeHints [][]zpay32.HopHint, target route.Vertex) (
|
|||||||
// we'll need to look at the next hint's start node. If
|
// we'll need to look at the next hint's start node. If
|
||||||
// we've reached the end of the hints list, we can
|
// we've reached the end of the hints list, we can
|
||||||
// assume we've reached the destination.
|
// assume we've reached the destination.
|
||||||
endNode := &graphdb.LightningNode{}
|
endNode := &models.LightningNode{}
|
||||||
if i != len(routeHint)-1 {
|
if i != len(routeHint)-1 {
|
||||||
endNode.AddPubKey(routeHint[i+1].NodeID)
|
endNode.AddPubKey(routeHint[i+1].NodeID)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
|
||||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||||
"github.com/lightningnetwork/lnd/lntypes"
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
@@ -89,7 +88,7 @@ func TestUpdateAdditionalEdge(t *testing.T) {
|
|||||||
|
|
||||||
// Create a minimal test node using the private key priv1.
|
// Create a minimal test node using the private key priv1.
|
||||||
pub := priv1.PubKey().SerializeCompressed()
|
pub := priv1.PubKey().SerializeCompressed()
|
||||||
testNode := &graphdb.LightningNode{}
|
testNode := &models.LightningNode{}
|
||||||
copy(testNode.PubKeyBytes[:], pub)
|
copy(testNode.PubKeyBytes[:], pub)
|
||||||
|
|
||||||
nodeID, err := testNode.PubKey()
|
nodeID, err := testNode.PubKey()
|
||||||
|
|||||||
@@ -192,7 +192,7 @@ func createTestCtxFromGraphInstanceAssumeValid(t *testing.T,
|
|||||||
return ctx
|
return ctx
|
||||||
}
|
}
|
||||||
|
|
||||||
func createTestNode() (*graphdb.LightningNode, error) {
|
func createTestNode() (*models.LightningNode, error) {
|
||||||
updateTime := rand.Int63()
|
updateTime := rand.Int63()
|
||||||
|
|
||||||
priv, err := btcec.NewPrivateKey()
|
priv, err := btcec.NewPrivateKey()
|
||||||
@@ -201,7 +201,7 @@ func createTestNode() (*graphdb.LightningNode, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub := priv.PubKey().SerializeCompressed()
|
pub := priv.PubKey().SerializeCompressed()
|
||||||
n := &graphdb.LightningNode{
|
n := &models.LightningNode{
|
||||||
HaveNodeAnnouncement: true,
|
HaveNodeAnnouncement: true,
|
||||||
LastUpdate: time.Unix(updateTime, 0),
|
LastUpdate: time.Unix(updateTime, 0),
|
||||||
Addresses: testAddrs,
|
Addresses: testAddrs,
|
||||||
@@ -2899,7 +2899,7 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
|
|||||||
|
|
||||||
// Now check that we can update the node info for the partial node
|
// Now check that we can update the node info for the partial node
|
||||||
// without messing up the channel graph.
|
// without messing up the channel graph.
|
||||||
n1 := &graphdb.LightningNode{
|
n1 := &models.LightningNode{
|
||||||
HaveNodeAnnouncement: true,
|
HaveNodeAnnouncement: true,
|
||||||
LastUpdate: time.Unix(123, 0),
|
LastUpdate: time.Unix(123, 0),
|
||||||
Addresses: testAddrs,
|
Addresses: testAddrs,
|
||||||
@@ -2912,7 +2912,7 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
|
|||||||
|
|
||||||
require.NoError(t, ctx.graph.AddLightningNode(n1))
|
require.NoError(t, ctx.graph.AddLightningNode(n1))
|
||||||
|
|
||||||
n2 := &graphdb.LightningNode{
|
n2 := &models.LightningNode{
|
||||||
HaveNodeAnnouncement: true,
|
HaveNodeAnnouncement: true,
|
||||||
LastUpdate: time.Unix(123, 0),
|
LastUpdate: time.Unix(123, 0),
|
||||||
Addresses: testAddrs,
|
Addresses: testAddrs,
|
||||||
|
|||||||
+2
-2
@@ -6533,7 +6533,7 @@ func (r *rpcServer) DescribeGraph(ctx context.Context,
|
|||||||
// First iterate through all the known nodes (connected or unconnected
|
// First iterate through all the known nodes (connected or unconnected
|
||||||
// within the graph), collating their current state into the RPC
|
// within the graph), collating their current state into the RPC
|
||||||
// response.
|
// response.
|
||||||
err := graph.ForEachNode(func(_ kvdb.RTx, node *graphdb.LightningNode) error {
|
err := graph.ForEachNode(func(_ kvdb.RTx, node *models.LightningNode) error {
|
||||||
lnNode := marshalNode(node)
|
lnNode := marshalNode(node)
|
||||||
|
|
||||||
resp.Nodes = append(resp.Nodes, lnNode)
|
resp.Nodes = append(resp.Nodes, lnNode)
|
||||||
@@ -6861,7 +6861,7 @@ func (r *rpcServer) GetNodeInfo(ctx context.Context,
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func marshalNode(node *graphdb.LightningNode) *lnrpc.LightningNode {
|
func marshalNode(node *models.LightningNode) *lnrpc.LightningNode {
|
||||||
nodeAddrs := make([]*lnrpc.NodeAddress, len(node.Addresses))
|
nodeAddrs := make([]*lnrpc.NodeAddress, len(node.Addresses))
|
||||||
for i, addr := range node.Addresses {
|
for i, addr := range node.Addresses {
|
||||||
nodeAddr := &lnrpc.NodeAddress{
|
nodeAddr := &lnrpc.NodeAddress{
|
||||||
|
|||||||
@@ -877,7 +877,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
selfNode := &graphdb.LightningNode{
|
selfNode := &models.LightningNode{
|
||||||
HaveNodeAnnouncement: true,
|
HaveNodeAnnouncement: true,
|
||||||
LastUpdate: time.Now(),
|
LastUpdate: time.Now(),
|
||||||
Addresses: selfAddrs,
|
Addresses: selfAddrs,
|
||||||
@@ -3184,7 +3184,7 @@ func (s *server) createNewHiddenService() error {
|
|||||||
|
|
||||||
// Finally, we'll update the on-disk version of our announcement so it
|
// Finally, we'll update the on-disk version of our announcement so it
|
||||||
// will eventually propagate to nodes in the network.
|
// will eventually propagate to nodes in the network.
|
||||||
selfNode := &graphdb.LightningNode{
|
selfNode := &models.LightningNode{
|
||||||
HaveNodeAnnouncement: true,
|
HaveNodeAnnouncement: true,
|
||||||
LastUpdate: time.Unix(int64(newNodeAnn.Timestamp), 0),
|
LastUpdate: time.Unix(int64(newNodeAnn.Timestamp), 0),
|
||||||
Addresses: newNodeAnn.Addresses,
|
Addresses: newNodeAnn.Addresses,
|
||||||
|
|||||||
Reference in new issue
Block a user