autopilot/interface+agent: remove NodeKey from AttachmentDirective
Instead parse the pubkey bytes only when needed.
This commit is contained in:
parent
89c3c5319f
commit
5ecc209c41
@ -574,8 +574,13 @@ func (a *Agent) executeDirective(directive AttachmentDirective) {
|
|||||||
|
|
||||||
// We'll start out by attempting to connect to the peer in order to
|
// We'll start out by attempting to connect to the peer in order to
|
||||||
// begin the funding workflow.
|
// begin the funding workflow.
|
||||||
pub := directive.NodeKey
|
|
||||||
nodeID := directive.NodeID
|
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)
|
alreadyConnected, err := a.cfg.ConnectToPeer(pub, directive.Addrs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("Unable to connect to %x: %v",
|
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
|
// request attachment directives, return a fake so the agent will
|
||||||
// attempt to open a channel.
|
// attempt to open a channel.
|
||||||
var fakeDirective = AttachmentDirective{
|
var fakeDirective = AttachmentDirective{
|
||||||
NodeKey: self,
|
|
||||||
NodeID: NewNodeID(self),
|
NodeID: NewNodeID(self),
|
||||||
ChanAmt: btcutil.SatoshiPerBitcoin,
|
ChanAmt: btcutil.SatoshiPerBitcoin,
|
||||||
Addrs: []net.Addr{
|
Addrs: []net.Addr{
|
||||||
@ -669,7 +668,6 @@ func TestAgentImmediateAttach(t *testing.T) {
|
|||||||
}
|
}
|
||||||
nodeID := NewNodeID(pub)
|
nodeID := NewNodeID(pub)
|
||||||
directives[i] = AttachmentDirective{
|
directives[i] = AttachmentDirective{
|
||||||
NodeKey: pub,
|
|
||||||
NodeID: nodeID,
|
NodeID: nodeID,
|
||||||
ChanAmt: btcutil.SatoshiPerBitcoin,
|
ChanAmt: btcutil.SatoshiPerBitcoin,
|
||||||
Addrs: []net.Addr{
|
Addrs: []net.Addr{
|
||||||
@ -802,7 +800,6 @@ func TestAgentPrivateChannels(t *testing.T) {
|
|||||||
t.Fatalf("unable to generate key: %v", err)
|
t.Fatalf("unable to generate key: %v", err)
|
||||||
}
|
}
|
||||||
directives[i] = AttachmentDirective{
|
directives[i] = AttachmentDirective{
|
||||||
NodeKey: pub,
|
|
||||||
NodeID: NewNodeID(pub),
|
NodeID: NewNodeID(pub),
|
||||||
ChanAmt: btcutil.SatoshiPerBitcoin,
|
ChanAmt: btcutil.SatoshiPerBitcoin,
|
||||||
Addrs: []net.Addr{
|
Addrs: []net.Addr{
|
||||||
@ -925,7 +922,6 @@ func TestAgentPendingChannelState(t *testing.T) {
|
|||||||
}
|
}
|
||||||
nodeID := NewNodeID(nodeKey)
|
nodeID := NewNodeID(nodeKey)
|
||||||
nodeDirective := AttachmentDirective{
|
nodeDirective := AttachmentDirective{
|
||||||
NodeKey: nodeKey,
|
|
||||||
NodeID: nodeID,
|
NodeID: nodeID,
|
||||||
ChanAmt: 0.5 * btcutil.SatoshiPerBitcoin,
|
ChanAmt: 0.5 * btcutil.SatoshiPerBitcoin,
|
||||||
Addrs: []net.Addr{
|
Addrs: []net.Addr{
|
||||||
@ -1309,7 +1305,6 @@ func TestAgentSkipPendingConns(t *testing.T) {
|
|||||||
t.Fatalf("unable to generate key: %v", err)
|
t.Fatalf("unable to generate key: %v", err)
|
||||||
}
|
}
|
||||||
nodeDirective := AttachmentDirective{
|
nodeDirective := AttachmentDirective{
|
||||||
NodeKey: nodeKey,
|
|
||||||
NodeID: NewNodeID(nodeKey),
|
NodeID: NewNodeID(nodeKey),
|
||||||
ChanAmt: 0.5 * btcutil.SatoshiPerBitcoin,
|
ChanAmt: 0.5 * btcutil.SatoshiPerBitcoin,
|
||||||
Addrs: []net.Addr{
|
Addrs: []net.Addr{
|
||||||
|
@ -85,12 +85,10 @@ type ChannelGraph interface {
|
|||||||
// AttachmentHeuristic. It details to which node a channel should be created
|
// AttachmentHeuristic. It details to which node a channel should be created
|
||||||
// to, and also the parameters which should be used in the channel creation.
|
// to, and also the parameters which should be used in the channel creation.
|
||||||
type AttachmentDirective struct {
|
type AttachmentDirective struct {
|
||||||
// NodeKey is the target node for this attachment directive. It can be
|
// NodeID is the serialized compressed pubkey of the target node for
|
||||||
// identified by its public key, and therefore can be used along with
|
// this attachment directive. It can be identified by its public key,
|
||||||
// a ChannelOpener implementation to execute the directive.
|
// and therefore can be used along with a ChannelOpener implementation
|
||||||
NodeKey *btcec.PublicKey
|
// to execute the directive.
|
||||||
|
|
||||||
// NodeID is the serialized compressed pubkey of the target node.
|
|
||||||
NodeID NodeID
|
NodeID NodeID
|
||||||
|
|
||||||
// ChanAmt is the size of the channel that should be opened, expressed
|
// 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
|
// With the node selected, we'll add this (node, amount) tuple
|
||||||
// to out set of recommended directives.
|
// to out set of recommended directives.
|
||||||
pubBytes := selectedNode.PubKey()
|
pubBytes := selectedNode.PubKey()
|
||||||
pub, err := btcec.ParsePubKey(pubBytes[:], btcec.S256())
|
nID := NodeID(pubBytes)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
directives = append(directives, AttachmentDirective{
|
directives = append(directives, AttachmentDirective{
|
||||||
// TODO(roasbeef): need curve?
|
NodeID: nID,
|
||||||
NodeKey: &btcec.PublicKey{
|
|
||||||
X: pub.X,
|
|
||||||
Y: pub.Y,
|
|
||||||
},
|
|
||||||
NodeID: NewNodeID(pub),
|
|
||||||
Addrs: selectedNode.Addrs(),
|
Addrs: selectedNode.Addrs(),
|
||||||
})
|
})
|
||||||
|
|
||||||
// With the node selected, we'll add it to the set of visited
|
// With the node selected, we'll add it to the set of visited
|
||||||
// nodes to avoid attaching to it again.
|
// nodes to avoid attaching to it again.
|
||||||
visited[NodeID(pubBytes)] = struct{}{}
|
visited[nID] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
numSelectedNodes := int64(len(directives))
|
numSelectedNodes := int64(len(directives))
|
||||||
|
@ -366,11 +366,11 @@ func TestConstrainedPrefAttachmentSelectTwoVertexes(t *testing.T) {
|
|||||||
edge2Pub := edge2.Peer.PubKey()
|
edge2Pub := edge2.Peer.PubKey()
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case bytes.Equal(directive.NodeKey.SerializeCompressed(), edge1Pub[:]):
|
case bytes.Equal(directive.NodeID[:], edge1Pub[:]):
|
||||||
case bytes.Equal(directive.NodeKey.SerializeCompressed(), edge2Pub[:]):
|
case bytes.Equal(directive.NodeID[:], edge2Pub[:]):
|
||||||
default:
|
default:
|
||||||
t1.Fatalf("attached to unknown node: %x",
|
t1.Fatalf("attached to unknown node: %x",
|
||||||
directive.NodeKey.SerializeCompressed())
|
directive.NodeID[:])
|
||||||
}
|
}
|
||||||
|
|
||||||
// As the number of funds available exceed the
|
// 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'll simulate a channel update by adding the nodes
|
||||||
// we just establish channel with the to set of nodes
|
// we just establish channel with the to set of nodes
|
||||||
// to be skipped.
|
// to be skipped.
|
||||||
skipNodes[NewNodeID(directives[0].NodeKey)] = struct{}{}
|
skipNodes[directives[0].NodeID] = struct{}{}
|
||||||
skipNodes[NewNodeID(directives[1].NodeKey)] = struct{}{}
|
skipNodes[directives[1].NodeID] = struct{}{}
|
||||||
|
|
||||||
// If we attempt to make a call to the Select function,
|
// If we attempt to make a call to the Select function,
|
||||||
// without providing any new information, then we
|
// without providing any new information, then we
|
||||||
|
Loading…
Reference in New Issue
Block a user