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
55 changes: 31 additions & 24 deletions autopilot/prefattach_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,19 +417,22 @@ 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)
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 @@ -447,19 +450,19 @@ func (d *testDBGraph) addRandChannel(node1, node2 *btcec.PublicKey,
if err != nil {
return nil, err
}
dbNode := &models.Node{
HaveNodeAnnouncement: true,
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(),
}
dbNode.AddPubKey(nodeKey)
})
if err := d.db.AddNode(
context.Background(), dbNode,
); err != nil {
Expand Down Expand Up @@ -494,7 +497,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 +555,19 @@ func (d *testDBGraph) addRandNode() (*btcec.PublicKey, error) {
if err != nil {
return nil, err
}
dbNode := &models.Node{
HaveNodeAnnouncement: true,
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(),
}
dbNode.AddPubKey(nodeKey)
})
err = d.db.AddNode(context.Background(), dbNode)
if err != nil {
return nil, err
Expand Down
20 changes: 10 additions & 10 deletions channeldb/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,16 +811,16 @@ 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())
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.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
79 changes: 40 additions & 39 deletions graph/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,18 @@ 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())
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 @@ -1084,16 +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{
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())
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.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 +1403,15 @@ 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)
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.RawFeatureVector,
})

// We require all aliases within the graph to be unique for our
// tests.
Expand Down Expand Up @@ -1787,16 +1789,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())
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.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