diff --git a/autopilot/graph.go b/autopilot/graph.go index 5ee54737..15440caf 100644 --- a/autopilot/graph.go +++ b/autopilot/graph.go @@ -270,6 +270,30 @@ func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey, nil } +func (d *databaseChannelGraph) addRandNode() (*btcec.PublicKey, error) { + nodeKey, err := randKey() + if err != nil { + return nil, err + } + dbNode := &channeldb.LightningNode{ + HaveNodeAnnouncement: true, + Addresses: []net.Addr{ + &net.TCPAddr{ + IP: bytes.Repeat([]byte("a"), 16), + }, + }, + Features: lnwire.NewFeatureVector(nil, lnwire.GlobalFeatures), + AuthSigBytes: testSig.Serialize(), + } + dbNode.AddPubKey(nodeKey) + if err := d.db.AddLightningNode(dbNode); err != nil { + return nil, err + } + + return nodeKey, nil + +} + // memChannelGraph is an implementation of the autopilot.ChannelGraph backed by // an in-memory graph. type memChannelGraph struct { @@ -407,6 +431,24 @@ func (m *memChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey, return &edge1, &edge2, nil } +func (m *memChannelGraph) addRandNode() (*btcec.PublicKey, error) { + newPub, err := randKey() + if err != nil { + return nil, err + } + vertex := memNode{ + pub: newPub, + addrs: []net.Addr{ + &net.TCPAddr{ + IP: bytes.Repeat([]byte("a"), 16), + }, + }, + } + m.graph[NewNodeID(newPub)] = vertex + + return newPub, nil +} + // memNode is a purely in-memory implementation of the autopilot.Node // interface. type memNode struct { diff --git a/autopilot/prefattach_test.go b/autopilot/prefattach_test.go index c647c2d9..5801c00d 100644 --- a/autopilot/prefattach_test.go +++ b/autopilot/prefattach_test.go @@ -182,6 +182,8 @@ type testGraph interface { addRandChannel(*btcec.PublicKey, *btcec.PublicKey, btcutil.Amount) (*ChannelEdge, *ChannelEdge, error) + + addRandNode() (*btcec.PublicKey, error) } func newDiskChanGraph() (testGraph, func(), error) {