diff --git a/autopilot/agent.go b/autopilot/agent.go index e984c8fd..f4b25b9a 100644 --- a/autopilot/agent.go +++ b/autopilot/agent.go @@ -574,8 +574,13 @@ func (a *Agent) executeDirective(directive AttachmentDirective) { // We'll start out by attempting to connect to the peer in order to // begin the funding workflow. - pub := directive.NodeKey nodeID := directive.NodeID + pub, err := btcec.ParsePubKey(nodeID[:], btcec.S256()) + if err != nil { + log.Errorf("Unable to parse pubkey %x: %v", nodeID, err) + return + } + alreadyConnected, err := a.cfg.ConnectToPeer(pub, directive.Addrs) if err != nil { log.Warnf("Unable to connect to %x: %v", diff --git a/autopilot/agent_test.go b/autopilot/agent_test.go index 98b03a57..c5c07de4 100644 --- a/autopilot/agent_test.go +++ b/autopilot/agent_test.go @@ -325,7 +325,6 @@ func TestAgentChannelFailureSignal(t *testing.T) { // request attachment directives, return a fake so the agent will // attempt to open a channel. var fakeDirective = AttachmentDirective{ - NodeKey: self, NodeID: NewNodeID(self), ChanAmt: btcutil.SatoshiPerBitcoin, Addrs: []net.Addr{ @@ -669,7 +668,6 @@ func TestAgentImmediateAttach(t *testing.T) { } nodeID := NewNodeID(pub) directives[i] = AttachmentDirective{ - NodeKey: pub, NodeID: nodeID, ChanAmt: btcutil.SatoshiPerBitcoin, Addrs: []net.Addr{ @@ -802,7 +800,6 @@ func TestAgentPrivateChannels(t *testing.T) { t.Fatalf("unable to generate key: %v", err) } directives[i] = AttachmentDirective{ - NodeKey: pub, NodeID: NewNodeID(pub), ChanAmt: btcutil.SatoshiPerBitcoin, Addrs: []net.Addr{ @@ -925,7 +922,6 @@ func TestAgentPendingChannelState(t *testing.T) { } nodeID := NewNodeID(nodeKey) nodeDirective := AttachmentDirective{ - NodeKey: nodeKey, NodeID: nodeID, ChanAmt: 0.5 * btcutil.SatoshiPerBitcoin, Addrs: []net.Addr{ @@ -1309,7 +1305,6 @@ func TestAgentSkipPendingConns(t *testing.T) { t.Fatalf("unable to generate key: %v", err) } nodeDirective := AttachmentDirective{ - NodeKey: nodeKey, NodeID: NewNodeID(nodeKey), ChanAmt: 0.5 * btcutil.SatoshiPerBitcoin, Addrs: []net.Addr{ diff --git a/autopilot/interface.go b/autopilot/interface.go index efa99298..35e447e7 100644 --- a/autopilot/interface.go +++ b/autopilot/interface.go @@ -85,12 +85,10 @@ type ChannelGraph interface { // AttachmentHeuristic. It details to which node a channel should be created // to, and also the parameters which should be used in the channel creation. type AttachmentDirective struct { - // NodeKey is the target node for this attachment directive. It can be - // identified by its public key, and therefore can be used along with - // a ChannelOpener implementation to execute the directive. - NodeKey *btcec.PublicKey - - // NodeID is the serialized compressed pubkey of the target node. + // NodeID is the serialized compressed pubkey of the target node for + // this attachment directive. It can be identified by its public key, + // and therefore can be used along with a ChannelOpener implementation + // to execute the directive. NodeID NodeID // ChanAmt is the size of the channel that should be opened, expressed diff --git a/autopilot/prefattach.go b/autopilot/prefattach.go index 85969992..d675ac98 100644 --- a/autopilot/prefattach.go +++ b/autopilot/prefattach.go @@ -197,23 +197,15 @@ func (p *ConstrainedPrefAttachment) Select(self *btcec.PublicKey, g ChannelGraph // With the node selected, we'll add this (node, amount) tuple // to out set of recommended directives. pubBytes := selectedNode.PubKey() - pub, err := btcec.ParsePubKey(pubBytes[:], btcec.S256()) - if err != nil { - return nil, err - } + nID := NodeID(pubBytes) directives = append(directives, AttachmentDirective{ - // TODO(roasbeef): need curve? - NodeKey: &btcec.PublicKey{ - X: pub.X, - Y: pub.Y, - }, - NodeID: NewNodeID(pub), + NodeID: nID, Addrs: selectedNode.Addrs(), }) // With the node selected, we'll add it to the set of visited // nodes to avoid attaching to it again. - visited[NodeID(pubBytes)] = struct{}{} + visited[nID] = struct{}{} } numSelectedNodes := int64(len(directives)) diff --git a/autopilot/prefattach_test.go b/autopilot/prefattach_test.go index 6a6dc44c..f3e6daf8 100644 --- a/autopilot/prefattach_test.go +++ b/autopilot/prefattach_test.go @@ -366,11 +366,11 @@ func TestConstrainedPrefAttachmentSelectTwoVertexes(t *testing.T) { edge2Pub := edge2.Peer.PubKey() switch { - case bytes.Equal(directive.NodeKey.SerializeCompressed(), edge1Pub[:]): - case bytes.Equal(directive.NodeKey.SerializeCompressed(), edge2Pub[:]): + case bytes.Equal(directive.NodeID[:], edge1Pub[:]): + case bytes.Equal(directive.NodeID[:], edge2Pub[:]): default: t1.Fatalf("attached to unknown node: %x", - directive.NodeKey.SerializeCompressed()) + directive.NodeID[:]) } // As the number of funds available exceed the @@ -666,8 +666,8 @@ func TestConstrainedPrefAttachmentSelectSkipNodes(t *testing.T) { // We'll simulate a channel update by adding the nodes // we just establish channel with the to set of nodes // to be skipped. - skipNodes[NewNodeID(directives[0].NodeKey)] = struct{}{} - skipNodes[NewNodeID(directives[1].NodeKey)] = struct{}{} + skipNodes[directives[0].NodeID] = struct{}{} + skipNodes[directives[1].NodeID] = struct{}{} // If we attempt to make a call to the Select function, // without providing any new information, then we