multi: fix linter errors
This commit is contained in:
11 files changed
+276
-186
No files matched your search
+6
-3
@@ -3,6 +3,7 @@ package autopilot
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"errors"
|
||||||
"net"
|
"net"
|
||||||
"sort"
|
"sort"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
@@ -134,7 +135,9 @@ 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 *models.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.
|
||||||
@@ -168,9 +171,9 @@ func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
|
|||||||
|
|
||||||
dbNode, err := d.db.FetchLightningNode(vertex)
|
dbNode, err := d.db.FetchLightningNode(vertex)
|
||||||
switch {
|
switch {
|
||||||
case err == graphdb.ErrGraphNodeNotFound:
|
case errors.Is(err, graphdb.ErrGraphNodeNotFound):
|
||||||
fallthrough
|
fallthrough
|
||||||
case err == graphdb.ErrGraphNotFound:
|
case errors.Is(err, graphdb.ErrGraphNotFound):
|
||||||
graphNode := &models.LightningNode{
|
graphNode := &models.LightningNode{
|
||||||
HaveNodeAnnouncement: true,
|
HaveNodeAnnouncement: true,
|
||||||
Addresses: []net.Addr{
|
Addresses: []net.Addr{
|
||||||
|
|||||||
@@ -734,7 +734,7 @@ func createLightningNode(priv *btcec.PrivateKey) *models.LightningNode {
|
|||||||
AuthSigBytes: testSig.Serialize(),
|
AuthSigBytes: testSig.Serialize(),
|
||||||
LastUpdate: time.Unix(updateTime, 0),
|
LastUpdate: time.Unix(updateTime, 0),
|
||||||
Color: color.RGBA{1, 2, 3, 0},
|
Color: color.RGBA{1, 2, 3, 0},
|
||||||
Alias: "kek" + string(pub[:]),
|
Alias: "kek" + string(pub),
|
||||||
Features: testFeatures,
|
Features: testFeatures,
|
||||||
Addresses: testAddrs,
|
Addresses: testAddrs,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1685,7 +1685,7 @@ func (d *AuthenticatedGossiper) retransmitStaleAnns(now time.Time) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil && err != graphdb.ErrGraphNoEdgesFound {
|
if err != nil && !errors.Is(err, graphdb.ErrGraphNoEdgesFound) {
|
||||||
return fmt.Errorf("unable to retrieve outgoing channels: %w",
|
return fmt.Errorf("unable to retrieve outgoing channels: %w",
|
||||||
err)
|
err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -202,7 +202,9 @@ func (r *mockGraphSource) AddProof(chanID lnwire.ShortChannelID,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *mockGraphSource) ForEachNode(func(node *models.LightningNode) error) error {
|
func (r *mockGraphSource) ForEachNode(
|
||||||
|
func(node *models.LightningNode) error) error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2318,9 +2320,7 @@ func TestProcessZombieEdgeNowLive(t *testing.T) {
|
|||||||
|
|
||||||
// At this point, the channel should still be considered a zombie.
|
// At this point, the channel should still be considered a zombie.
|
||||||
_, _, _, err = ctx.router.GetChannelByID(chanID)
|
_, _, _, err = ctx.router.GetChannelByID(chanID)
|
||||||
if err != graphdb.ErrZombieEdge {
|
require.ErrorIs(t, err, graphdb.ErrZombieEdge)
|
||||||
t.Fatalf("channel should still be a zombie")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Attempting to process the current channel update should fail due to
|
// Attempting to process the current channel update should fail due to
|
||||||
// its edge being considered a zombie and its timestamp not being within
|
// its edge being considered a zombie and its timestamp not being within
|
||||||
@@ -2441,7 +2441,7 @@ func TestReceiveRemoteChannelUpdateFirst(t *testing.T) {
|
|||||||
// to the map of premature ChannelUpdates. Check that nothing
|
// to the map of premature ChannelUpdates. Check that nothing
|
||||||
// was added to the graph.
|
// was added to the graph.
|
||||||
chanInfo, e1, e2, err := ctx.router.GetChannelByID(batch.chanUpdAnn1.ShortChannelID)
|
chanInfo, e1, e2, err := ctx.router.GetChannelByID(batch.chanUpdAnn1.ShortChannelID)
|
||||||
if err != graphdb.ErrEdgeNotFound {
|
if !errors.Is(err, graphdb.ErrEdgeNotFound) {
|
||||||
t.Fatalf("Expected ErrEdgeNotFound, got: %v", err)
|
t.Fatalf("Expected ErrEdgeNotFound, got: %v", err)
|
||||||
}
|
}
|
||||||
if chanInfo != nil {
|
if chanInfo != nil {
|
||||||
|
|||||||
+141
-88
@@ -123,9 +123,9 @@ var (
|
|||||||
// edge's participants.
|
// edge's participants.
|
||||||
zombieBucket = []byte("zombie-index")
|
zombieBucket = []byte("zombie-index")
|
||||||
|
|
||||||
// disabledEdgePolicyBucket is a sub-bucket of the main edgeBucket bucket
|
// disabledEdgePolicyBucket is a sub-bucket of the main edgeBucket
|
||||||
// responsible for maintaining an index of disabled edge policies. Each
|
// bucket responsible for maintaining an index of disabled edge
|
||||||
// entry exists within the bucket as follows:
|
// policies. Each entry exists within the bucket as follows:
|
||||||
//
|
//
|
||||||
// maps: <chanID><direction> -> []byte{}
|
// maps: <chanID><direction> -> []byte{}
|
||||||
//
|
//
|
||||||
@@ -471,28 +471,32 @@ func (c *ChannelGraph) ForEachChannel(cb func(*models.ChannelEdgeInfo,
|
|||||||
|
|
||||||
// Load edge index, recombine each channel with the policies
|
// Load edge index, recombine each channel with the policies
|
||||||
// loaded above and invoke the callback.
|
// loaded above and invoke the callback.
|
||||||
return kvdb.ForAll(edgeIndex, func(k, edgeInfoBytes []byte) error {
|
return kvdb.ForAll(
|
||||||
var chanID [8]byte
|
edgeIndex, func(k, edgeInfoBytes []byte) error {
|
||||||
copy(chanID[:], k)
|
var chanID [8]byte
|
||||||
|
copy(chanID[:], k)
|
||||||
|
|
||||||
edgeInfoReader := bytes.NewReader(edgeInfoBytes)
|
edgeInfoReader := bytes.NewReader(edgeInfoBytes)
|
||||||
info, err := deserializeChanEdgeInfo(edgeInfoReader)
|
info, err := deserializeChanEdgeInfo(
|
||||||
if err != nil {
|
edgeInfoReader,
|
||||||
return err
|
)
|
||||||
}
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
policy1 := channelMap[channelMapKey{
|
policy1 := channelMap[channelMapKey{
|
||||||
nodeKey: info.NodeKey1Bytes,
|
nodeKey: info.NodeKey1Bytes,
|
||||||
chanID: chanID,
|
chanID: chanID,
|
||||||
}]
|
}]
|
||||||
|
|
||||||
policy2 := channelMap[channelMapKey{
|
policy2 := channelMap[channelMapKey{
|
||||||
nodeKey: info.NodeKey2Bytes,
|
nodeKey: info.NodeKey2Bytes,
|
||||||
chanID: chanID,
|
chanID: chanID,
|
||||||
}]
|
}]
|
||||||
|
|
||||||
return cb(&info, policy1, policy2)
|
return cb(&info, policy1, policy2)
|
||||||
})
|
},
|
||||||
|
)
|
||||||
}, func() {})
|
}, func() {})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -600,7 +604,9 @@ 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 *models.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,
|
||||||
@@ -675,20 +681,27 @@ func (c *ChannelGraph) DisabledChannelIDs() ([]uint64, error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// We iterate over all disabled policies and we add each channel that
|
// We iterate over all disabled policies and we add each channel
|
||||||
// has more than one disabled policy to disabledChanIDs array.
|
// that has more than one disabled policy to disabledChanIDs
|
||||||
return disabledEdgePolicyIndex.ForEach(func(k, v []byte) error {
|
// array.
|
||||||
chanID := byteOrder.Uint64(k[:8])
|
return disabledEdgePolicyIndex.ForEach(
|
||||||
_, edgeFound := chanEdgeFound[chanID]
|
func(k, v []byte) error {
|
||||||
if edgeFound {
|
chanID := byteOrder.Uint64(k[:8])
|
||||||
delete(chanEdgeFound, chanID)
|
_, edgeFound := chanEdgeFound[chanID]
|
||||||
disabledChanIDs = append(disabledChanIDs, chanID)
|
if edgeFound {
|
||||||
return nil
|
delete(chanEdgeFound, chanID)
|
||||||
}
|
disabledChanIDs = append(
|
||||||
|
disabledChanIDs, chanID,
|
||||||
|
)
|
||||||
|
|
||||||
chanEdgeFound[chanID] = struct{}{}
|
return nil
|
||||||
return nil
|
}
|
||||||
})
|
|
||||||
|
chanEdgeFound[chanID] = struct{}{}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
)
|
||||||
}, func() {
|
}, func() {
|
||||||
disabledChanIDs = nil
|
disabledChanIDs = nil
|
||||||
chanEdgeFound = make(map[uint64]struct{})
|
chanEdgeFound = make(map[uint64]struct{})
|
||||||
@@ -816,7 +829,9 @@ func (c *ChannelGraph) SourceNode() (*models.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) (*models.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
|
||||||
@@ -1338,12 +1353,15 @@ func (c *ChannelGraph) PruneGraph(spentOutputs []*wire.OutPoint,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Next grab the two edge indexes which will also need to be updated.
|
// Next grab the two edge indexes which will also need to be
|
||||||
|
// updated.
|
||||||
edgeIndex, err := edges.CreateBucketIfNotExists(edgeIndexBucket)
|
edgeIndex, err := edges.CreateBucketIfNotExists(edgeIndexBucket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
chanIndex, err := edges.CreateBucketIfNotExists(channelPointBucket)
|
chanIndex, err := edges.CreateBucketIfNotExists(
|
||||||
|
channelPointBucket,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -1364,7 +1382,8 @@ func (c *ChannelGraph) PruneGraph(spentOutputs []*wire.OutPoint,
|
|||||||
// if NOT if filter
|
// if NOT if filter
|
||||||
|
|
||||||
var opBytes bytes.Buffer
|
var opBytes bytes.Buffer
|
||||||
if err := WriteOutpoint(&opBytes, chanPoint); err != nil {
|
err := WriteOutpoint(&opBytes, chanPoint)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1403,7 +1422,9 @@ func (c *ChannelGraph) PruneGraph(spentOutputs []*wire.OutPoint,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
pruneBucket, err := metaBucket.CreateBucketIfNotExists(pruneLogBucket)
|
pruneBucket, err := metaBucket.CreateBucketIfNotExists(
|
||||||
|
pruneLogBucket,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -1549,7 +1570,8 @@ func (c *ChannelGraph) pruneGraphNodes(nodes kvdb.RwBucket,
|
|||||||
|
|
||||||
// If we reach this point, then there are no longer any edges
|
// If we reach this point, then there are no longer any edges
|
||||||
// that connect this node, so we can delete it.
|
// that connect this node, so we can delete it.
|
||||||
if err := c.deleteLightningNode(nodes, nodePubKey[:]); err != nil {
|
err := c.deleteLightningNode(nodes, nodePubKey[:])
|
||||||
|
if err != nil {
|
||||||
if errors.Is(err, ErrGraphNodeNotFound) ||
|
if errors.Is(err, ErrGraphNodeNotFound) ||
|
||||||
errors.Is(err, ErrGraphNodesNotFound) {
|
errors.Is(err, ErrGraphNodesNotFound) {
|
||||||
|
|
||||||
@@ -1616,7 +1638,9 @@ func (c *ChannelGraph) DisconnectBlockAtHeight(height uint32) (
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
chanIndex, err := edges.CreateBucketIfNotExists(channelPointBucket)
|
chanIndex, err := edges.CreateBucketIfNotExists(
|
||||||
|
channelPointBucket,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -1664,7 +1688,9 @@ func (c *ChannelGraph) DisconnectBlockAtHeight(height uint32) (
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
pruneBucket, err := metaBucket.CreateBucketIfNotExists(pruneLogBucket)
|
pruneBucket, err := metaBucket.CreateBucketIfNotExists(
|
||||||
|
pruneLogBucket,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -1679,9 +1705,9 @@ func (c *ChannelGraph) DisconnectBlockAtHeight(height uint32) (
|
|||||||
// the keys in a second loop.
|
// the keys in a second loop.
|
||||||
var pruneKeys [][]byte
|
var pruneKeys [][]byte
|
||||||
pruneCursor := pruneBucket.ReadWriteCursor()
|
pruneCursor := pruneBucket.ReadWriteCursor()
|
||||||
|
//nolint:lll
|
||||||
for k, _ := pruneCursor.Seek(pruneKeyStart[:]); k != nil &&
|
for k, _ := pruneCursor.Seek(pruneKeyStart[:]); k != nil &&
|
||||||
bytes.Compare(k, pruneKeyEnd[:]) <= 0; k, _ = pruneCursor.Next() {
|
bytes.Compare(k, pruneKeyEnd[:]) <= 0; k, _ = pruneCursor.Next() {
|
||||||
|
|
||||||
pruneKeys = append(pruneKeys, k)
|
pruneKeys = append(pruneKeys, k)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1977,6 +2003,8 @@ func (c *ChannelGraph) ChanUpdatesInHorizon(startTime,
|
|||||||
// With our start and end times constructed, we'll step through
|
// With our start and end times constructed, we'll step through
|
||||||
// the index collecting the info and policy of each update of
|
// the index collecting the info and policy of each update of
|
||||||
// each channel that has a last update within the time range.
|
// each channel that has a last update within the time range.
|
||||||
|
//
|
||||||
|
//nolint:lll
|
||||||
for indexKey, _ := updateCursor.Seek(startTimeBytes[:]); indexKey != nil &&
|
for indexKey, _ := updateCursor.Seek(startTimeBytes[:]); indexKey != nil &&
|
||||||
bytes.Compare(indexKey, endTimeBytes[:]) <= 0; indexKey, _ = updateCursor.Next() {
|
bytes.Compare(indexKey, endTimeBytes[:]) <= 0; indexKey, _ = updateCursor.Next() {
|
||||||
|
|
||||||
@@ -2110,6 +2138,8 @@ func (c *ChannelGraph) NodeUpdatesInHorizon(startTime,
|
|||||||
// With our start and end times constructed, we'll step through
|
// With our start and end times constructed, we'll step through
|
||||||
// the index collecting info for each node within the time
|
// the index collecting info for each node within the time
|
||||||
// range.
|
// range.
|
||||||
|
//
|
||||||
|
//nolint:lll
|
||||||
for indexKey, _ := updateCursor.Seek(startTimeBytes[:]); indexKey != nil &&
|
for indexKey, _ := updateCursor.Seek(startTimeBytes[:]); indexKey != nil &&
|
||||||
bytes.Compare(indexKey, endTimeBytes[:]) <= 0; indexKey, _ = updateCursor.Next() {
|
bytes.Compare(indexKey, endTimeBytes[:]) <= 0; indexKey, _ = updateCursor.Next() {
|
||||||
|
|
||||||
@@ -2346,6 +2376,8 @@ func (c *ChannelGraph) FilterChannelRange(startHeight,
|
|||||||
|
|
||||||
// We'll now iterate through the database, and find each
|
// We'll now iterate through the database, and find each
|
||||||
// channel ID that resides within the specified range.
|
// channel ID that resides within the specified range.
|
||||||
|
//
|
||||||
|
//nolint:lll
|
||||||
for k, v := cursor.Seek(chanIDStart[:]); k != nil &&
|
for k, v := cursor.Seek(chanIDStart[:]); k != nil &&
|
||||||
bytes.Compare(k, chanIDEnd[:]) <= 0; k, v = cursor.Next() {
|
bytes.Compare(k, chanIDEnd[:]) <= 0; k, v = cursor.Next() {
|
||||||
// Don't send alias SCIDs during gossip sync.
|
// Don't send alias SCIDs during gossip sync.
|
||||||
@@ -2578,7 +2610,9 @@ func delEdgeUpdateIndexEntry(edgesBucket kvdb.RwBucket, chanID uint64,
|
|||||||
// would have been created by both edges: we'll alternate the update
|
// would have been created by both edges: we'll alternate the update
|
||||||
// times, as one may had overridden the other.
|
// times, as one may had overridden the other.
|
||||||
if edge1 != nil {
|
if edge1 != nil {
|
||||||
byteOrder.PutUint64(indexKey[:8], uint64(edge1.LastUpdate.Unix()))
|
byteOrder.PutUint64(
|
||||||
|
indexKey[:8], uint64(edge1.LastUpdate.Unix()),
|
||||||
|
)
|
||||||
if err := updateIndex.Delete(indexKey[:]); err != nil {
|
if err := updateIndex.Delete(indexKey[:]); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -2587,7 +2621,9 @@ func delEdgeUpdateIndexEntry(edgesBucket kvdb.RwBucket, chanID uint64,
|
|||||||
// We'll also attempt to delete the entry that may have been created by
|
// We'll also attempt to delete the entry that may have been created by
|
||||||
// the second edge.
|
// the second edge.
|
||||||
if edge2 != nil {
|
if edge2 != nil {
|
||||||
byteOrder.PutUint64(indexKey[:8], uint64(edge2.LastUpdate.Unix()))
|
byteOrder.PutUint64(
|
||||||
|
indexKey[:8], uint64(edge2.LastUpdate.Unix()),
|
||||||
|
)
|
||||||
if err := updateIndex.Delete(indexKey[:]); err != nil {
|
if err := updateIndex.Delete(indexKey[:]); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -2654,7 +2690,8 @@ func (c *ChannelGraph) delChannelEdgeUnsafe(edges, edgeIndex, chanIndex,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// As part of deleting the edge we also remove all disabled entries
|
// As part of deleting the edge we also remove all disabled entries
|
||||||
// from the edgePolicyDisabledIndex bucket. We do that for both directions.
|
// from the edgePolicyDisabledIndex bucket. We do that for both
|
||||||
|
// directions.
|
||||||
updateEdgePolicyDisabledIndex(edges, cid, false, false)
|
updateEdgePolicyDisabledIndex(edges, cid, false, false)
|
||||||
updateEdgePolicyDisabledIndex(edges, cid, true, false)
|
updateEdgePolicyDisabledIndex(edges, cid, true, false)
|
||||||
|
|
||||||
@@ -2935,8 +2972,8 @@ 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) (*models.LightningNode,
|
func (c *ChannelGraph) FetchLightningNode(nodePub route.Vertex) (
|
||||||
error) {
|
*models.LightningNode, error) {
|
||||||
|
|
||||||
return c.fetchLightningNode(nil, nodePub)
|
return c.fetchLightningNode(nil, nodePub)
|
||||||
}
|
}
|
||||||
@@ -3047,7 +3084,9 @@ var _ GraphCacheNode = (*graphCacheNode)(nil)
|
|||||||
// timestamp of when the data for the node was lasted updated is returned along
|
// timestamp of when the data for the node was lasted updated is returned along
|
||||||
// with a true boolean. Otherwise, an empty time.Time is returned with a false
|
// with a true boolean. Otherwise, an empty time.Time is returned with a false
|
||||||
// boolean.
|
// boolean.
|
||||||
func (c *ChannelGraph) HasLightningNode(nodePub [33]byte) (time.Time, bool, error) {
|
func (c *ChannelGraph) HasLightningNode(nodePub [33]byte) (time.Time, bool,
|
||||||
|
error) {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
updateTime time.Time
|
updateTime time.Time
|
||||||
exists bool
|
exists bool
|
||||||
@@ -3124,7 +3163,7 @@ func nodeTraversal(tx kvdb.RTx, nodePub []byte, db kvdb.Backend,
|
|||||||
// as its prefix. This indicates that we've stepped over into
|
// as its prefix. This indicates that we've stepped over into
|
||||||
// another node's edges, so we can terminate our scan.
|
// another node's edges, so we can terminate our scan.
|
||||||
edgeCursor := edges.ReadCursor()
|
edgeCursor := edges.ReadCursor()
|
||||||
for nodeEdge, _ := edgeCursor.Seek(nodeStart[:]); bytes.HasPrefix(nodeEdge, nodePub); nodeEdge, _ = edgeCursor.Next() {
|
for nodeEdge, _ := edgeCursor.Seek(nodeStart[:]); bytes.HasPrefix(nodeEdge, nodePub); nodeEdge, _ = edgeCursor.Next() { //nolint:lll
|
||||||
// If the prefix still matches, the channel id is
|
// If the prefix still matches, the channel id is
|
||||||
// returned in nodeEdge. Channel id is used to lookup
|
// returned in nodeEdge. Channel id is used to lookup
|
||||||
// the node at the other end of the channel and both
|
// the node at the other end of the channel and both
|
||||||
@@ -3216,8 +3255,8 @@ 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) (*models.LightningNode,
|
channel *models.ChannelEdgeInfo, thisNodeKey []byte) (
|
||||||
error) {
|
*models.LightningNode, 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.
|
||||||
var targetNodeBytes [33]byte
|
var targetNodeBytes [33]byte
|
||||||
@@ -3253,7 +3292,9 @@ func (c *ChannelGraph) FetchOtherNode(tx kvdb.RTx,
|
|||||||
// otherwise we can use the existing db transaction.
|
// otherwise we can use the existing db transaction.
|
||||||
var err error
|
var err error
|
||||||
if tx == nil {
|
if tx == nil {
|
||||||
err = kvdb.View(c.db, fetchNodeFunc, func() { targetNode = nil })
|
err = kvdb.View(c.db, fetchNodeFunc, func() {
|
||||||
|
targetNode = nil
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
err = fetchNodeFunc(tx)
|
err = fetchNodeFunc(tx)
|
||||||
}
|
}
|
||||||
@@ -3563,37 +3604,41 @@ func (c *ChannelGraph) ChannelView() ([]EdgePoint, error) {
|
|||||||
// Once we have the proper bucket, we'll range over each key
|
// Once we have the proper bucket, we'll range over each key
|
||||||
// (which is the channel point for the channel) and decode it,
|
// (which is the channel point for the channel) and decode it,
|
||||||
// accumulating each entry.
|
// accumulating each entry.
|
||||||
return chanIndex.ForEach(func(chanPointBytes, chanID []byte) error {
|
return chanIndex.ForEach(
|
||||||
chanPointReader := bytes.NewReader(chanPointBytes)
|
func(chanPointBytes, chanID []byte) error {
|
||||||
|
chanPointReader := bytes.NewReader(
|
||||||
|
chanPointBytes,
|
||||||
|
)
|
||||||
|
|
||||||
var chanPoint wire.OutPoint
|
var chanPoint wire.OutPoint
|
||||||
err := ReadOutpoint(chanPointReader, &chanPoint)
|
err := ReadOutpoint(chanPointReader, &chanPoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
edgeInfo, err := fetchChanEdgeInfo(
|
edgeInfo, err := fetchChanEdgeInfo(
|
||||||
edgeIndex, chanID,
|
edgeIndex, chanID,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
pkScript, err := genMultiSigP2WSH(
|
pkScript, err := genMultiSigP2WSH(
|
||||||
edgeInfo.BitcoinKey1Bytes[:],
|
edgeInfo.BitcoinKey1Bytes[:],
|
||||||
edgeInfo.BitcoinKey2Bytes[:],
|
edgeInfo.BitcoinKey2Bytes[:],
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
edgePoints = append(edgePoints, EdgePoint{
|
edgePoints = append(edgePoints, EdgePoint{
|
||||||
FundingPkScript: pkScript,
|
FundingPkScript: pkScript,
|
||||||
OutPoint: chanPoint,
|
OutPoint: chanPoint,
|
||||||
})
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
},
|
||||||
|
)
|
||||||
}, func() {
|
}, func() {
|
||||||
edgePoints = nil
|
edgePoints = nil
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
@@ -4082,8 +4127,8 @@ func deserializeLightningNode(r io.Reader) (models.LightningNode, error) {
|
|||||||
node.HaveNodeAnnouncement = false
|
node.HaveNodeAnnouncement = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// The rest of the data is optional, and will only be there if we got a node
|
// The rest of the data is optional, and will only be there if we got a
|
||||||
// announcement for this node.
|
// node announcement for this node.
|
||||||
if !node.HaveNodeAnnouncement {
|
if !node.HaveNodeAnnouncement {
|
||||||
return node, nil
|
return node, nil
|
||||||
}
|
}
|
||||||
@@ -4192,7 +4237,8 @@ func putChanEdgeInfo(edgeIndex kvdb.RwBucket,
|
|||||||
if err := WriteOutpoint(&b, &edgeInfo.ChannelPoint); err != nil {
|
if err := WriteOutpoint(&b, &edgeInfo.ChannelPoint); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := binary.Write(&b, byteOrder, uint64(edgeInfo.Capacity)); err != nil {
|
err := binary.Write(&b, byteOrder, uint64(edgeInfo.Capacity))
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := b.Write(chanID[:]); err != nil {
|
if _, err := b.Write(chanID[:]); err != nil {
|
||||||
@@ -4205,7 +4251,7 @@ func putChanEdgeInfo(edgeIndex kvdb.RwBucket,
|
|||||||
if len(edgeInfo.ExtraOpaqueData) > MaxAllowedExtraOpaqueBytes {
|
if len(edgeInfo.ExtraOpaqueData) > MaxAllowedExtraOpaqueBytes {
|
||||||
return ErrTooManyExtraOpaqueBytes(len(edgeInfo.ExtraOpaqueData))
|
return ErrTooManyExtraOpaqueBytes(len(edgeInfo.ExtraOpaqueData))
|
||||||
}
|
}
|
||||||
err := wire.WriteVarBytes(&b, 0, edgeInfo.ExtraOpaqueData)
|
err = wire.WriteVarBytes(&b, 0, edgeInfo.ExtraOpaqueData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -4518,10 +4564,14 @@ func serializeChanEdgePolicy(w io.Writer, edge *models.ChannelEdgePolicy,
|
|||||||
if err := binary.Write(w, byteOrder, uint64(edge.MinHTLC)); err != nil {
|
if err := binary.Write(w, byteOrder, uint64(edge.MinHTLC)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := binary.Write(w, byteOrder, uint64(edge.FeeBaseMSat)); err != nil {
|
err = binary.Write(w, byteOrder, uint64(edge.FeeBaseMSat))
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := binary.Write(w, byteOrder, uint64(edge.FeeProportionalMillionths)); err != nil {
|
err = binary.Write(
|
||||||
|
w, byteOrder, uint64(edge.FeeProportionalMillionths),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4654,8 +4704,11 @@ func deserializeChanEdgePolicyRaw(r io.Reader) (*models.ChannelEdgePolicy,
|
|||||||
return edge, nil
|
return edge, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// MakeTestGraph creates a new instance of the ChannelGraph for testing purposes.
|
// MakeTestGraph creates a new instance of the ChannelGraph for testing
|
||||||
func MakeTestGraph(t testing.TB, modifiers ...OptionModifier) (*ChannelGraph, error) {
|
// purposes.
|
||||||
|
func MakeTestGraph(t testing.TB, modifiers ...OptionModifier) (*ChannelGraph,
|
||||||
|
error) {
|
||||||
|
|
||||||
opts := DefaultOptions()
|
opts := DefaultOptions()
|
||||||
for _, modifier := range modifiers {
|
for _, modifier := range modifiers {
|
||||||
modifier(opts)
|
modifier(opts)
|
||||||
|
|||||||
+110
-80
@@ -21,7 +21,6 @@ import (
|
|||||||
"github.com/btcsuite/btcd/btcutil"
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/davecgh/go-spew/spew"
|
|
||||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||||
"github.com/lightningnetwork/lnd/kvdb"
|
"github.com/lightningnetwork/lnd/kvdb"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
@@ -37,13 +36,15 @@ var (
|
|||||||
"[2001:db8:85a3:0:0:8a2e:370:7334]:80")
|
"[2001:db8:85a3:0:0:8a2e:370:7334]:80")
|
||||||
testAddrs = []net.Addr{testAddr, anotherAddr}
|
testAddrs = []net.Addr{testAddr, anotherAddr}
|
||||||
|
|
||||||
testRBytes, _ = hex.DecodeString("8ce2bc69281ce27da07e6683571319d18e949ddfa2965fb6caa1bf0314f882d7")
|
testRBytes, _ = hex.DecodeString("8ce2bc69281ce27da07e6683571319d18" +
|
||||||
testSBytes, _ = hex.DecodeString("299105481d63e0f4bc2a88121167221b6700d72a0ead154c03be696a292d24ae")
|
"e949ddfa2965fb6caa1bf0314f882d7")
|
||||||
testRScalar = new(btcec.ModNScalar)
|
testSBytes, _ = hex.DecodeString("299105481d63e0f4bc2a88121167221b6" +
|
||||||
testSScalar = new(btcec.ModNScalar)
|
"700d72a0ead154c03be696a292d24ae")
|
||||||
_ = testRScalar.SetByteSlice(testRBytes)
|
testRScalar = new(btcec.ModNScalar)
|
||||||
_ = testSScalar.SetByteSlice(testSBytes)
|
testSScalar = new(btcec.ModNScalar)
|
||||||
testSig = ecdsa.NewSignature(testRScalar, testSScalar)
|
_ = testRScalar.SetByteSlice(testRBytes)
|
||||||
|
_ = testSScalar.SetByteSlice(testSBytes)
|
||||||
|
testSig = ecdsa.NewSignature(testRScalar, testSScalar)
|
||||||
|
|
||||||
testFeatures = lnwire.NewFeatureVector(
|
testFeatures = lnwire.NewFeatureVector(
|
||||||
lnwire.NewRawFeatureVector(lnwire.GossipQueriesRequired),
|
lnwire.NewRawFeatureVector(lnwire.GossipQueriesRequired),
|
||||||
@@ -65,7 +66,9 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func createLightningNode(db kvdb.Backend, priv *btcec.PrivateKey) (*models.LightningNode, error) {
|
func createLightningNode(_ kvdb.Backend, priv *btcec.PrivateKey) (
|
||||||
|
*models.LightningNode, error) {
|
||||||
|
|
||||||
updateTime := prand.Int63()
|
updateTime := prand.Int63()
|
||||||
|
|
||||||
pub := priv.PubKey().SerializeCompressed()
|
pub := priv.PubKey().SerializeCompressed()
|
||||||
@@ -124,7 +127,8 @@ func TestNodeInsertionAndDeletion(t *testing.T) {
|
|||||||
dbNode, err := graph.FetchLightningNode(testPub)
|
dbNode, err := graph.FetchLightningNode(testPub)
|
||||||
require.NoError(t, err, "unable to locate node")
|
require.NoError(t, err, "unable to locate node")
|
||||||
|
|
||||||
if _, exists, err := graph.HasLightningNode(dbNode.PubKeyBytes); err != nil {
|
_, exists, err := graph.HasLightningNode(dbNode.PubKeyBytes)
|
||||||
|
if err != nil {
|
||||||
t.Fatalf("unable to query for node: %v", err)
|
t.Fatalf("unable to query for node: %v", err)
|
||||||
} else if !exists {
|
} else if !exists {
|
||||||
t.Fatalf("node should be found but wasn't")
|
t.Fatalf("node should be found but wasn't")
|
||||||
@@ -175,7 +179,8 @@ func TestPartialNode(t *testing.T) {
|
|||||||
dbNode, err := graph.FetchLightningNode(testPub)
|
dbNode, err := graph.FetchLightningNode(testPub)
|
||||||
require.NoError(t, err, "unable to locate node")
|
require.NoError(t, err, "unable to locate node")
|
||||||
|
|
||||||
if _, exists, err := graph.HasLightningNode(dbNode.PubKeyBytes); err != nil {
|
_, exists, err := graph.HasLightningNode(dbNode.PubKeyBytes)
|
||||||
|
if err != nil {
|
||||||
t.Fatalf("unable to query for node: %v", err)
|
t.Fatalf("unable to query for node: %v", err)
|
||||||
} else if !exists {
|
} else if !exists {
|
||||||
t.Fatalf("node should be found but wasn't")
|
t.Fatalf("node should be found but wasn't")
|
||||||
@@ -346,7 +351,8 @@ func TestEdgeInsertionDeletion(t *testing.T) {
|
|||||||
|
|
||||||
// Ensure that any query attempts to lookup the delete channel edge are
|
// Ensure that any query attempts to lookup the delete channel edge are
|
||||||
// properly deleted.
|
// properly deleted.
|
||||||
if _, _, _, err := graph.FetchChannelEdgesByOutpoint(&outpoint); err == nil {
|
_, _, _, err = graph.FetchChannelEdgesByOutpoint(&outpoint)
|
||||||
|
if err == nil {
|
||||||
t.Fatalf("channel edge not deleted")
|
t.Fatalf("channel edge not deleted")
|
||||||
}
|
}
|
||||||
if _, _, _, err := graph.FetchChannelEdgesByID(chanID); err == nil {
|
if _, _, _, err := graph.FetchChannelEdgesByID(chanID); err == nil {
|
||||||
@@ -528,12 +534,8 @@ func TestDisconnectBlockAtHeight(t *testing.T) {
|
|||||||
// at height 155.
|
// at height 155.
|
||||||
hash, h, err := graph.PruneTip()
|
hash, h, err := graph.PruneTip()
|
||||||
require.NoError(t, err, "unable to get prune tip")
|
require.NoError(t, err, "unable to get prune tip")
|
||||||
if !blockHash.IsEqual(hash) {
|
require.True(t, blockHash.IsEqual(hash))
|
||||||
t.Fatalf("expected best block to be %x, was %x", blockHash, hash)
|
require.Equal(t, h, height-1)
|
||||||
}
|
|
||||||
if h != height-1 {
|
|
||||||
t.Fatalf("expected best block height to be %d, was %d", height-1, h)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func assertEdgeInfoEqual(t *testing.T, e1 *models.ChannelEdgeInfo,
|
func assertEdgeInfoEqual(t *testing.T, e1 *models.ChannelEdgeInfo,
|
||||||
@@ -567,20 +569,19 @@ func assertEdgeInfoEqual(t *testing.T, e1 *models.ChannelEdgeInfo,
|
|||||||
e2.Features)
|
e2.Features)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !bytes.Equal(e1.AuthProof.NodeSig1Bytes, e2.AuthProof.NodeSig1Bytes) {
|
require.True(t, bytes.Equal(
|
||||||
t.Fatalf("nodesig1 doesn't match: %v vs %v",
|
e1.AuthProof.NodeSig1Bytes, e2.AuthProof.NodeSig1Bytes,
|
||||||
spew.Sdump(e1.AuthProof.NodeSig1Bytes),
|
))
|
||||||
spew.Sdump(e2.AuthProof.NodeSig1Bytes))
|
require.True(t, bytes.Equal(
|
||||||
}
|
e1.AuthProof.NodeSig2Bytes, e2.AuthProof.NodeSig2Bytes,
|
||||||
if !bytes.Equal(e1.AuthProof.NodeSig2Bytes, e2.AuthProof.NodeSig2Bytes) {
|
))
|
||||||
t.Fatalf("nodesig2 doesn't match")
|
require.True(t, bytes.Equal(
|
||||||
}
|
e1.AuthProof.BitcoinSig1Bytes,
|
||||||
if !bytes.Equal(e1.AuthProof.BitcoinSig1Bytes, e2.AuthProof.BitcoinSig1Bytes) {
|
e2.AuthProof.BitcoinSig1Bytes,
|
||||||
t.Fatalf("bitcoinsig1 doesn't match")
|
))
|
||||||
}
|
require.True(t, bytes.Equal(
|
||||||
if !bytes.Equal(e1.AuthProof.BitcoinSig2Bytes, e2.AuthProof.BitcoinSig2Bytes) {
|
e1.AuthProof.BitcoinSig2Bytes, e2.AuthProof.BitcoinSig2Bytes,
|
||||||
t.Fatalf("bitcoinsig2 doesn't match")
|
))
|
||||||
}
|
|
||||||
|
|
||||||
if e1.ChannelPoint != e2.ChannelPoint {
|
if e1.ChannelPoint != e2.ChannelPoint {
|
||||||
t.Fatalf("channel point match: %v vs %v", e1.ChannelPoint,
|
t.Fatalf("channel point match: %v vs %v", e1.ChannelPoint,
|
||||||
@@ -759,7 +760,9 @@ func TestEdgeInfoUpdates(t *testing.T) {
|
|||||||
|
|
||||||
// Next, attempt to query the channel edges according to the outpoint
|
// Next, attempt to query the channel edges according to the outpoint
|
||||||
// of the channel.
|
// of the channel.
|
||||||
dbEdgeInfo, dbEdge1, dbEdge2, err = graph.FetchChannelEdgesByOutpoint(&outpoint)
|
dbEdgeInfo, dbEdge1, dbEdge2, err = graph.FetchChannelEdgesByOutpoint(
|
||||||
|
&outpoint,
|
||||||
|
)
|
||||||
require.NoError(t, err, "unable to fetch channel by ID")
|
require.NoError(t, err, "unable to fetch channel by ID")
|
||||||
if err := compareEdgePolicies(dbEdge1, edge1); err != nil {
|
if err := compareEdgePolicies(dbEdge1, edge1); err != nil {
|
||||||
t.Fatalf("edge doesn't match: %v", err)
|
t.Fatalf("edge doesn't match: %v", err)
|
||||||
@@ -1089,11 +1092,13 @@ 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 *models.LightningNode) error {
|
err = graph.ForEachNode(
|
||||||
nodeMap[n.PubKeyBytes] = struct{}{}
|
func(tx kvdb.RTx, n *models.LightningNode) error {
|
||||||
|
nodeMap[n.PubKeyBytes] = struct{}{}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
},
|
||||||
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Len(t, nodeMap, numNodes)
|
require.Len(t, nodeMap, numNodes)
|
||||||
|
|
||||||
@@ -1162,8 +1167,8 @@ func TestGraphCacheTraversal(t *testing.T) {
|
|||||||
delete(chanIndex, d.ChannelID)
|
delete(chanIndex, d.ChannelID)
|
||||||
|
|
||||||
if !d.OutPolicySet || d.InPolicy == nil {
|
if !d.OutPolicySet || d.InPolicy == nil {
|
||||||
return fmt.Errorf("channel policy not " +
|
return fmt.Errorf("channel policy " +
|
||||||
"present")
|
"not present")
|
||||||
}
|
}
|
||||||
|
|
||||||
// The incoming edge should also indicate that
|
// The incoming edge should also indicate that
|
||||||
@@ -1212,10 +1217,12 @@ 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 *models.LightningNode) error {
|
err := graph.ForEachNode(
|
||||||
delete(nodeIndex, node.Alias)
|
func(_ kvdb.RTx, node *models.LightningNode) error {
|
||||||
return nil
|
delete(nodeIndex, node.Alias)
|
||||||
})
|
return nil
|
||||||
|
},
|
||||||
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Len(t, nodeIndex, 0)
|
require.Len(t, nodeIndex, 0)
|
||||||
|
|
||||||
@@ -1225,7 +1232,9 @@ func fillTestGraph(t require.TestingT, graph *ChannelGraph, numNodes,
|
|||||||
for n := 0; n < numNodes-1; n++ {
|
for n := 0; n < numNodes-1; n++ {
|
||||||
node1 := nodes[n]
|
node1 := nodes[n]
|
||||||
node2 := nodes[n+1]
|
node2 := nodes[n+1]
|
||||||
if bytes.Compare(node1.PubKeyBytes[:], node2.PubKeyBytes[:]) == -1 {
|
if bytes.Compare(
|
||||||
|
node1.PubKeyBytes[:], node2.PubKeyBytes[:],
|
||||||
|
) == -1 {
|
||||||
node1, node2 = node2, node1
|
node1, node2 = node2, node1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1279,8 +1288,8 @@ func fillTestGraph(t require.TestingT, graph *ChannelGraph, numNodes,
|
|||||||
return chanIndex, nodes
|
return chanIndex, nodes
|
||||||
}
|
}
|
||||||
|
|
||||||
func assertPruneTip(t *testing.T, graph *ChannelGraph, blockHash *chainhash.Hash,
|
func assertPruneTip(t *testing.T, graph *ChannelGraph,
|
||||||
blockHeight uint32) {
|
blockHash *chainhash.Hash, blockHeight uint32) {
|
||||||
|
|
||||||
pruneHash, pruneHeight, err := graph.PruneTip()
|
pruneHash, pruneHeight, err := graph.PruneTip()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1320,10 +1329,12 @@ 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, _ *models.LightningNode) error {
|
err := graph.ForEachNode(
|
||||||
numNodes++
|
func(_ kvdb.RTx, _ *models.LightningNode) error {
|
||||||
return nil
|
numNodes++
|
||||||
})
|
return nil
|
||||||
|
},
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_, _, line, _ := runtime.Caller(1)
|
_, _, line, _ := runtime.Caller(1)
|
||||||
t.Fatalf("line %v: unable to scan nodes: %v", line, err)
|
t.Fatalf("line %v: unable to scan nodes: %v", line, err)
|
||||||
@@ -1331,7 +1342,8 @@ func assertNumNodes(t *testing.T, graph *ChannelGraph, n int) {
|
|||||||
|
|
||||||
if numNodes != n {
|
if numNodes != n {
|
||||||
_, _, line, _ := runtime.Caller(1)
|
_, _, line, _ := runtime.Caller(1)
|
||||||
t.Fatalf("line %v: expected %v nodes, got %v", line, n, numNodes)
|
t.Fatalf("line %v: expected %v nodes, got %v", line, n,
|
||||||
|
numNodes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1355,7 +1367,9 @@ func assertChanViewEqual(t *testing.T, a []EdgePoint, b []EdgePoint) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func assertChanViewEqualChanPoints(t *testing.T, a []EdgePoint, b []*wire.OutPoint) {
|
func assertChanViewEqualChanPoints(t *testing.T, a []EdgePoint,
|
||||||
|
b []*wire.OutPoint) {
|
||||||
|
|
||||||
if len(a) != len(b) {
|
if len(a) != len(b) {
|
||||||
_, _, line, _ := runtime.Caller(1)
|
_, _, line, _ := runtime.Caller(1)
|
||||||
t.Fatalf("line %v: chan views don't match", line)
|
t.Fatalf("line %v: chan views don't match", line)
|
||||||
@@ -1434,13 +1448,17 @@ func TestGraphPruning(t *testing.T) {
|
|||||||
copy(edgeInfo.NodeKey1Bytes[:], graphNodes[i].PubKeyBytes[:])
|
copy(edgeInfo.NodeKey1Bytes[:], graphNodes[i].PubKeyBytes[:])
|
||||||
copy(edgeInfo.NodeKey2Bytes[:], graphNodes[i+1].PubKeyBytes[:])
|
copy(edgeInfo.NodeKey2Bytes[:], graphNodes[i+1].PubKeyBytes[:])
|
||||||
copy(edgeInfo.BitcoinKey1Bytes[:], graphNodes[i].PubKeyBytes[:])
|
copy(edgeInfo.BitcoinKey1Bytes[:], graphNodes[i].PubKeyBytes[:])
|
||||||
copy(edgeInfo.BitcoinKey2Bytes[:], graphNodes[i+1].PubKeyBytes[:])
|
copy(
|
||||||
|
edgeInfo.BitcoinKey2Bytes[:],
|
||||||
|
graphNodes[i+1].PubKeyBytes[:],
|
||||||
|
)
|
||||||
if err := graph.AddChannelEdge(&edgeInfo); err != nil {
|
if err := graph.AddChannelEdge(&edgeInfo); err != nil {
|
||||||
t.Fatalf("unable to add node: %v", err)
|
t.Fatalf("unable to add node: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
pkScript, err := genMultiSigP2WSH(
|
pkScript, err := genMultiSigP2WSH(
|
||||||
edgeInfo.BitcoinKey1Bytes[:], edgeInfo.BitcoinKey2Bytes[:],
|
edgeInfo.BitcoinKey1Bytes[:],
|
||||||
|
edgeInfo.BitcoinKey2Bytes[:],
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to gen multi-sig p2wsh: %v", err)
|
t.Fatalf("unable to gen multi-sig p2wsh: %v", err)
|
||||||
@@ -1772,7 +1790,9 @@ func TestChanUpdatesInHorizon(t *testing.T) {
|
|||||||
|
|
||||||
assertEdgeInfoEqual(t, chanExp.Info, chanRet.Info)
|
assertEdgeInfoEqual(t, chanExp.Info, chanRet.Info)
|
||||||
|
|
||||||
err := compareEdgePolicies(chanExp.Policy1, chanRet.Policy1)
|
err := compareEdgePolicies(
|
||||||
|
chanExp.Policy1, chanRet.Policy1,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -1879,7 +1899,9 @@ func TestNodeUpdatesInHorizon(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, queryCase := range queryCases {
|
for _, queryCase := range queryCases {
|
||||||
resp, err := graph.NodeUpdatesInHorizon(queryCase.start, queryCase.end)
|
resp, err := graph.NodeUpdatesInHorizon(
|
||||||
|
queryCase.start, queryCase.end,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to query for nodes: %v", err)
|
t.Fatalf("unable to query for nodes: %v", err)
|
||||||
}
|
}
|
||||||
@@ -2725,7 +2747,9 @@ func TestIncompleteChannelPolicies(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ensure that channel is reported with unknown policies.
|
// Ensure that channel is reported with unknown policies.
|
||||||
checkPolicies := func(node *models.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,
|
||||||
@@ -3046,9 +3070,7 @@ func TestAddChannelEdgeShellNodes(t *testing.T) {
|
|||||||
|
|
||||||
node2, err = graph.FetchLightningNode(node2.PubKeyBytes)
|
node2, err = graph.FetchLightningNode(node2.PubKeyBytes)
|
||||||
require.NoError(t, err, "unable to fetch node2")
|
require.NoError(t, err, "unable to fetch node2")
|
||||||
if node2.HaveNodeAnnouncement {
|
require.False(t, node2.HaveNodeAnnouncement)
|
||||||
t.Fatalf("should have shell announcement for node2, but is full")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestNodePruningUpdateIndexDeletion tests that once a node has been removed
|
// TestNodePruningUpdateIndexDeletion tests that once a node has been removed
|
||||||
@@ -3163,17 +3185,19 @@ 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 []*models.LightningNode, graphs []*ChannelGraph,
|
checkNodes := func(nodes []*models.LightningNode,
|
||||||
public bool) {
|
graphs []*ChannelGraph, public bool) {
|
||||||
|
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
for _, graph := range graphs {
|
for _, graph := range graphs {
|
||||||
isPublic, err := graph.IsPublicNode(node.PubKeyBytes)
|
isPublic, err := graph.IsPublicNode(
|
||||||
|
node.PubKeyBytes,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to determine if pivot "+
|
t.Fatalf("unable to determine if "+
|
||||||
"is public: %v", err)
|
"pivot is public: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
@@ -3278,8 +3302,8 @@ func TestDisabledChannelIDs(t *testing.T) {
|
|||||||
disabledChanIds, err := graph.DisabledChannelIDs()
|
disabledChanIds, err := graph.DisabledChannelIDs()
|
||||||
require.NoError(t, err, "unable to get disabled channel ids")
|
require.NoError(t, err, "unable to get disabled channel ids")
|
||||||
if len(disabledChanIds) > 0 {
|
if len(disabledChanIds) > 0 {
|
||||||
t.Fatalf("expected empty disabled channels, got %v disabled channels",
|
t.Fatalf("expected empty disabled channels, got %v disabled "+
|
||||||
len(disabledChanIds))
|
"channels", len(disabledChanIds))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add one disabled policy and ensure the channel is still not in the
|
// Add one disabled policy and ensure the channel is still not in the
|
||||||
@@ -3291,8 +3315,8 @@ func TestDisabledChannelIDs(t *testing.T) {
|
|||||||
disabledChanIds, err = graph.DisabledChannelIDs()
|
disabledChanIds, err = graph.DisabledChannelIDs()
|
||||||
require.NoError(t, err, "unable to get disabled channel ids")
|
require.NoError(t, err, "unable to get disabled channel ids")
|
||||||
if len(disabledChanIds) > 0 {
|
if len(disabledChanIds) > 0 {
|
||||||
t.Fatalf("expected empty disabled channels, got %v disabled channels",
|
t.Fatalf("expected empty disabled channels, got %v disabled "+
|
||||||
len(disabledChanIds))
|
"channels", len(disabledChanIds))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add second disabled policy and ensure the channel is now in the
|
// Add second disabled policy and ensure the channel is now in the
|
||||||
@@ -3303,12 +3327,15 @@ func TestDisabledChannelIDs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
disabledChanIds, err = graph.DisabledChannelIDs()
|
disabledChanIds, err = graph.DisabledChannelIDs()
|
||||||
require.NoError(t, err, "unable to get disabled channel ids")
|
require.NoError(t, err, "unable to get disabled channel ids")
|
||||||
if len(disabledChanIds) != 1 || disabledChanIds[0] != edgeInfo.ChannelID {
|
if len(disabledChanIds) != 1 ||
|
||||||
|
disabledChanIds[0] != edgeInfo.ChannelID {
|
||||||
|
|
||||||
t.Fatalf("expected disabled channel with id %v, "+
|
t.Fatalf("expected disabled channel with id %v, "+
|
||||||
"got %v", edgeInfo.ChannelID, disabledChanIds)
|
"got %v", edgeInfo.ChannelID, disabledChanIds)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete the channel edge and ensure it is removed from the disabled list.
|
// Delete the channel edge and ensure it is removed from the disabled
|
||||||
|
// list.
|
||||||
if err = graph.DeleteChannelEdges(
|
if err = graph.DeleteChannelEdges(
|
||||||
false, true, edgeInfo.ChannelID,
|
false, true, edgeInfo.ChannelID,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
@@ -3317,8 +3344,8 @@ func TestDisabledChannelIDs(t *testing.T) {
|
|||||||
disabledChanIds, err = graph.DisabledChannelIDs()
|
disabledChanIds, err = graph.DisabledChannelIDs()
|
||||||
require.NoError(t, err, "unable to get disabled channel ids")
|
require.NoError(t, err, "unable to get disabled channel ids")
|
||||||
if len(disabledChanIds) > 0 {
|
if len(disabledChanIds) > 0 {
|
||||||
t.Fatalf("expected empty disabled channels, got %v disabled channels",
|
t.Fatalf("expected empty disabled channels, got %v disabled "+
|
||||||
len(disabledChanIds))
|
"channels", len(disabledChanIds))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3421,7 +3448,9 @@ func TestEdgePolicyMissingMaxHtcl(t *testing.T) {
|
|||||||
copy(indexKey[:], scratch[:])
|
copy(indexKey[:], scratch[:])
|
||||||
byteOrder.PutUint64(indexKey[8:], edge1.ChannelID)
|
byteOrder.PutUint64(indexKey[8:], edge1.ChannelID)
|
||||||
|
|
||||||
updateIndex, err := edges.CreateBucketIfNotExists(edgeUpdateIndexBucket)
|
updateIndex, err := edges.CreateBucketIfNotExists(
|
||||||
|
edgeUpdateIndexBucket,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -3556,8 +3585,8 @@ func TestGraphZombieIndex(t *testing.T) {
|
|||||||
// the featuresMap have not been defined.
|
// the featuresMap have not been defined.
|
||||||
func compareNodes(a, b *models.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 "+
|
||||||
"got %v", a.LastUpdate, b.LastUpdate)
|
"%v, got %v", a.LastUpdate, b.LastUpdate)
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(a.Addresses, b.Addresses) {
|
if !reflect.DeepEqual(a.Addresses, b.Addresses) {
|
||||||
return fmt.Errorf("Addresses doesn't match: expected %#v, \n "+
|
return fmt.Errorf("Addresses doesn't match: expected %#v, \n "+
|
||||||
@@ -3576,8 +3605,9 @@ func compareNodes(a, b *models.LightningNode) error {
|
|||||||
"got %#v", a.Alias, b.Alias)
|
"got %#v", a.Alias, b.Alias)
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(a.HaveNodeAnnouncement, b.HaveNodeAnnouncement) {
|
if !reflect.DeepEqual(a.HaveNodeAnnouncement, b.HaveNodeAnnouncement) {
|
||||||
return fmt.Errorf("HaveNodeAnnouncement doesn't match: expected %#v, \n "+
|
return fmt.Errorf("HaveNodeAnnouncement doesn't match: "+
|
||||||
"got %#v", a.HaveNodeAnnouncement, b.HaveNodeAnnouncement)
|
"expected %#v, got %#v", a.HaveNodeAnnouncement,
|
||||||
|
b.HaveNodeAnnouncement)
|
||||||
}
|
}
|
||||||
if !bytes.Equal(a.ExtraOpaqueData, b.ExtraOpaqueData) {
|
if !bytes.Equal(a.ExtraOpaqueData, b.ExtraOpaqueData) {
|
||||||
return fmt.Errorf("extra data doesn't match: %v vs %v",
|
return fmt.Errorf("extra data doesn't match: %v vs %v",
|
||||||
@@ -3595,8 +3625,8 @@ func compareEdgePolicies(a, b *models.ChannelEdgePolicy) error {
|
|||||||
"got %v", a.ChannelID, b.ChannelID)
|
"got %v", a.ChannelID, b.ChannelID)
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(a.LastUpdate, b.LastUpdate) {
|
if !reflect.DeepEqual(a.LastUpdate, b.LastUpdate) {
|
||||||
return fmt.Errorf("edge LastUpdate doesn't match: expected %#v, \n "+
|
return fmt.Errorf("edge LastUpdate doesn't match: "+
|
||||||
"got %#v", a.LastUpdate, b.LastUpdate)
|
"expected %#v, got %#v", a.LastUpdate, b.LastUpdate)
|
||||||
}
|
}
|
||||||
if a.MessageFlags != b.MessageFlags {
|
if a.MessageFlags != b.MessageFlags {
|
||||||
return fmt.Errorf("MessageFlags doesn't match: expected %v, "+
|
return fmt.Errorf("MessageFlags doesn't match: expected %v, "+
|
||||||
|
|||||||
@@ -315,7 +315,7 @@ func (m *mockChainView) Reset() {
|
|||||||
m.staleBlocks = make(chan *chainview.FilteredBlock, 10)
|
m.staleBlocks = make(chan *chainview.FilteredBlock, 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockChainView) UpdateFilter(ops []graphdb.EdgePoint, updateHeight uint32) error {
|
func (m *mockChainView) UpdateFilter(ops []graphdb.EdgePoint, _ uint32) error {
|
||||||
m.Lock()
|
m.Lock()
|
||||||
defer m.Unlock()
|
defer m.Unlock()
|
||||||
|
|
||||||
|
|||||||
@@ -748,7 +748,9 @@ var stateMachineTests = []stateMachineTest{
|
|||||||
|
|
||||||
// Check that trying to enable the channel with unknown
|
// Check that trying to enable the channel with unknown
|
||||||
// edges results in a failure.
|
// edges results in a failure.
|
||||||
h.assertEnables(newChans, graphdb.ErrEdgeNotFound, false)
|
h.assertEnables(
|
||||||
|
newChans, graphdb.ErrEdgeNotFound, false,
|
||||||
|
)
|
||||||
|
|
||||||
// Now, insert edge policies for the channel into the
|
// Now, insert edge policies for the channel into the
|
||||||
// graph, starting with the channel enabled, and mark
|
// graph, starting with the channel enabled, and mark
|
||||||
|
|||||||
@@ -354,7 +354,7 @@ func parseTestGraph(t *testing.T, useCache bool, path string) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
err = graph.AddChannelEdge(&edgeInfo)
|
err = graph.AddChannelEdge(&edgeInfo)
|
||||||
if err != nil && err != graphdb.ErrEdgeAlreadyExist {
|
if err != nil && !errors.Is(err, graphdb.ErrEdgeAlreadyExist) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -662,7 +662,7 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
|
|||||||
}
|
}
|
||||||
|
|
||||||
err = graph.AddChannelEdge(&edgeInfo)
|
err = graph.AddChannelEdge(&edgeInfo)
|
||||||
if err != nil && err != graphdb.ErrEdgeAlreadyExist {
|
if err != nil && !errors.Is(err, graphdb.ErrEdgeAlreadyExist) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-3
@@ -6533,7 +6533,9 @@ 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 *models.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)
|
||||||
@@ -6563,7 +6565,7 @@ func (r *rpcServer) DescribeGraph(ctx context.Context,
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil && err != graphdb.ErrGraphNoEdgesFound {
|
if err != nil && !errors.Is(err, graphdb.ErrGraphNoEdgesFound) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6809,7 +6811,7 @@ func (r *rpcServer) GetNodeInfo(ctx context.Context,
|
|||||||
// be returned.
|
// be returned.
|
||||||
node, err := graph.FetchLightningNode(pubKey)
|
node, err := graph.FetchLightningNode(pubKey)
|
||||||
switch {
|
switch {
|
||||||
case err == graphdb.ErrGraphNodeNotFound:
|
case errors.Is(err, graphdb.ErrGraphNodeNotFound):
|
||||||
return nil, status.Error(codes.NotFound, err.Error())
|
return nil, status.Error(codes.NotFound, err.Error())
|
||||||
case err != nil:
|
case err != nil:
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -3447,7 +3447,7 @@ func (s *server) establishPersistentConnections() error {
|
|||||||
nodeAddrsMap[pubStr] = n
|
nodeAddrsMap[pubStr] = n
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil && err != graphdb.ErrGraphNoEdgesFound {
|
if err != nil && !errors.Is(err, graphdb.ErrGraphNoEdgesFound) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user