autopilot: update API usage to account for recent channeldb changes

This commit is contained in:
Olaoluwa Osuntokun 2018-01-30 20:23:56 -08:00
parent cd9d2d7e6f
commit cb48a5827a
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
2 changed files with 20 additions and 22 deletions

@ -9,6 +9,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"github.com/roasbeef/btcd/btcec" "github.com/roasbeef/btcd/btcec"
"github.com/roasbeef/btcd/wire" "github.com/roasbeef/btcd/wire"
"github.com/roasbeef/btcutil" "github.com/roasbeef/btcutil"

@ -63,7 +63,8 @@ var _ Node = (*dbNode)(nil)
// //
// NOTE: Part of the autopilot.Node interface. // NOTE: Part of the autopilot.Node interface.
func (d dbNode) PubKey() *btcec.PublicKey { func (d dbNode) PubKey() *btcec.PublicKey {
return d.node.PubKey pubKey, _ := d.node.PubKey()
return pubKey
} }
// Addrs returns a slice of publicly reachable public TCP addresses that the // Addrs returns a slice of publicly reachable public TCP addresses that the
@ -84,12 +85,13 @@ func (d dbNode) ForEachChannel(cb func(ChannelEdge) error) error {
return d.node.ForEachChannel(d.tx, func(tx *bolt.Tx, return d.node.ForEachChannel(d.tx, func(tx *bolt.Tx,
ei *channeldb.ChannelEdgeInfo, ep, _ *channeldb.ChannelEdgePolicy) error { ei *channeldb.ChannelEdgeInfo, ep, _ *channeldb.ChannelEdgePolicy) error {
pubkey, _ := ep.Node.PubKey()
edge := ChannelEdge{ edge := ChannelEdge{
Channel: Channel{ Channel: Channel{
ChanID: lnwire.NewShortChanIDFromInt(ep.ChannelID), ChanID: lnwire.NewShortChanIDFromInt(ep.ChannelID),
Capacity: ei.Capacity, Capacity: ei.Capacity,
FundedAmt: ei.Capacity, FundedAmt: ei.Capacity,
Node: NewNodeID(ep.Node.PubKey), Node: NewNodeID(pubkey),
}, },
Peer: dbNode{ Peer: dbNode{
tx: tx, tx: tx,
@ -138,7 +140,6 @@ func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
fallthrough fallthrough
case err == channeldb.ErrGraphNotFound: case err == channeldb.ErrGraphNotFound:
graphNode := &channeldb.LightningNode{ graphNode := &channeldb.LightningNode{
PubKey: pub,
HaveNodeAnnouncement: true, HaveNodeAnnouncement: true,
Addresses: []net.Addr{ Addresses: []net.Addr{
&net.TCPAddr{ &net.TCPAddr{
@ -147,8 +148,9 @@ func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
}, },
Features: lnwire.NewFeatureVector(nil, Features: lnwire.NewFeatureVector(nil,
lnwire.GlobalFeatures), lnwire.GlobalFeatures),
AuthSig: testSig, AuthSigBytes: testSig.Serialize(),
} }
graphNode.AddPubKey(pub)
if err := d.db.AddLightningNode(graphNode); err != nil { if err := d.db.AddLightningNode(graphNode); err != nil {
return nil, err return nil, err
} }
@ -164,7 +166,6 @@ func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
return nil, err return nil, err
} }
dbNode := &channeldb.LightningNode{ dbNode := &channeldb.LightningNode{
PubKey: nodeKey,
HaveNodeAnnouncement: true, HaveNodeAnnouncement: true,
Addresses: []net.Addr{ Addresses: []net.Addr{
&net.TCPAddr{ &net.TCPAddr{
@ -172,8 +173,9 @@ func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
}, },
}, },
Features: lnwire.NewFeatureVector(nil, lnwire.GlobalFeatures), Features: lnwire.NewFeatureVector(nil, lnwire.GlobalFeatures),
AuthSig: testSig, AuthSigBytes: testSig.Serialize(),
} }
dbNode.AddPubKey(nodeKey)
if err := d.db.AddLightningNode(dbNode); err != nil { if err := d.db.AddLightningNode(dbNode); err != nil {
return nil, err return nil, err
} }
@ -192,30 +194,25 @@ func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
} }
var lnNode1, lnNode2 *btcec.PublicKey var lnNode1, lnNode2 *btcec.PublicKey
node1Bytes := vertex1.PubKey.SerializeCompressed() if bytes.Compare(vertex1.PubKeyBytes[:], vertex2.PubKeyBytes[:]) == -1 {
node2Bytes := vertex2.PubKey.SerializeCompressed() lnNode1, _ = vertex1.PubKey()
if bytes.Compare(node1Bytes, node2Bytes) == -1 { lnNode2, _ = vertex2.PubKey()
lnNode1 = vertex1.PubKey
lnNode2 = vertex2.PubKey
} else { } else {
lnNode1 = vertex2.PubKey lnNode1, _ = vertex2.PubKey()
lnNode2 = vertex1.PubKey lnNode2, _ = vertex1.PubKey()
} }
chanID := randChanID() chanID := randChanID()
edge := &channeldb.ChannelEdgeInfo{ edge := &channeldb.ChannelEdgeInfo{
ChannelID: chanID.ToUint64(), ChannelID: chanID.ToUint64(),
NodeKey1: lnNode1,
NodeKey2: lnNode2,
BitcoinKey1: vertex1.PubKey,
BitcoinKey2: vertex2.PubKey,
Capacity: capacity, Capacity: capacity,
} }
edge.AddNodeKeys(lnNode1, lnNode2, lnNode1, lnNode2)
if err := d.db.AddChannelEdge(edge); err != nil { if err := d.db.AddChannelEdge(edge); err != nil {
return nil, nil, err return nil, nil, err
} }
edgePolicy := &channeldb.ChannelEdgePolicy{ edgePolicy := &channeldb.ChannelEdgePolicy{
Signature: testSig, SigBytes: testSig.Serialize(),
ChannelID: chanID.ToUint64(), ChannelID: chanID.ToUint64(),
LastUpdate: time.Now(), LastUpdate: time.Now(),
TimeLockDelta: 10, TimeLockDelta: 10,
@ -229,7 +226,7 @@ func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
return nil, nil, err return nil, nil, err
} }
edgePolicy = &channeldb.ChannelEdgePolicy{ edgePolicy = &channeldb.ChannelEdgePolicy{
Signature: testSig, SigBytes: testSig.Serialize(),
ChannelID: chanID.ToUint64(), ChannelID: chanID.ToUint64(),
LastUpdate: time.Now(), LastUpdate: time.Now(),
TimeLockDelta: 10, TimeLockDelta: 10,