channeldb: take serialized key to fetch lightning node

This prevents inefficient key conversions in a follow up commit that
change the inner pathfinding loop.
This commit is contained in:
Joost Jager
2019-12-18 12:43:18 +01:00
parent 8ce9e15f4a
commit 37d9ee302c
9 changed files with 39 additions and 61 deletions

View File

@ -13,6 +13,7 @@ import (
"github.com/coreos/bbolt"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/routing/route"
)
var (
@ -145,7 +146,14 @@ func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
fetchNode := func(pub *btcec.PublicKey) (*channeldb.LightningNode, error) {
if pub != nil {
dbNode, err := d.db.FetchLightningNode(pub)
vertex, err := route.NewVertexFromBytes(
pub.SerializeCompressed(),
)
if err != nil {
return nil, err
}
dbNode, err := d.db.FetchLightningNode(vertex)
switch {
case err == channeldb.ErrGraphNodeNotFound:
fallthrough