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

@@ -59,12 +59,12 @@ type dbNode struct {
var _ Node = (*dbNode)(nil)
// PubKey is the identity public key of the node. This will be used to attempt
// to target a node for channel opening by the main autopilot agent.
// to target a node for channel opening by the main autopilot agent. The key
// will be returned in serialized compressed format.
//
// NOTE: Part of the autopilot.Node interface.
func (d dbNode) PubKey() *btcec.PublicKey {
pubKey, _ := d.node.PubKey()
return pubKey
func (d dbNode) PubKey() [33]byte {
return d.node.PubKeyBytes
}
// Addrs returns a slice of publicly reachable public TCP addresses that the
@@ -406,8 +406,11 @@ var _ Node = (*memNode)(nil)
// to target a node for channel opening by the main autopilot agent.
//
// NOTE: Part of the autopilot.Node interface.
func (m memNode) PubKey() *btcec.PublicKey {
return m.pub
func (m memNode) PubKey() [33]byte {
var n [33]byte
copy(n[:], m.pub.SerializeCompressed())
return n
}
// Addrs returns a slice of publicly reachable public TCP addresses that the