autopilot: convert Peer to route.Vertex
In preparation for removing the ForEachNode/ForEachChannel call pattern, we refactor the autopilot subserver by simplifying the `ChannelEdge` such that it no longer returns the `Node` type which has a `ForEachChannel` method on it. The aim is to completely remove the `ForEachChannel` usage.
This commit is contained in:
4 files changed
+18
-24
No files matched your search
+2
-6
@@ -106,9 +106,7 @@ func (d *dbNode) ForEachChannel(ctx context.Context,
|
|||||||
edge := ChannelEdge{
|
edge := ChannelEdge{
|
||||||
ChanID: lnwire.NewShortChanIDFromInt(ep.ChannelID),
|
ChanID: lnwire.NewShortChanIDFromInt(ep.ChannelID),
|
||||||
Capacity: ei.Capacity,
|
Capacity: ei.Capacity,
|
||||||
Peer: &dbNode{
|
Peer: node.Node().PubKeyBytes,
|
||||||
tx: node,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return cb(ctx, edge)
|
return cb(ctx, edge)
|
||||||
@@ -198,9 +196,7 @@ func (nc dbNodeCached) ForEachChannel(ctx context.Context,
|
|||||||
edge := ChannelEdge{
|
edge := ChannelEdge{
|
||||||
ChanID: lnwire.NewShortChanIDFromInt(cid),
|
ChanID: lnwire.NewShortChanIDFromInt(cid),
|
||||||
Capacity: channel.Capacity,
|
Capacity: channel.Capacity,
|
||||||
Peer: dbNodeCached{
|
Peer: channel.OtherNode,
|
||||||
node: channel.OtherNode,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := cb(ctx, edge); err != nil {
|
if err := cb(ctx, edge); err != nil {
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ type ChannelEdge struct {
|
|||||||
|
|
||||||
// Peer is the peer that this channel creates an edge to in the channel
|
// Peer is the peer that this channel creates an edge to in the channel
|
||||||
// graph.
|
// graph.
|
||||||
Peer Node
|
Peer route.Vertex
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChannelGraph in an interface that represents a traversable channel graph.
|
// ChannelGraph in an interface that represents a traversable channel graph.
|
||||||
|
|||||||
@@ -175,8 +175,8 @@ func TestPrefAttachmentSelectTwoVertexes(t *testing.T) {
|
|||||||
// The candidates should be amongst the two edges
|
// The candidates should be amongst the two edges
|
||||||
// created above.
|
// created above.
|
||||||
for nodeID, candidate := range candidates {
|
for nodeID, candidate := range candidates {
|
||||||
edge1Pub := edge1.Peer.PubKey()
|
edge1Pub := edge1.Peer
|
||||||
edge2Pub := edge2.Peer.PubKey()
|
edge2Pub := edge2.Peer
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case bytes.Equal(nodeID[:], edge1Pub[:]):
|
case bytes.Equal(nodeID[:], edge1Pub[:]):
|
||||||
@@ -228,7 +228,7 @@ func TestPrefAttachmentSelectGreedyAllocation(t *testing.T) {
|
|||||||
)
|
)
|
||||||
require.NoError(t1, err)
|
require.NoError(t1, err)
|
||||||
|
|
||||||
peerPubBytes := edge1.Peer.PubKey()
|
peerPubBytes := edge1.Peer
|
||||||
peerPub, err := btcec.ParsePubKey(peerPubBytes[:])
|
peerPub, err := btcec.ParsePubKey(peerPubBytes[:])
|
||||||
require.NoError(t1, err)
|
require.NoError(t1, err)
|
||||||
|
|
||||||
@@ -535,18 +535,12 @@ func (d *testDBGraph) addRandChannel(node1, node2 *btcec.PublicKey,
|
|||||||
return &ChannelEdge{
|
return &ChannelEdge{
|
||||||
ChanID: chanID,
|
ChanID: chanID,
|
||||||
Capacity: capacity,
|
Capacity: capacity,
|
||||||
Peer: &dbNode{tx: &testNodeTx{
|
Peer: vertex1.PubKeyBytes,
|
||||||
db: d,
|
|
||||||
node: vertex1,
|
|
||||||
}},
|
|
||||||
},
|
},
|
||||||
&ChannelEdge{
|
&ChannelEdge{
|
||||||
ChanID: chanID,
|
ChanID: chanID,
|
||||||
Capacity: capacity,
|
Capacity: capacity,
|
||||||
Peer: &dbNode{tx: &testNodeTx{
|
Peer: vertex2.PubKeyBytes,
|
||||||
db: d,
|
|
||||||
node: vertex2,
|
|
||||||
}},
|
|
||||||
},
|
},
|
||||||
nil
|
nil
|
||||||
}
|
}
|
||||||
@@ -692,14 +686,14 @@ func (m *memChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
|
|||||||
edge1 := ChannelEdge{
|
edge1 := ChannelEdge{
|
||||||
ChanID: randChanID(),
|
ChanID: randChanID(),
|
||||||
Capacity: capacity,
|
Capacity: capacity,
|
||||||
Peer: vertex2,
|
Peer: vertex2.PubKey(),
|
||||||
}
|
}
|
||||||
vertex1.chans = append(vertex1.chans, edge1)
|
vertex1.chans = append(vertex1.chans, edge1)
|
||||||
|
|
||||||
edge2 := ChannelEdge{
|
edge2 := ChannelEdge{
|
||||||
ChanID: randChanID(),
|
ChanID: randChanID(),
|
||||||
Capacity: capacity,
|
Capacity: capacity,
|
||||||
Peer: vertex1,
|
Peer: vertex1.PubKey(),
|
||||||
}
|
}
|
||||||
vertex2.chans = append(vertex2.chans, edge2)
|
vertex2.chans = append(vertex2.chans, edge2)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package autopilot
|
package autopilot
|
||||||
|
|
||||||
import "context"
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/lightningnetwork/lnd/routing/route"
|
||||||
|
)
|
||||||
|
|
||||||
// diameterCutoff is used to discard nodes in the diameter calculation.
|
// diameterCutoff is used to discard nodes in the diameter calculation.
|
||||||
// It is the multiplier for the eccentricity of the highest-degree node,
|
// It is the multiplier for the eccentricity of the highest-degree node,
|
||||||
@@ -31,8 +35,8 @@ func NewSimpleGraph(ctx context.Context, g ChannelGraph) (*SimpleGraph, error) {
|
|||||||
// The returned index is then used to create a simplified adjacency list
|
// The returned index is then used to create a simplified adjacency list
|
||||||
// where each node is identified by its index instead of its pubkey, and
|
// where each node is identified by its index instead of its pubkey, and
|
||||||
// also to create a mapping from node index to node pubkey.
|
// also to create a mapping from node index to node pubkey.
|
||||||
getNodeIndex := func(node Node) int {
|
getNodeIndex := func(node route.Vertex) int {
|
||||||
key := NodeID(node.PubKey())
|
key := NodeID(node)
|
||||||
nodeIndex, ok := nodes[key]
|
nodeIndex, ok := nodes[key]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -47,7 +51,7 @@ func NewSimpleGraph(ctx context.Context, g ChannelGraph) (*SimpleGraph, error) {
|
|||||||
// Iterate over each node and each channel and update the adj and the
|
// Iterate over each node and each channel and update the adj and the
|
||||||
// node index.
|
// node index.
|
||||||
err := g.ForEachNode(ctx, func(ctx context.Context, node Node) error {
|
err := g.ForEachNode(ctx, func(ctx context.Context, node Node) error {
|
||||||
u := getNodeIndex(node)
|
u := getNodeIndex(node.PubKey())
|
||||||
|
|
||||||
return node.ForEachChannel(
|
return node.ForEachChannel(
|
||||||
ctx, func(_ context.Context,
|
ctx, func(_ context.Context,
|
||||||
|
|||||||
Reference in new issue
Block a user