autopilot: update the Node interface to return a raw bytes, not the key

In this commit, we modify the Node interface to return a set of raw
bytes, rather than the full pubkey struct. We do this as within the
package, commonly we only require the pubkey bytes for fingerprinting
purposes. Before this commit, we were forced to _always_ decompress the
pubkey which can be expensive done thousands of times a second.
This commit is contained in:
Olaoluwa Osuntokun
2018-08-29 15:44:26 -07:00
parent 73af09a06a
commit a429c56c10
4 changed files with 37 additions and 16 deletions

View File

@@ -1,6 +1,7 @@
package autopilot
import (
"bytes"
"io/ioutil"
"os"
"testing"
@@ -344,11 +345,14 @@ func TestConstrainedPrefAttachmentSelectTwoVertexes(t *testing.T) {
// The node attached to should be amongst the two edges
// created above.
for _, directive := range directives {
edge1Pub := edge1.Peer.PubKey()
edge2Pub := edge2.Peer.PubKey()
switch {
case directive.PeerKey.IsEqual(edge1.Peer.PubKey()):
case directive.PeerKey.IsEqual(edge2.Peer.PubKey()):
case bytes.Equal(directive.PeerKey.SerializeCompressed(), edge1Pub[:]):
case bytes.Equal(directive.PeerKey.SerializeCompressed(), edge2Pub[:]):
default:
t1.Fatalf("attache to unknown node: %x",
t1.Fatalf("attached to unknown node: %x",
directive.PeerKey.SerializeCompressed())
}
@@ -472,8 +476,15 @@ func TestConstrainedPrefAttachmentSelectGreedyAllocation(t *testing.T) {
if err != nil {
t1.Fatalf("unable to create channel: %v", err)
}
peerPubBytes := edge1.Peer.PubKey()
peerPub, err := btcec.ParsePubKey(
peerPubBytes[:], btcec.S256(),
)
if err != nil {
t.Fatalf("unable to parse pubkey: %v", err)
}
_, _, err = graph.addRandChannel(
edge1.Peer.PubKey(), nil, chanCapacity,
peerPub, nil, chanCapacity,
)
if err != nil {
t1.Fatalf("unable to create channel: %v", err)