autopilot/interface+agent: remove NodeKey from AttachmentDirective

Instead parse the pubkey bytes only when needed.
This commit is contained in:
Johan T. Halseth 2018-12-06 13:59:46 +01:00
parent 89c3c5319f
commit 5ecc209c41
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26
5 changed files with 18 additions and 28 deletions

@ -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",

@ -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{

@ -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

@ -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))

@ -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