Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
47 changes: 25 additions & 22 deletions autopilot/prefattach_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,20 +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{
Addresses: []net.Addr{&net.TCPAddr{
IP: bytes.Repeat(
[]byte("a"), 16,
),
}},
Features: lnwire.NewFeatureVector(
nil, lnwire.Features,
),
AuthSigBytes: testSig.Serialize(),
}
copy(
graphNode.PubKeyBytes[:],
pub.SerializeCompressed(),
var pubKey [33]byte
copy(pubKey[:], pub.SerializeCompressed())
Comment on lines +420 to +421
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like a route.NewMustVertexFromBytes without error check could be useful

//nolint:ll
graphNode := models.NewV1Node(
pubKey, &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 @@ -449,18 +450,19 @@ func (d *testDBGraph) addRandChannel(node1, node2 *btcec.PublicKey,
if err != nil {
return nil, err
}
dbNode := &models.Node{
var pubKey [33]byte
copy(pubKey[:], nodeKey.SerializeCompressed())
dbNode := models.NewV1Node(pubKey, &models.NodeV1Fields{
Addresses: []net.Addr{
&net.TCPAddr{
IP: bytes.Repeat([]byte("a"), 16),
},
},
Features: lnwire.NewFeatureVector(
nil, lnwire.Features,
),
).RawFeatureVector,
AuthSigBytes: testSig.Serialize(),
}
copy(dbNode.PubKeyBytes[:], nodeKey.SerializeCompressed())
})
if err := d.db.AddNode(
context.Background(), dbNode,
); err != nil {
Expand Down Expand Up @@ -549,18 +551,19 @@ func (d *testDBGraph) addRandNode() (*btcec.PublicKey, error) {
if err != nil {
return nil, err
}
dbNode := &models.Node{
var pubKey [33]byte
copy(pubKey[:], nodeKey.SerializeCompressed())
dbNode := models.NewV1Node(pubKey, &models.NodeV1Fields{
Addresses: []net.Addr{
&net.TCPAddr{
IP: bytes.Repeat([]byte("a"), 16),
},
},
Features: lnwire.NewFeatureVector(
nil, lnwire.Features,
),
).RawFeatureVector,
AuthSigBytes: testSig.Serialize(),
}
copy(dbNode.PubKeyBytes[:], nodeKey.SerializeCompressed())
})
err = d.db.AddNode(context.Background(), dbNode)
if err != nil {
return nil, err
Expand Down
9 changes: 5 additions & 4 deletions channeldb/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,15 +811,16 @@ func createNode(priv *btcec.PrivateKey) *models.Node {
updateTime := rand.Int63()

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

return n
}
Expand Down
49 changes: 27 additions & 22 deletions graph/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,18 @@ func TestIgnoreNodeAnnouncement(t *testing.T) {
ctx := createTestCtxFromFile(t, startingBlockHeight, basicGraphFilePath)

pub := priv1.PubKey()
node := &models.Node{
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())
var pubBytes route.Vertex
copy(pubBytes[:], pub.SerializeCompressed())
node := models.NewV1Node(
pubBytes, &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 @@ -1083,15 +1086,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{
var pubKey [33]byte
copy(pubKey[:], priv1.PubKey().SerializeCompressed())
n1 := models.NewV1Node(pubKey, &models.NodeV1Fields{
LastUpdate: updateTimeStamp,
Addresses: testAddrs,
Color: color.RGBA{1, 2, 3, 0},
Alias: "node11",
AuthSigBytes: testSig.Serialize(),
Features: testFeatures,
}
copy(n1.PubKeyBytes[:], priv1.PubKey().SerializeCompressed())
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 @@ -1399,14 +1403,15 @@ func parseTestGraph(t *testing.T, useCache bool, path string) (
return nil, err
}

dbNode := &models.Node{
var pubKey [33]byte
copy(pubKey[:], pubBytes)
dbNode := models.NewV1Node(pubKey, &models.NodeV1Fields{
AuthSigBytes: testSig.Serialize(),
LastUpdate: testTime,
Addresses: testAddrs,
Alias: node.Alias,
Features: testFeatures,
}
copy(dbNode.PubKeyBytes[:], pubBytes)
Features: testFeatures.RawFeatureVector,
})

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

dbNode := &models.Node{
var pubKeyBytes [33]byte
copy(pubKeyBytes[:], pubKey.SerializeCompressed())
dbNode := models.NewV1Node(pubKeyBytes, &models.NodeV1Fields{
AuthSigBytes: testSig.Serialize(),
LastUpdate: testTime,
Addresses: testAddrs,
Alias: alias,
Features: features,
}

copy(dbNode.PubKeyBytes[:], pubKey.SerializeCompressed())
Features: features.RawFeatureVector,
})

privKeyMap[alias] = privKey

Expand Down
70 changes: 32 additions & 38 deletions graph/db/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,18 @@ var (
)

func createNode(priv *btcec.PrivateKey) *models.Node {
pub := priv.PubKey().SerializeCompressed()
n := &models.Node{
AuthSigBytes: testSig.Serialize(),
LastUpdate: nextUpdateTime(),
Color: color.RGBA{1, 2, 3, 0},
Alias: "kek" + hex.EncodeToString(pub),
Features: testFeatures,
Addresses: testAddrs,
}
copy(n.PubKeyBytes[:], priv.PubKey().SerializeCompressed())

return n
var pubKey [33]byte
copy(pubKey[:], priv.PubKey().SerializeCompressed())
return models.NewV1Node(
pubKey, &models.NodeV1Fields{
LastUpdate: nextUpdateTime(),
Color: color.RGBA{1, 2, 3, 0},
Alias: "kek" + hex.EncodeToString(pubKey[:]),
Addresses: testAddrs,
Features: testFeatures.RawFeatureVector,
AuthSigBytes: testSig.Serialize(),
},
)
}

func createTestVertex(t testing.TB) *models.Node {
Expand All @@ -105,16 +105,18 @@ func TestNodeInsertionAndDeletion(t *testing.T) {
timeStamp := int64(1232342)
nodeWithAddrs := func(addrs []net.Addr) *models.Node {
timeStamp++
return &models.Node{
AuthSigBytes: testSig.Serialize(),
LastUpdate: time.Unix(timeStamp, 0),
Color: color.RGBA{1, 2, 3, 0},
Alias: "kek",
Features: testFeatures,
Addresses: addrs,
ExtraOpaqueData: []byte{1, 1, 1, 2, 2, 2, 2},
PubKeyBytes: testPub,
}

return models.NewV1Node(
testPub, &models.NodeV1Fields{
AuthSigBytes: testSig.Serialize(),
LastUpdate: time.Unix(timeStamp, 0),
Color: color.RGBA{1, 2, 3, 0},
Alias: "kek",
Features: testFeatures.RawFeatureVector,
Addresses: addrs,
ExtraOpaqueData: []byte{1, 1, 1, 2, 2, 2, 2},
},
)
}

// First, insert the node into the graph DB. This should succeed
Expand Down Expand Up @@ -313,11 +315,7 @@ func TestPartialNode(t *testing.T) {

// The two nodes should match exactly! (with default values for
// LastUpdate and db set to satisfy compareNodes())
expectedNode1 := &models.Node{
LastUpdate: time.Unix(0, 0),
PubKeyBytes: pubKey1,
Features: lnwire.EmptyFeatureVector(),
}
expectedNode1 := models.NewV1ShellNode(pubKey1)
compareNodes(t, expectedNode1, dbNode1)

_, exists, err = graph.HasNode(ctx, dbNode2.PubKeyBytes)
Expand All @@ -326,11 +324,7 @@ func TestPartialNode(t *testing.T) {

// The two nodes should match exactly! (with default values for
// LastUpdate and db set to satisfy compareNodes())
expectedNode2 := &models.Node{
LastUpdate: time.Unix(0, 0),
PubKeyBytes: pubKey2,
Features: lnwire.EmptyFeatureVector(),
}
expectedNode2 := models.NewV1ShellNode(pubKey2)
compareNodes(t, expectedNode2, dbNode2)

// Next, delete the node from the graph, this should purge all data
Expand Down Expand Up @@ -365,7 +359,7 @@ func TestAliasLookup(t *testing.T) {
require.NoError(t, err, "unable to generate pubkey")
dbAlias, err := graph.LookupAlias(ctx, nodePub)
require.NoError(t, err, "unable to find alias")
require.Equal(t, testNode.Alias, dbAlias)
require.Equal(t, testNode.Alias.UnwrapOr(""), dbAlias)

// Ensure that looking up a non-existent alias results in an error.
node := createTestVertex(t)
Expand Down Expand Up @@ -1600,7 +1594,7 @@ func fillTestGraph(t testing.TB, graph *ChannelGraph, numNodes,
node := createTestVertex(t)

nodes[i] = node
nodeIndex[node.Alias] = struct{}{}
nodeIndex[node.Alias.UnwrapOr("")] = struct{}{}
}

// Add each of the nodes into the graph, they should be inserted
Expand All @@ -1612,7 +1606,7 @@ func fillTestGraph(t testing.TB, graph *ChannelGraph, numNodes,
// Iterate over each node as returned by the graph, if all nodes are
// reached, then the map created above should be empty.
err := graph.ForEachNode(ctx, func(n *models.Node) error {
delete(nodeIndex, n.Alias)
delete(nodeIndex, n.Alias.UnwrapOr(""))
return nil
}, func() {})
require.NoError(t, err)
Expand Down Expand Up @@ -2289,7 +2283,7 @@ func TestNodeUpdatesInHorizon(t *testing.T) {
require.Len(t, resp, len(queryCase.resp))

for i := 0; i < len(resp); i++ {
compareNodes(t, &queryCase.resp[i], &resp[i])
compareNodes(t, &queryCase.resp[i], resp[i])
}
}
}
Expand Down Expand Up @@ -2487,7 +2481,7 @@ func TestNodeUpdatesInHorizonEarlyTermination(t *testing.T) {
)

// Collect only up to stopAt nodes, breaking afterwards.
var collected []models.Node
var collected []*models.Node
count := 0
for node := range iter {
if count >= stopAt {
Expand Down Expand Up @@ -3824,7 +3818,7 @@ func TestNodePruningUpdateIndexDeletion(t *testing.T) {
t.Fatalf("should have 1 nodes instead have: %v",
len(nodesInHorizon))
}
compareNodes(t, node1, &nodesInHorizon[0])
compareNodes(t, node1, nodesInHorizon[0])

// We'll now delete the node from the graph, this should result in it
// being removed from the update index as well.
Expand Down
2 changes: 1 addition & 1 deletion graph/db/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ type V1Store interface { //nolint:interfacebloat
// by two nodes to quickly determine if they have the same set of up to
// date node announcements.
NodeUpdatesInHorizon(startTime, endTime time.Time,
opts ...IteratorOption) iter.Seq2[models.Node, error]
opts ...IteratorOption) iter.Seq2[*models.Node, error]

// FetchNode attempts to look up a target node by its identity
// public key. If the node isn't found in the database, then
Expand Down
Loading