autopilot: update API usage to account for recent channeldb changes
This commit is contained in:
parent
cd9d2d7e6f
commit
cb48a5827a
@ -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,16 +166,16 @@ 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{
|
||||||
IP: bytes.Repeat([]byte("a"), 16),
|
IP: bytes.Repeat([]byte("a"), 16),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
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,
|
Capacity: capacity,
|
||||||
NodeKey2: lnNode2,
|
|
||||||
BitcoinKey1: vertex1.PubKey,
|
|
||||||
BitcoinKey2: vertex2.PubKey,
|
|
||||||
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,
|
||||||
|
Loading…
Reference in New Issue
Block a user