multi: remove LightningNode from ChannelEdgePolicy

Finally, The LightningNode object is removed from ChannelEdgePolicy.
This is a step towards letting ChannelEdgePolicy reflect exactly the
schema that is on disk.

This is also nice because the `Node` object is not necessarily always
required when the ChannelEdgePolicy is loaded from the DB, so now it
only get's loaded when needed.
This commit is contained in:
Elle Mouton committed 2023-11-08 14:50:34 +02:00
1 parent 6c76d31e89
commit 3a17479ff4
9 files changed
+114 -130

No files matched your search

+6 -1
View File
@@ -104,6 +104,11 @@ func (d *dbNode) ForEachChannel(cb func(ChannelEdge) error) error {
return nil return nil
} }
node, err := d.db.FetchLightningNode(tx, ep.ToNode)
if err != nil {
return err
}
edge := ChannelEdge{ edge := ChannelEdge{
ChanID: lnwire.NewShortChanIDFromInt( ChanID: lnwire.NewShortChanIDFromInt(
ep.ChannelID, ep.ChannelID,
@@ -112,7 +117,7 @@ func (d *dbNode) ForEachChannel(cb func(ChannelEdge) error) error {
Peer: &dbNode{ Peer: &dbNode{
tx: tx, tx: tx,
db: d.db, db: d.db,
node: ep.Node, node: node,
}, },
} }
+50 -28
View File
@@ -1858,6 +1858,14 @@ type ChannelEdge struct {
// Policy2 points to the "second" edge policy of the channel containing // Policy2 points to the "second" edge policy of the channel containing
// the dynamic information required to properly route through the edge. // the dynamic information required to properly route through the edge.
Policy2 *ChannelEdgePolicy Policy2 *ChannelEdgePolicy
// Node1 is "node 1" in the channel. This is the node that would have
// produced Policy1 if it exists.
Node1 *LightningNode
// Node2 is "node 2" in the channel. This is the node that would have
// produced Policy2 if it exists.
Node2 *LightningNode
} }
// ChanUpdatesInHorizon returns all the known channel edges which have at least // ChanUpdatesInHorizon returns all the known channel edges which have at least
@@ -1952,6 +1960,20 @@ func (c *ChannelGraph) ChanUpdatesInHorizon(startTime,
err) err)
} }
node1, err := fetchLightningNode(
nodes, edgeInfo.NodeKey1Bytes[:],
)
if err != nil {
return err
}
node2, err := fetchLightningNode(
nodes, edgeInfo.NodeKey2Bytes[:],
)
if err != nil {
return err
}
// Finally, we'll collate this edge with the rest of // Finally, we'll collate this edge with the rest of
// edges to be returned. // edges to be returned.
edgesSeen[chanIDInt] = struct{}{} edgesSeen[chanIDInt] = struct{}{}
@@ -1959,6 +1981,8 @@ func (c *ChannelGraph) ChanUpdatesInHorizon(startTime,
Info: &edgeInfo, Info: &edgeInfo,
Policy1: edge1, Policy1: edge1,
Policy2: edge2, Policy2: edge2,
Node1: &node1,
Node2: &node2,
} }
edgesInHorizon = append(edgesInHorizon, channel) edgesInHorizon = append(edgesInHorizon, channel)
edgesToCache[chanIDInt] = channel edgesToCache[chanIDInt] = channel
@@ -2279,10 +2303,26 @@ func (c *ChannelGraph) FetchChanInfos(chanIDs []uint64) ([]ChannelEdge, error) {
return err return err
} }
node1, err := fetchLightningNode(
nodes, edgeInfo.NodeKey1Bytes[:],
)
if err != nil {
return err
}
node2, err := fetchLightningNode(
nodes, edgeInfo.NodeKey2Bytes[:],
)
if err != nil {
return err
}
chanEdges = append(chanEdges, ChannelEdge{ chanEdges = append(chanEdges, ChannelEdge{
Info: &edgeInfo, Info: &edgeInfo,
Policy1: edge1, Policy1: edge1,
Policy2: edge2, Policy2: edge2,
Node1: &node1,
Node2: &node2,
}) })
} }
return nil return nil
@@ -2558,10 +2598,6 @@ func updateEdgePolicy(tx kvdb.RwTx, edge *ChannelEdgePolicy,
if edgeIndex == nil { if edgeIndex == nil {
return false, ErrEdgeNotFound return false, ErrEdgeNotFound
} }
nodes, err := tx.CreateTopLevelBucket(nodeBucket)
if err != nil {
return false, err
}
// Create the channelID key be converting the channel ID // Create the channelID key be converting the channel ID
// integer into a byte slice. // integer into a byte slice.
@@ -2591,7 +2627,7 @@ func updateEdgePolicy(tx kvdb.RwTx, edge *ChannelEdgePolicy,
// Finally, with the direction of the edge being updated // Finally, with the direction of the edge being updated
// identified, we update the on-disk edge representation. // identified, we update the on-disk edge representation.
err = putChanEdgePolicy(edges, nodes, edge, fromNode, toNode) err := putChanEdgePolicy(edges, edge, fromNode, toNode)
if err != nil { if err != nil {
return false, err return false, err
} }
@@ -3441,9 +3477,9 @@ type ChannelEdgePolicy struct {
// HTLCs for each millionth of a satoshi forwarded. // HTLCs for each millionth of a satoshi forwarded.
FeeProportionalMillionths lnwire.MilliSatoshi FeeProportionalMillionths lnwire.MilliSatoshi
// Node is the LightningNode that this directed edge leads to. Using // ToNode is the public key of the node that this directed edge leads
// this pointer the channel graph can further be traversed. // to. Using this pub key, the channel graph can further be traversed.
Node *LightningNode ToNode [33]byte
// ExtraOpaqueData is the set of data that was appended to this // ExtraOpaqueData is the set of data that was appended to this
// message, some of which we may not actually know how to iterate or // message, some of which we may not actually know how to iterate or
@@ -4460,8 +4496,8 @@ func deserializeChanEdgeInfo(r io.Reader) (ChannelEdgeInfo, error) {
return edgeInfo, nil return edgeInfo, nil
} }
func putChanEdgePolicy(edges, nodes kvdb.RwBucket, edge *ChannelEdgePolicy, func putChanEdgePolicy(edges kvdb.RwBucket, edge *ChannelEdgePolicy, from,
from, to []byte) error { to []byte) error {
var edgeKey [33 + 8]byte var edgeKey [33 + 8]byte
copy(edgeKey[:], from) copy(edgeKey[:], from)
@@ -4501,7 +4537,7 @@ func putChanEdgePolicy(edges, nodes kvdb.RwBucket, edge *ChannelEdgePolicy,
// TODO(halseth): get rid of these invalid policies in a // TODO(halseth): get rid of these invalid policies in a
// migration. // migration.
oldEdgePolicy, err := deserializeChanEdgePolicy( oldEdgePolicy, err := deserializeChanEdgePolicy(
bytes.NewReader(edgeBytes), nodes, bytes.NewReader(edgeBytes),
) )
if err != nil && err != ErrEdgePolicyOptionalFieldNotFound { if err != nil && err != ErrEdgePolicyOptionalFieldNotFound {
return err return err
@@ -4599,7 +4635,7 @@ func fetchChanEdgePolicy(edges kvdb.RBucket, chanID []byte,
edgeReader := bytes.NewReader(edgeBytes) edgeReader := bytes.NewReader(edgeBytes)
ep, err := deserializeChanEdgePolicy(edgeReader, nodes) ep, err := deserializeChanEdgePolicy(edgeReader)
switch { switch {
// If the db policy was missing an expected optional field, we return // If the db policy was missing an expected optional field, we return
// nil as if the policy was unknown. // nil as if the policy was unknown.
@@ -4709,9 +4745,7 @@ func serializeChanEdgePolicy(w io.Writer, edge *ChannelEdgePolicy,
return nil return nil
} }
func deserializeChanEdgePolicy(r io.Reader, func deserializeChanEdgePolicy(r io.Reader) (*ChannelEdgePolicy, error) {
nodes kvdb.RBucket) (*ChannelEdgePolicy, error) {
// Deserialize the policy. Note that in case an optional field is not // Deserialize the policy. Note that in case an optional field is not
// found, both an error and a populated policy object are returned. // found, both an error and a populated policy object are returned.
edge, deserializeErr := deserializeChanEdgePolicyRaw(r) edge, deserializeErr := deserializeChanEdgePolicyRaw(r)
@@ -4721,14 +4755,6 @@ func deserializeChanEdgePolicy(r io.Reader,
return nil, deserializeErr return nil, deserializeErr
} }
// Populate full LightningNode struct.
pub := edge.Node.PubKeyBytes[:]
node, err := fetchLightningNode(nodes, pub)
if err != nil {
return nil, fmt.Errorf("unable to fetch node: %x, %v", pub, err)
}
edge.Node = &node
return edge, deserializeErr return edge, deserializeErr
} }
@@ -4778,13 +4804,9 @@ func deserializeChanEdgePolicyRaw(r io.Reader) (*ChannelEdgePolicy, error) {
} }
edge.FeeProportionalMillionths = lnwire.MilliSatoshi(n) edge.FeeProportionalMillionths = lnwire.MilliSatoshi(n)
var pub [33]byte if _, err := r.Read(edge.ToNode[:]); err != nil {
if _, err := r.Read(pub[:]); err != nil {
return nil, err return nil, err
} }
edge.Node = &LightningNode{
PubKeyBytes: pub,
}
// 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
// we'll ignore the EOF error and return the edge as is. // we'll ignore the EOF error and return the edge as is.
+2 -2
View File
@@ -271,7 +271,7 @@ func (c *GraphCache) AddChannel(info *ChannelEdgeInfo,
// of node 2 then we have the policy 1 as seen from node 1. // of node 2 then we have the policy 1 as seen from node 1.
if policy1 != nil { if policy1 != nil {
fromNode, toNode := info.NodeKey1Bytes, info.NodeKey2Bytes fromNode, toNode := info.NodeKey1Bytes, info.NodeKey2Bytes
if policy1.Node.PubKeyBytes != info.NodeKey2Bytes { if policy1.ToNode != info.NodeKey2Bytes {
fromNode, toNode = toNode, fromNode fromNode, toNode = toNode, fromNode
} }
isEdge1 := policy1.ChannelFlags&lnwire.ChanUpdateDirection == 0 isEdge1 := policy1.ChannelFlags&lnwire.ChanUpdateDirection == 0
@@ -279,7 +279,7 @@ func (c *GraphCache) AddChannel(info *ChannelEdgeInfo,
} }
if policy2 != nil { if policy2 != nil {
fromNode, toNode := info.NodeKey2Bytes, info.NodeKey1Bytes fromNode, toNode := info.NodeKey2Bytes, info.NodeKey1Bytes
if policy2.Node.PubKeyBytes != info.NodeKey1Bytes { if policy2.ToNode != info.NodeKey1Bytes {
fromNode, toNode = toNode, fromNode fromNode, toNode = toNode, fromNode
} }
isEdge1 := policy2.ChannelFlags&lnwire.ChanUpdateDirection == 0 isEdge1 := policy2.ChannelFlags&lnwire.ChanUpdateDirection == 0
+3 -12
View File
@@ -73,18 +73,12 @@ func TestGraphCacheAddNode(t *testing.T) {
outPolicy1 := &ChannelEdgePolicy{ outPolicy1 := &ChannelEdgePolicy{
ChannelID: 1000, ChannelID: 1000,
ChannelFlags: lnwire.ChanUpdateChanFlags(channelFlagA), ChannelFlags: lnwire.ChanUpdateChanFlags(channelFlagA),
Node: &LightningNode{ ToNode: nodeB,
PubKeyBytes: nodeB,
Features: lnwire.EmptyFeatureVector(),
},
} }
inPolicy1 := &ChannelEdgePolicy{ inPolicy1 := &ChannelEdgePolicy{
ChannelID: 1000, ChannelID: 1000,
ChannelFlags: lnwire.ChanUpdateChanFlags(channelFlagB), ChannelFlags: lnwire.ChanUpdateChanFlags(channelFlagB),
Node: &LightningNode{ ToNode: nodeA,
PubKeyBytes: nodeA,
Features: lnwire.EmptyFeatureVector(),
},
} }
node := &node{ node := &node{
pubKey: nodeA, pubKey: nodeA,
@@ -159,9 +153,6 @@ func assertCachedPolicyEqual(t *testing.T, original *ChannelEdgePolicy,
cached.FeeProportionalMillionths, cached.FeeProportionalMillionths,
) )
require.Equal( require.Equal(
t, t, route.Vertex(original.ToNode), cached.ToNodePubKey(),
route.Vertex(original.Node.PubKeyBytes),
cached.ToNodePubKey(),
) )
require.Equal(t, original.Node.Features, cached.ToNodeFeatures)
} }
+35 -34
View File
@@ -619,15 +619,15 @@ func createChannelEdge(db kvdb.Backend, node1, node2 *LightningNode) (*ChannelEd
*ChannelEdgePolicy, *ChannelEdgePolicy) { *ChannelEdgePolicy, *ChannelEdgePolicy) {
var ( var (
firstNode *LightningNode firstNode [33]byte
secondNode *LightningNode secondNode [33]byte
) )
if bytes.Compare(node1.PubKeyBytes[:], node2.PubKeyBytes[:]) == -1 { if bytes.Compare(node1.PubKeyBytes[:], node2.PubKeyBytes[:]) == -1 {
firstNode = node1 firstNode = node1.PubKeyBytes
secondNode = node2 secondNode = node2.PubKeyBytes
} else { } else {
firstNode = node2 firstNode = node2.PubKeyBytes
secondNode = node1 secondNode = node1.PubKeyBytes
} }
// In addition to the fake vertexes we create some fake channel // In addition to the fake vertexes we create some fake channel
@@ -653,10 +653,10 @@ func createChannelEdge(db kvdb.Backend, node1, node2 *LightningNode) (*ChannelEd
Capacity: 1000, Capacity: 1000,
ExtraOpaqueData: []byte("new unknown feature"), ExtraOpaqueData: []byte("new unknown feature"),
} }
copy(edgeInfo.NodeKey1Bytes[:], firstNode.PubKeyBytes[:]) copy(edgeInfo.NodeKey1Bytes[:], firstNode[:])
copy(edgeInfo.NodeKey2Bytes[:], secondNode.PubKeyBytes[:]) copy(edgeInfo.NodeKey2Bytes[:], secondNode[:])
copy(edgeInfo.BitcoinKey1Bytes[:], firstNode.PubKeyBytes[:]) copy(edgeInfo.BitcoinKey1Bytes[:], firstNode[:])
copy(edgeInfo.BitcoinKey2Bytes[:], secondNode.PubKeyBytes[:]) copy(edgeInfo.BitcoinKey2Bytes[:], secondNode[:])
edge1 := &ChannelEdgePolicy{ edge1 := &ChannelEdgePolicy{
SigBytes: testSig.Serialize(), SigBytes: testSig.Serialize(),
@@ -669,7 +669,7 @@ func createChannelEdge(db kvdb.Backend, node1, node2 *LightningNode) (*ChannelEd
MaxHTLC: 13928598, MaxHTLC: 13928598,
FeeBaseMSat: 4352345, FeeBaseMSat: 4352345,
FeeProportionalMillionths: 3452352, FeeProportionalMillionths: 3452352,
Node: secondNode, ToNode: secondNode,
ExtraOpaqueData: []byte("new unknown feature2"), ExtraOpaqueData: []byte("new unknown feature2"),
} }
edge2 := &ChannelEdgePolicy{ edge2 := &ChannelEdgePolicy{
@@ -683,7 +683,7 @@ func createChannelEdge(db kvdb.Backend, node1, node2 *LightningNode) (*ChannelEd
MaxHTLC: 13928598, MaxHTLC: 13928598,
FeeBaseMSat: 4352345, FeeBaseMSat: 4352345,
FeeProportionalMillionths: 90392423, FeeProportionalMillionths: 90392423,
Node: firstNode, ToNode: firstNode,
ExtraOpaqueData: []byte("new unknown feature1"), ExtraOpaqueData: []byte("new unknown feature1"),
} }
@@ -1063,8 +1063,7 @@ func TestGraphTraversal(t *testing.T) {
// Each should indicate that it's outgoing (pointed // Each should indicate that it's outgoing (pointed
// towards the second node). // towards the second node).
if !bytes.Equal( if !bytes.Equal(
outEdge.Node.PubKeyBytes[:], outEdge.ToNode[:], secondNode.PubKeyBytes[:],
secondNode.PubKeyBytes[:],
) { ) {
return fmt.Errorf("wrong outgoing edge") return fmt.Errorf("wrong outgoing edge")
@@ -1073,14 +1072,14 @@ func TestGraphTraversal(t *testing.T) {
// The incoming edge should also indicate that it's // The incoming edge should also indicate that it's
// pointing to the origin node. // pointing to the origin node.
if !bytes.Equal( if !bytes.Equal(
inEdge.Node.PubKeyBytes[:], inEdge.ToNode[:], firstNode.PubKeyBytes[:],
firstNode.PubKeyBytes[:],
) { ) {
return fmt.Errorf("wrong outgoing edge") return fmt.Errorf("wrong outgoing edge")
} }
numNodeChans++ numNodeChans++
return nil return nil
}) })
require.NoError(t, err) require.NoError(t, err)
@@ -1275,7 +1274,7 @@ func fillTestGraph(t require.TestingT, graph *ChannelGraph, numNodes,
// from node1 -> node2. // from node1 -> node2.
edge := randEdgePolicy(chanID, graph.db) edge := randEdgePolicy(chanID, graph.db)
edge.ChannelFlags = 0 edge.ChannelFlags = 0
edge.Node = node2 edge.ToNode = node2.PubKeyBytes
edge.SigBytes = testSig.Serialize() edge.SigBytes = testSig.Serialize()
require.NoError(t, graph.UpdateEdgePolicy(edge)) require.NoError(t, graph.UpdateEdgePolicy(edge))
@@ -1283,7 +1282,7 @@ func fillTestGraph(t require.TestingT, graph *ChannelGraph, numNodes,
// node2 -> node1 this time. // node2 -> node1 this time.
edge = randEdgePolicy(chanID, graph.db) edge = randEdgePolicy(chanID, graph.db)
edge.ChannelFlags = 1 edge.ChannelFlags = 1
edge.Node = node1 edge.ToNode = node1.PubKeyBytes
edge.SigBytes = testSig.Serialize() edge.SigBytes = testSig.Serialize()
require.NoError(t, graph.UpdateEdgePolicy(edge)) require.NoError(t, graph.UpdateEdgePolicy(edge))
@@ -1468,7 +1467,7 @@ func TestGraphPruning(t *testing.T) {
// node_i -> node_i+1 // node_i -> node_i+1
edge := randEdgePolicy(chanID, graph.db) edge := randEdgePolicy(chanID, graph.db)
edge.ChannelFlags = 0 edge.ChannelFlags = 0
edge.Node = graphNodes[i] edge.ToNode = graphNodes[i].PubKeyBytes
edge.SigBytes = testSig.Serialize() edge.SigBytes = testSig.Serialize()
if err := graph.UpdateEdgePolicy(edge); err != nil { if err := graph.UpdateEdgePolicy(edge); err != nil {
t.Fatalf("unable to update edge: %v", err) t.Fatalf("unable to update edge: %v", err)
@@ -1478,7 +1477,7 @@ func TestGraphPruning(t *testing.T) {
// node_i this time. // node_i this time.
edge = randEdgePolicy(chanID, graph.db) edge = randEdgePolicy(chanID, graph.db)
edge.ChannelFlags = 1 edge.ChannelFlags = 1
edge.Node = graphNodes[i] edge.ToNode = graphNodes[i].PubKeyBytes
edge.SigBytes = testSig.Serialize() edge.SigBytes = testSig.Serialize()
if err := graph.UpdateEdgePolicy(edge); err != nil { if err := graph.UpdateEdgePolicy(edge); err != nil {
t.Fatalf("unable to update edge: %v", err) t.Fatalf("unable to update edge: %v", err)
@@ -1693,7 +1692,7 @@ func TestChanUpdatesInHorizon(t *testing.T) {
chanID.ToUint64(), graph.db, edge1UpdateTime.Unix(), chanID.ToUint64(), graph.db, edge1UpdateTime.Unix(),
) )
edge1.ChannelFlags = 0 edge1.ChannelFlags = 0
edge1.Node = node2 edge1.ToNode = node2.PubKeyBytes
edge1.SigBytes = testSig.Serialize() edge1.SigBytes = testSig.Serialize()
if err := graph.UpdateEdgePolicy(edge1); err != nil { if err := graph.UpdateEdgePolicy(edge1); err != nil {
t.Fatalf("unable to update edge: %v", err) t.Fatalf("unable to update edge: %v", err)
@@ -1703,7 +1702,7 @@ func TestChanUpdatesInHorizon(t *testing.T) {
chanID.ToUint64(), graph.db, edge2UpdateTime.Unix(), chanID.ToUint64(), graph.db, edge2UpdateTime.Unix(),
) )
edge2.ChannelFlags = 1 edge2.ChannelFlags = 1
edge2.Node = node1 edge2.ToNode = node1.PubKeyBytes
edge2.SigBytes = testSig.Serialize() edge2.SigBytes = testSig.Serialize()
if err := graph.UpdateEdgePolicy(edge2); err != nil { if err := graph.UpdateEdgePolicy(edge2); err != nil {
t.Fatalf("unable to update edge: %v", err) t.Fatalf("unable to update edge: %v", err)
@@ -2187,7 +2186,7 @@ func TestFetchChanInfos(t *testing.T) {
chanID.ToUint64(), graph.db, updateTime.Unix(), chanID.ToUint64(), graph.db, updateTime.Unix(),
) )
edge1.ChannelFlags = 0 edge1.ChannelFlags = 0
edge1.Node = node2 edge1.ToNode = node2.PubKeyBytes
edge1.SigBytes = testSig.Serialize() edge1.SigBytes = testSig.Serialize()
if err := graph.UpdateEdgePolicy(edge1); err != nil { if err := graph.UpdateEdgePolicy(edge1); err != nil {
t.Fatalf("unable to update edge: %v", err) t.Fatalf("unable to update edge: %v", err)
@@ -2197,7 +2196,7 @@ func TestFetchChanInfos(t *testing.T) {
chanID.ToUint64(), graph.db, updateTime.Unix(), chanID.ToUint64(), graph.db, updateTime.Unix(),
) )
edge2.ChannelFlags = 1 edge2.ChannelFlags = 1
edge2.Node = node1 edge2.ToNode = node1.PubKeyBytes
edge2.SigBytes = testSig.Serialize() edge2.SigBytes = testSig.Serialize()
if err := graph.UpdateEdgePolicy(edge2); err != nil { if err := graph.UpdateEdgePolicy(edge2); err != nil {
t.Fatalf("unable to update edge: %v", err) t.Fatalf("unable to update edge: %v", err)
@@ -2326,7 +2325,7 @@ func TestIncompleteChannelPolicies(t *testing.T) {
chanID.ToUint64(), graph.db, updateTime.Unix(), chanID.ToUint64(), graph.db, updateTime.Unix(),
) )
edgePolicy.ChannelFlags = 0 edgePolicy.ChannelFlags = 0
edgePolicy.Node = node2 edgePolicy.ToNode = node2.PubKeyBytes
edgePolicy.SigBytes = testSig.Serialize() edgePolicy.SigBytes = testSig.Serialize()
if err := graph.UpdateEdgePolicy(edgePolicy); err != nil { if err := graph.UpdateEdgePolicy(edgePolicy); err != nil {
t.Fatalf("unable to update edge: %v", err) t.Fatalf("unable to update edge: %v", err)
@@ -2341,7 +2340,7 @@ func TestIncompleteChannelPolicies(t *testing.T) {
chanID.ToUint64(), graph.db, updateTime.Unix(), chanID.ToUint64(), graph.db, updateTime.Unix(),
) )
edgePolicy.ChannelFlags = 1 edgePolicy.ChannelFlags = 1
edgePolicy.Node = node1 edgePolicy.ToNode = node1.PubKeyBytes
edgePolicy.SigBytes = testSig.Serialize() edgePolicy.SigBytes = testSig.Serialize()
if err := graph.UpdateEdgePolicy(edgePolicy); err != nil { if err := graph.UpdateEdgePolicy(edgePolicy); err != nil {
t.Fatalf("unable to update edge: %v", err) t.Fatalf("unable to update edge: %v", err)
@@ -2388,7 +2387,7 @@ func TestChannelEdgePruningUpdateIndexDeletion(t *testing.T) {
edge1 := randEdgePolicy(chanID.ToUint64(), graph.db) edge1 := randEdgePolicy(chanID.ToUint64(), graph.db)
edge1.ChannelFlags = 0 edge1.ChannelFlags = 0
edge1.Node = node1 edge1.ToNode = node1.PubKeyBytes
edge1.SigBytes = testSig.Serialize() edge1.SigBytes = testSig.Serialize()
if err := graph.UpdateEdgePolicy(edge1); err != nil { if err := graph.UpdateEdgePolicy(edge1); err != nil {
t.Fatalf("unable to update edge: %v", err) t.Fatalf("unable to update edge: %v", err)
@@ -2396,7 +2395,7 @@ func TestChannelEdgePruningUpdateIndexDeletion(t *testing.T) {
edge2 := randEdgePolicy(chanID.ToUint64(), graph.db) edge2 := randEdgePolicy(chanID.ToUint64(), graph.db)
edge2.ChannelFlags = 1 edge2.ChannelFlags = 1
edge2.Node = node2 edge2.ToNode = node2.PubKeyBytes
edge2.SigBytes = testSig.Serialize() edge2.SigBytes = testSig.Serialize()
if err := graph.UpdateEdgePolicy(edge2); err != nil { if err := graph.UpdateEdgePolicy(edge2); err != nil {
t.Fatalf("unable to update edge: %v", err) t.Fatalf("unable to update edge: %v", err)
@@ -2541,7 +2540,7 @@ func TestPruneGraphNodes(t *testing.T) {
// points from the first to the second node. // points from the first to the second node.
edge1 := randEdgePolicy(chanID.ToUint64(), graph.db) edge1 := randEdgePolicy(chanID.ToUint64(), graph.db)
edge1.ChannelFlags = 0 edge1.ChannelFlags = 0
edge1.Node = node1 edge1.ToNode = node1.PubKeyBytes
edge1.SigBytes = testSig.Serialize() edge1.SigBytes = testSig.Serialize()
if err := graph.UpdateEdgePolicy(edge1); err != nil { if err := graph.UpdateEdgePolicy(edge1); err != nil {
t.Fatalf("unable to update edge: %v", err) t.Fatalf("unable to update edge: %v", err)
@@ -2908,8 +2907,8 @@ func TestEdgePolicyMissingMaxHtcl(t *testing.T) {
} }
chanID := edgeInfo.ChannelID chanID := edgeInfo.ChannelID
from := edge2.Node.PubKeyBytes[:] from := edge2.ToNode[:]
to := edge1.Node.PubKeyBytes[:] to := edge1.ToNode[:]
// We'll remove the no max_htlc field from the first edge policy, and // We'll remove the no max_htlc field from the first edge policy, and
// all other opaque data, and serialize it. // all other opaque data, and serialize it.
@@ -2945,7 +2944,7 @@ func TestEdgePolicyMissingMaxHtcl(t *testing.T) {
return ErrGraphNotFound return ErrGraphNotFound
} }
_, err = deserializeChanEdgePolicy(r, nodes) _, err = deserializeChanEdgePolicy(r)
if err != ErrEdgePolicyOptionalFieldNotFound { if err != ErrEdgePolicyOptionalFieldNotFound {
t.Fatalf("expected "+ t.Fatalf("expected "+
"ErrEdgePolicyOptionalFieldNotFound, got %v", "ErrEdgePolicyOptionalFieldNotFound, got %v",
@@ -3196,9 +3195,11 @@ func compareEdgePolicies(a, b *ChannelEdgePolicy) error {
return fmt.Errorf("extra data doesn't match: %v vs %v", return fmt.Errorf("extra data doesn't match: %v vs %v",
a.ExtraOpaqueData, b.ExtraOpaqueData) a.ExtraOpaqueData, b.ExtraOpaqueData)
} }
if err := compareNodes(a.Node, b.Node); err != nil { if !bytes.Equal(a.ToNode[:], b.ToNode[:]) {
return err return fmt.Errorf("ToNode doesn't match: expected %x, got %x",
a.ToNode, b.ToNode)
} }
return nil return nil
} }
+10 -6
View File
@@ -280,10 +280,12 @@ func (c *ChanSeries) FetchChanAnns(chain chainhash.Hash,
// If this edge has a validated node announcement, that // If this edge has a validated node announcement, that
// we haven't yet sent, then we'll send that as well. // we haven't yet sent, then we'll send that as well.
nodePub := channel.Policy1.Node.PubKeyBytes nodePub := channel.Node2.PubKeyBytes
hasNodeAnn := channel.Policy1.Node.HaveNodeAnnouncement hasNodeAnn := channel.Node2.HaveNodeAnnouncement
if _, ok := nodePubsSent[nodePub]; !ok && hasNodeAnn { if _, ok := nodePubsSent[nodePub]; !ok && hasNodeAnn {
nodeAnn, err := channel.Policy1.Node.NodeAnnouncement(true) nodeAnn, err := channel.Node2.NodeAnnouncement(
true,
)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -297,10 +299,12 @@ func (c *ChanSeries) FetchChanAnns(chain chainhash.Hash,
// If this edge has a validated node announcement, that // If this edge has a validated node announcement, that
// we haven't yet sent, then we'll send that as well. // we haven't yet sent, then we'll send that as well.
nodePub := channel.Policy2.Node.PubKeyBytes nodePub := channel.Node1.PubKeyBytes
hasNodeAnn := channel.Policy2.Node.HaveNodeAnnouncement hasNodeAnn := channel.Node1.HaveNodeAnnouncement
if _, ok := nodePubsSent[nodePub]; !ok && hasNodeAnn { if _, ok := nodePubsSent[nodePub]; !ok && hasNodeAnn {
nodeAnn, err := channel.Policy2.Node.NodeAnnouncement(true) nodeAnn, err := channel.Node1.NodeAnnouncement(
true,
)
if err != nil { if err != nil {
return nil, err return nil, err
} }
+1 -1
View File
@@ -85,7 +85,7 @@ func randEdgePolicy(chanID *lnwire.ShortChannelID,
MaxHTLC: lnwire.MilliSatoshi(prand.Int31()), MaxHTLC: lnwire.MilliSatoshi(prand.Int31()),
FeeBaseMSat: lnwire.MilliSatoshi(prand.Int31()), FeeBaseMSat: lnwire.MilliSatoshi(prand.Int31()),
FeeProportionalMillionths: lnwire.MilliSatoshi(prand.Int31()), FeeProportionalMillionths: lnwire.MilliSatoshi(prand.Int31()),
Node: node, ToNode: node.PubKeyBytes,
} }
} }
+3 -34
View File
@@ -303,16 +303,6 @@ func parseTestGraph(t *testing.T, useCache bool, path string) (
} }
} }
aliasForNode := func(node route.Vertex) string {
for alias, pubKey := range aliasMap {
if pubKey == node {
return alias
}
}
return ""
}
// With all the vertexes inserted, we can now insert the edges into the // With all the vertexes inserted, we can now insert the edges into the
// test graph. // test graph.
for _, edge := range g.Edges { for _, edge := range g.Edges {
@@ -387,10 +377,7 @@ func parseTestGraph(t *testing.T, useCache bool, path string) (
MaxHTLC: lnwire.MilliSatoshi(edge.MaxHTLC), MaxHTLC: lnwire.MilliSatoshi(edge.MaxHTLC),
FeeBaseMSat: lnwire.MilliSatoshi(edge.FeeBaseMsat), FeeBaseMSat: lnwire.MilliSatoshi(edge.FeeBaseMsat),
FeeProportionalMillionths: lnwire.MilliSatoshi(edge.FeeRate), FeeProportionalMillionths: lnwire.MilliSatoshi(edge.FeeRate),
Node: &channeldb.LightningNode{ ToNode: targetNode,
Alias: aliasForNode(targetNode),
PubKeyBytes: targetNode,
},
} }
if err := graph.UpdateEdgePolicy(edgePolicy); err != nil { if err := graph.UpdateEdgePolicy(edgePolicy); err != nil {
return nil, err return nil, err
@@ -684,11 +671,6 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
channelFlags |= lnwire.ChanUpdateDisabled channelFlags |= lnwire.ChanUpdateDisabled
} }
node2Features := lnwire.EmptyFeatureVector()
if node2.testChannelPolicy != nil {
node2Features = node2.Features
}
edgePolicy := &channeldb.ChannelEdgePolicy{ edgePolicy := &channeldb.ChannelEdgePolicy{
SigBytes: testSig.Serialize(), SigBytes: testSig.Serialize(),
MessageFlags: msgFlags, MessageFlags: msgFlags,
@@ -700,11 +682,7 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
MaxHTLC: node1.MaxHTLC, MaxHTLC: node1.MaxHTLC,
FeeBaseMSat: node1.FeeBaseMsat, FeeBaseMSat: node1.FeeBaseMsat,
FeeProportionalMillionths: node1.FeeRate, FeeProportionalMillionths: node1.FeeRate,
Node: &channeldb.LightningNode{ ToNode: node2Vertex,
Alias: node2.Alias,
PubKeyBytes: node2Vertex,
Features: node2Features,
},
} }
if err := graph.UpdateEdgePolicy(edgePolicy); err != nil { if err := graph.UpdateEdgePolicy(edgePolicy); err != nil {
return nil, err return nil, err
@@ -722,11 +700,6 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
} }
channelFlags |= lnwire.ChanUpdateDirection channelFlags |= lnwire.ChanUpdateDirection
node1Features := lnwire.EmptyFeatureVector()
if node1.testChannelPolicy != nil {
node1Features = node1.Features
}
edgePolicy := &channeldb.ChannelEdgePolicy{ edgePolicy := &channeldb.ChannelEdgePolicy{
SigBytes: testSig.Serialize(), SigBytes: testSig.Serialize(),
MessageFlags: msgFlags, MessageFlags: msgFlags,
@@ -738,11 +711,7 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
MaxHTLC: node2.MaxHTLC, MaxHTLC: node2.MaxHTLC,
FeeBaseMSat: node2.FeeBaseMsat, FeeBaseMSat: node2.FeeBaseMsat,
FeeProportionalMillionths: node2.FeeRate, FeeProportionalMillionths: node2.FeeRate,
Node: &channeldb.LightningNode{ ToNode: node1Vertex,
Alias: node1.Alias,
PubKeyBytes: node1Vertex,
Features: node1Features,
},
} }
if err := graph.UpdateEdgePolicy(edgePolicy); err != nil { if err := graph.UpdateEdgePolicy(edgePolicy); err != nil {
return nil, err return nil, err
+4 -12
View File
@@ -1431,9 +1431,7 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
MinHTLC: 1, MinHTLC: 1,
FeeBaseMSat: 10, FeeBaseMSat: 10,
FeeProportionalMillionths: 10000, FeeProportionalMillionths: 10000,
Node: &channeldb.LightningNode{ ToNode: edge.NodeKey2Bytes,
PubKeyBytes: edge.NodeKey2Bytes,
},
} }
edgePolicy.ChannelFlags = 0 edgePolicy.ChannelFlags = 0
@@ -1450,9 +1448,7 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
MinHTLC: 1, MinHTLC: 1,
FeeBaseMSat: 10, FeeBaseMSat: 10,
FeeProportionalMillionths: 10000, FeeProportionalMillionths: 10000,
Node: &channeldb.LightningNode{ ToNode: edge.NodeKey1Bytes,
PubKeyBytes: edge.NodeKey1Bytes,
},
} }
edgePolicy.ChannelFlags = 1 edgePolicy.ChannelFlags = 1
@@ -1528,9 +1524,7 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
MinHTLC: 1, MinHTLC: 1,
FeeBaseMSat: 10, FeeBaseMSat: 10,
FeeProportionalMillionths: 10000, FeeProportionalMillionths: 10000,
Node: &channeldb.LightningNode{ ToNode: edge.NodeKey2Bytes,
PubKeyBytes: edge.NodeKey2Bytes,
},
} }
edgePolicy.ChannelFlags = 0 edgePolicy.ChannelFlags = 0
@@ -1546,9 +1540,7 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
MinHTLC: 1, MinHTLC: 1,
FeeBaseMSat: 10, FeeBaseMSat: 10,
FeeProportionalMillionths: 10000, FeeProportionalMillionths: 10000,
Node: &channeldb.LightningNode{ ToNode: edge.NodeKey1Bytes,
PubKeyBytes: edge.NodeKey1Bytes,
},
} }
edgePolicy.ChannelFlags = 1 edgePolicy.ChannelFlags = 1