Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 41 additions & 36 deletions autopilot/prefattach_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,19 +417,21 @@ func (d *testDBGraph) addRandChannel(node1, node2 *btcec.PublicKey,
case errors.Is(err, graphdb.ErrGraphNodeNotFound):
fallthrough
case errors.Is(err, graphdb.ErrGraphNotFound):
graphNode := &models.Node{
HaveNodeAnnouncement: true,
Addresses: []net.Addr{&net.TCPAddr{
IP: bytes.Repeat(
[]byte("a"), 16,
),
}},
Features: lnwire.NewFeatureVector(
nil, lnwire.Features,
),
AuthSigBytes: testSig.Serialize(),
}
graphNode.AddPubKey(pub)
//nolint:ll
graphNode := models.NewV1Node(
route.NewVertex(pub),
&models.NodeV1Fields{
Addresses: []net.Addr{&net.TCPAddr{
IP: bytes.Repeat(
[]byte("a"), 16,
),
}},
Features: lnwire.NewFeatureVector(
nil, lnwire.Features,
).RawFeatureVector,
AuthSigBytes: testSig.Serialize(),
},
)
err := d.db.AddNode(
context.Background(), graphNode,
)
Expand All @@ -447,19 +449,18 @@ func (d *testDBGraph) addRandChannel(node1, node2 *btcec.PublicKey,
if err != nil {
return nil, err
}
dbNode := &models.Node{
HaveNodeAnnouncement: true,
Addresses: []net.Addr{
&net.TCPAddr{

dbNode := models.NewV1Node(
route.NewVertex(nodeKey), &models.NodeV1Fields{
Addresses: []net.Addr{&net.TCPAddr{
IP: bytes.Repeat([]byte("a"), 16),
},
}},
Features: lnwire.NewFeatureVector(
nil, lnwire.Features,
).RawFeatureVector,
AuthSigBytes: testSig.Serialize(),
},
Features: lnwire.NewFeatureVector(
nil, lnwire.Features,
),
AuthSigBytes: testSig.Serialize(),
}
dbNode.AddPubKey(nodeKey)
)
if err := d.db.AddNode(
context.Background(), dbNode,
); err != nil {
Expand Down Expand Up @@ -494,7 +495,11 @@ func (d *testDBGraph) addRandChannel(node1, node2 *btcec.PublicKey,
Capacity: capacity,
Features: lnwire.EmptyFeatureVector(),
}
edge.AddNodeKeys(lnNode1, lnNode2, lnNode1, lnNode2)
copy(edge.NodeKey1Bytes[:], lnNode1.SerializeCompressed())
copy(edge.NodeKey2Bytes[:], lnNode2.SerializeCompressed())
copy(edge.BitcoinKey1Bytes[:], lnNode1.SerializeCompressed())
copy(edge.BitcoinKey2Bytes[:], lnNode2.SerializeCompressed())

if err := d.db.AddChannelEdge(ctx, edge); err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -548,19 +553,19 @@ func (d *testDBGraph) addRandNode() (*btcec.PublicKey, error) {
if err != nil {
return nil, err
}
dbNode := &models.Node{
HaveNodeAnnouncement: true,
Addresses: []net.Addr{
&net.TCPAddr{
IP: bytes.Repeat([]byte("a"), 16),
dbNode := models.NewV1Node(
route.NewVertex(nodeKey), &models.NodeV1Fields{
Addresses: []net.Addr{
&net.TCPAddr{
IP: bytes.Repeat([]byte("a"), 16),
},
},
Features: lnwire.NewFeatureVector(
nil, lnwire.Features,
).RawFeatureVector,
AuthSigBytes: testSig.Serialize(),
},
Features: lnwire.NewFeatureVector(
nil, lnwire.Features,
),
AuthSigBytes: testSig.Serialize(),
}
dbNode.AddPubKey(nodeKey)
)
err = d.db.AddNode(context.Background(), dbNode)
if err != nil {
return nil, err
Expand Down
22 changes: 12 additions & 10 deletions channeldb/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/routing/route"
"github.com/lightningnetwork/lnd/shachain"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -811,16 +812,17 @@ func createNode(priv *btcec.PrivateKey) *models.Node {
updateTime := rand.Int63()

pub := priv.PubKey().SerializeCompressed()
n := &models.Node{
HaveNodeAnnouncement: true,
AuthSigBytes: testSig.Serialize(),
LastUpdate: time.Unix(updateTime, 0),
Color: color.RGBA{1, 2, 3, 0},
Alias: "kek" + string(pub),
Features: testFeatures,
Addresses: testAddrs,
}
copy(n.PubKeyBytes[:], priv.PubKey().SerializeCompressed())
n := models.NewV1Node(
route.NewVertex(priv.PubKey()),
&models.NodeV1Fields{
AuthSigBytes: testSig.Serialize(),
LastUpdate: time.Unix(updateTime, 0),
Color: color.RGBA{1, 2, 3, 0},
Alias: "kek" + string(pub),
Features: testFeatures.RawFeatureVector,
Addresses: testAddrs,
},
)

return n
}
Expand Down
4 changes: 2 additions & 2 deletions discovery/chan_series.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func (c *ChanSeries) FetchChanAnns(chain chainhash.Hash,
// If this edge has a validated node announcement, that
// we haven't yet sent, then we'll send that as well.
nodePub := channel.Node2.PubKeyBytes
hasNodeAnn := channel.Node2.HaveNodeAnnouncement
hasNodeAnn := channel.Node2.HaveAnnouncement()
if _, ok := nodePubsSent[nodePub]; !ok && hasNodeAnn {
nodeAnn, err := channel.Node2.NodeAnnouncement(
true,
Expand All @@ -321,7 +321,7 @@ func (c *ChanSeries) FetchChanAnns(chain chainhash.Hash,
// If this edge has a validated node announcement, that
// we haven't yet sent, then we'll send that as well.
nodePub := channel.Node1.PubKeyBytes
hasNodeAnn := channel.Node1.HaveNodeAnnouncement
hasNodeAnn := channel.Node1.HaveAnnouncement()
if _, ok := nodePubsSent[nodePub]; !ok && hasNodeAnn {
nodeAnn, err := channel.Node1.NodeAnnouncement(
true,
Expand Down
2 changes: 1 addition & 1 deletion graph/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type Config struct {

// Graph is the channel graph that the ChannelRouter will use to gather
// metrics from and also to carry out path finding queries.
Graph DB
Graph *graphdb.ChannelGraph

// Chain is the router's source to the most up-to-date blockchain data.
// All incoming advertised channels will be checked against the chain
Expand Down
78 changes: 39 additions & 39 deletions graph/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,16 @@ func TestIgnoreNodeAnnouncement(t *testing.T) {
ctx := createTestCtxFromFile(t, startingBlockHeight, basicGraphFilePath)

pub := priv1.PubKey()
node := &models.Node{
HaveNodeAnnouncement: true,
LastUpdate: time.Unix(123, 0),
Addresses: testAddrs,
Color: color.RGBA{1, 2, 3, 0},
Alias: "node11",
AuthSigBytes: testSig.Serialize(),
Features: testFeatures,
}
copy(node.PubKeyBytes[:], pub.SerializeCompressed())
node := models.NewV1Node(
route.NewVertex(pub), &models.NodeV1Fields{
Addresses: testAddrs,
AuthSigBytes: testSig.Serialize(),
Features: testFeatures.RawFeatureVector,
LastUpdate: time.Unix(123, 0),
Color: color.RGBA{1, 2, 3, 0},
Alias: "node11",
},
)

err := ctx.builder.AddNode(t.Context(), node)
if !IsError(err, ErrIgnored) {
Expand Down Expand Up @@ -1084,16 +1084,16 @@ func TestIsStaleNode(t *testing.T) {

// With the node stub in the database, we'll add the fully node
// announcement to the database.
n1 := &models.Node{
HaveNodeAnnouncement: true,
LastUpdate: updateTimeStamp,
Addresses: testAddrs,
Color: color.RGBA{1, 2, 3, 0},
Alias: "node11",
AuthSigBytes: testSig.Serialize(),
Features: testFeatures,
}
copy(n1.PubKeyBytes[:], priv1.PubKey().SerializeCompressed())
n1 := models.NewV1Node(
route.NewVertex(priv1.PubKey()), &models.NodeV1Fields{
LastUpdate: updateTimeStamp,
Addresses: testAddrs,
Color: color.RGBA{1, 2, 3, 0},
Alias: "node11",
AuthSigBytes: testSig.Serialize(),
Features: testFeatures.RawFeatureVector,
},
)
if err := ctx.builder.AddNode(t.Context(), n1); err != nil {
t.Fatalf("could not add node: %v", err)
}
Expand Down Expand Up @@ -1401,15 +1401,16 @@ func parseTestGraph(t *testing.T, useCache bool, path string) (
return nil, err
}

dbNode := &models.Node{
HaveNodeAnnouncement: true,
AuthSigBytes: testSig.Serialize(),
LastUpdate: testTime,
Addresses: testAddrs,
Alias: node.Alias,
Features: testFeatures,
}
copy(dbNode.PubKeyBytes[:], pubBytes)
pubKey, err := route.NewVertexFromBytes(pubBytes)
require.NoError(t, err)

dbNode := models.NewV1Node(pubKey, &models.NodeV1Fields{
AuthSigBytes: testSig.Serialize(),
LastUpdate: testTime,
Addresses: testAddrs,
Alias: node.Alias,
Features: testFeatures.RawFeatureVector,
})

// We require all aliases within the graph to be unique for our
// tests.
Expand Down Expand Up @@ -1787,16 +1788,15 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
features = lnwire.EmptyFeatureVector()
}

dbNode := &models.Node{
HaveNodeAnnouncement: true,
AuthSigBytes: testSig.Serialize(),
LastUpdate: testTime,
Addresses: testAddrs,
Alias: alias,
Features: features,
}

copy(dbNode.PubKeyBytes[:], pubKey.SerializeCompressed())
dbNode := models.NewV1Node(
route.NewVertex(pubKey), &models.NodeV1Fields{
AuthSigBytes: testSig.Serialize(),
LastUpdate: testTime,
Addresses: testAddrs,
Alias: alias,
Features: features.RawFeatureVector,
},
)

privKeyMap[alias] = privKey

Expand Down
4 changes: 0 additions & 4 deletions graph/db/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ import (
var ErrChanGraphShuttingDown = fmt.Errorf("ChannelGraph shutting down")

// ChannelGraph is a layer above the graph's CRUD layer.
//
// NOTE: currently, this is purely a pass-through layer directly to the backing
// KVStore. Upcoming commits will move the graph cache out of the KVStore and
// into this layer so that the KVStore is only responsible for CRUD operations.
type ChannelGraph struct {
started atomic.Bool
stopped atomic.Bool
Expand Down
Loading
Loading