Skip to content

Commit

Permalink
funding with asset: funding.TestFundingManagerNormalWorkflow
Browse files Browse the repository at this point in the history
  • Loading branch information
wxf4150 committed Apr 22, 2022
1 parent 7e84e9e commit d3eafab
Show file tree
Hide file tree
Showing 33 changed files with 692 additions and 278 deletions.
37 changes: 25 additions & 12 deletions autopilot/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package autopilot

import (
"bytes"
"github.com/lightningnetwork/lnd/lnwallet/omnicore"
"math/big"
"net"
"sort"
Expand Down Expand Up @@ -100,7 +101,9 @@ func (d dbNode) ForEachChannel(cb func(ChannelEdge) error) error {

edge := ChannelEdge{
ChanID: lnwire.NewShortChanIDFromInt(ep.ChannelID),
Capacity: ei.Capacity,
BtcCapacity: ei.BtcCapacity,
AssetCapacity: ei.AssetCapacity,
AsserId: ei.AssetId,
Peer: dbNode{
tx: tx,
node: ep.Node,
Expand Down Expand Up @@ -137,7 +140,7 @@ func (d *databaseChannelGraph) ForEachNode(cb func(Node) error) error {
// meant to aide in the generation of random graphs for use within test cases
// the exercise the autopilot package.
func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
capacity btcutil.Amount) (*ChannelEdge, *ChannelEdge, error) {
capacity btcutil.Amount,assetCapacity omnicore.Amount,assetId uint32) (*ChannelEdge, *ChannelEdge, error) {

fetchNode := func(pub *btcec.PublicKey) (*channeldb.LightningNode, error) {
if pub != nil {
Expand Down Expand Up @@ -222,7 +225,9 @@ func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
chanID := randChanID()
edge := &channeldb.ChannelEdgeInfo{
ChannelID: chanID.ToUint64(),
Capacity: capacity,
BtcCapacity: capacity,
AssetCapacity: assetCapacity,
AssetId: assetId,
}
edge.AddNodeKeys(lnNode1, lnNode2, lnNode1, lnNode2)
if err := d.db.AddChannelEdge(edge); err != nil {
Expand All @@ -233,8 +238,8 @@ func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
ChannelID: chanID.ToUint64(),
LastUpdate: time.Now(),
TimeLockDelta: 10,
MinHTLC: 1,
MaxHTLC: lnwire.NewMSatFromSatoshis(capacity),
MinBtcHTLC: 1,
MaxBtcHTLC: lnwire.NewMSatFromSatoshis(capacity),
FeeBaseMSat: 10,
FeeProportionalMillionths: 10000,
MessageFlags: 1,
Expand All @@ -249,8 +254,8 @@ func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
ChannelID: chanID.ToUint64(),
LastUpdate: time.Now(),
TimeLockDelta: 10,
MinHTLC: 1,
MaxHTLC: lnwire.NewMSatFromSatoshis(capacity),
MinBtcHTLC: 1,
MaxBtcHTLC: lnwire.NewMSatFromSatoshis(capacity),
FeeBaseMSat: 10,
FeeProportionalMillionths: 10000,
MessageFlags: 1,
Expand All @@ -262,14 +267,18 @@ func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,

return &ChannelEdge{
ChanID: chanID,
Capacity: capacity,
BtcCapacity: capacity,
AssetCapacity: assetCapacity,
AsserId: assetId,
Peer: dbNode{
node: vertex1,
},
},
&ChannelEdge{
ChanID: chanID,
Capacity: capacity,
BtcCapacity: capacity,
AssetCapacity: assetCapacity,
AsserId: assetId,
Peer: dbNode{
node: vertex2,
},
Expand Down Expand Up @@ -356,7 +365,7 @@ func randKey() (*btcec.PublicKey, error) {
// meant to aide in the generation of random graphs for use within test cases
// the exercise the autopilot package.
func (m *memChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
capacity btcutil.Amount) (*ChannelEdge, *ChannelEdge, error) {
capacity btcutil.Amount, assetCapacity omnicore.Amount,assetId uint32 ) (*ChannelEdge, *ChannelEdge, error) {

var (
vertex1, vertex2 *memNode
Expand Down Expand Up @@ -419,14 +428,18 @@ func (m *memChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,

edge1 := ChannelEdge{
ChanID: randChanID(),
Capacity: capacity,
BtcCapacity: capacity,
AssetCapacity: assetCapacity,
AsserId: assetId,
Peer: vertex2,
}
vertex1.chans = append(vertex1.chans, edge1)

edge2 := ChannelEdge{
ChanID: randChanID(),
Capacity: capacity,
BtcCapacity: capacity,
AssetCapacity: assetCapacity,
AsserId: assetId,
Peer: vertex1,
}
vertex2.chans = append(vertex2.chans, edge2)
Expand Down
5 changes: 4 additions & 1 deletion autopilot/interface.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package autopilot

import (
"github.com/lightningnetwork/lnd/lnwallet/omnicore"
"net"

"github.com/btcsuite/btcd/btcec"
Expand Down Expand Up @@ -64,7 +65,9 @@ type ChannelEdge struct {
ChanID lnwire.ShortChannelID

// Capacity is the capacity of the channel expressed in satoshis.
Capacity btcutil.Amount
BtcCapacity btcutil.Amount
AssetCapacity omnicore.Amount
AsserId uint32

// Peer is the peer that this channel creates an edge to in the channel
// graph.
Expand Down
4 changes: 2 additions & 2 deletions autopilot/prefattach.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (p *PrefAttachment) NodeScores(g ChannelGraph, chans []LocalChannel,
return nil
}
seenChans[e.ChanID.ToUint64()] = struct{}{}
allChans = append(allChans, e.Capacity)
allChans = append(allChans, e.BtcCapacity)
return nil
})
if err != nil {
Expand Down Expand Up @@ -122,7 +122,7 @@ func (p *PrefAttachment) NodeScores(g ChannelGraph, chans []LocalChannel,
// graph (we will potentially waste time trying to use
// these useless channels in path finding), we decrease
// the counter for such channels.
if e.Capacity < medianChanSize/minMedianChanSizeFraction {
if e.BtcCapacity < medianChanSize/minMedianChanSizeFraction {
nodeChans--
return nil
}
Expand Down
9 changes: 7 additions & 2 deletions chanacceptor/rpcacceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,13 @@ func (r *RPCAcceptor) sendAcceptRequests(errChan chan error,
NodePubkey: req.Node.SerializeCompressed(),
ChainHash: req.OpenChanMsg.ChainHash[:],
PendingChanId: req.OpenChanMsg.PendingChannelID[:],
FundingAmt: uint64(req.OpenChanMsg.FundingAmount),
PushAmt: uint64(req.OpenChanMsg.PushAmount),
FundingAmt: uint64(req.OpenChanMsg.FundingBtcAmount),
PushAmt: uint64(req.OpenChanMsg.PushBtcAmount),
/*obd update wxf
todo add asset
*/
//FundingAmt: uint64(req.OpenChanMsg.FundingAssetAmount),
//PushAmt: uint64(req.OpenChanMsg.PushAssetAmount),
DustLimit: uint64(req.OpenChanMsg.DustLimit),
MaxValueInFlight: uint64(req.OpenChanMsg.MaxValueInFlight),
ChannelReserve: uint64(req.OpenChanMsg.ChannelReserve),
Expand Down
70 changes: 58 additions & 12 deletions channeldb/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/binary"
"errors"
"fmt"
"github.com/lightningnetwork/lnd/lnwallet/omnicore"
"image/color"
"io"
"math"
Expand Down Expand Up @@ -492,7 +493,10 @@ func (c *ChannelGraph) ForEachNodeChannel(tx kvdb.RTx, node route.Vertex,
ChannelID: e.ChannelID,
IsNode1: node == e.NodeKey1Bytes,
OtherNode: e.NodeKey2Bytes,
Capacity: e.Capacity,
/*obd add wxf*/
BtcCapacity: e.BtcCapacity,
AssetCapacity: e.AssetCapacity,
AssetId: e.AssetId,
OutPolicySet: p1 != nil,
InPolicy: cachedInPolicy,
}
Expand Down Expand Up @@ -578,7 +582,9 @@ func (c *ChannelGraph) ForEachNodeCached(cb func(node route.Vertex,
ChannelID: e.ChannelID,
IsNode1: node.PubKeyBytes == e.NodeKey1Bytes,
OtherNode: e.NodeKey2Bytes,
Capacity: e.Capacity,
BtcCapacity: e.BtcCapacity,
AssetCapacity: e.AssetCapacity,
AssetId: e.AssetId,
OutPolicySet: p1 != nil,
InPolicy: cachedInPolicy,
}
Expand Down Expand Up @@ -3061,9 +3067,14 @@ type ChannelEdgeInfo struct {
// used to uniquely identify the channel within the channel graph.
ChannelPoint wire.OutPoint

/*
obd update wxf
*/
// Capacity is the total capacity of the channel, this is determined by
// the value output in the outpoint that created this channel.
Capacity btcutil.Amount
BtcCapacity btcutil.Amount
AssetCapacity omnicore.Amount
AssetId uint32

// ExtraOpaqueData is the set of data that was appended to this
// message, some of which we may not actually know how to iterate or
Expand Down Expand Up @@ -3408,11 +3419,16 @@ type ChannelEdgePolicy struct {

// MinHTLC is the smallest value HTLC this node will forward, expressed
// in millisatoshi.
MinHTLC lnwire.MilliSatoshi
MinBtcHTLC lnwire.MilliSatoshi

// MaxHTLC is the largest value HTLC this node will forward, expressed
// in millisatoshi.
MaxHTLC lnwire.MilliSatoshi
MaxBtcHTLC lnwire.MilliSatoshi
/*obd add wxf
*/
MinAssetHTLC omnicore.Amount
MaxAssetHTLC omnicore.Amount
AssetId uint32

// FeeBaseMSat is the base HTLC fee that will be charged for forwarding
// ANY HTLC, expressed in mSAT's.
Expand Down Expand Up @@ -4358,7 +4374,13 @@ func putChanEdgeInfo(edgeIndex kvdb.RwBucket, edgeInfo *ChannelEdgeInfo, chanID
if err := writeOutpoint(&b, &edgeInfo.ChannelPoint); err != nil {
return err
}
if err := binary.Write(&b, byteOrder, uint64(edgeInfo.Capacity)); err != nil {
if err := binary.Write(&b, byteOrder, uint64(edgeInfo.BtcCapacity)); err != nil {
return err
}
if err := binary.Write(&b, byteOrder, uint64(edgeInfo.AssetCapacity)); err != nil {
return err
}
if err := binary.Write(&b, byteOrder, uint32(edgeInfo.AssetId)); err != nil {
return err
}
if _, err := b.Write(chanID[:]); err != nil {
Expand Down Expand Up @@ -4442,7 +4464,13 @@ func deserializeChanEdgeInfo(r io.Reader) (ChannelEdgeInfo, error) {
if err := readOutpoint(r, &edgeInfo.ChannelPoint); err != nil {
return ChannelEdgeInfo{}, err
}
if err := binary.Read(r, byteOrder, &edgeInfo.Capacity); err != nil {
if err := binary.Read(r, byteOrder, &edgeInfo.BtcCapacity); err != nil {
return ChannelEdgeInfo{}, err
}
if err := binary.Read(r, byteOrder, &edgeInfo.AssetCapacity); err != nil {
return ChannelEdgeInfo{}, err
}
if err := binary.Read(r, byteOrder, &edgeInfo.AssetId); err != nil {
return ChannelEdgeInfo{}, err
}
if err := binary.Read(r, byteOrder, &edgeInfo.ChannelID); err != nil {
Expand Down Expand Up @@ -4690,7 +4718,10 @@ func serializeChanEdgePolicy(w io.Writer, edge *ChannelEdgePolicy,
if err := binary.Write(w, byteOrder, edge.TimeLockDelta); err != nil {
return err
}
if err := binary.Write(w, byteOrder, uint64(edge.MinHTLC)); err != nil {
if err := binary.Write(w, byteOrder, uint64(edge.MinBtcHTLC)); err != nil {
return err
}
if err := binary.Write(w, byteOrder, uint64(edge.MinAssetHTLC)); err != nil {
return err
}
if err := binary.Write(w, byteOrder, uint64(edge.FeeBaseMSat)); err != nil {
Expand All @@ -4710,7 +4741,12 @@ func serializeChanEdgePolicy(w io.Writer, edge *ChannelEdgePolicy,
// TODO(halseth): clean up when moving to TLV.
var opaqueBuf bytes.Buffer
if edge.MessageFlags.HasMaxHtlc() {
err := binary.Write(&opaqueBuf, byteOrder, uint64(edge.MaxHTLC))
err := binary.Write(&opaqueBuf, byteOrder, uint64(edge.MaxBtcHTLC))
if err != nil {
return err
}
/*obd add wxf*/
err = binary.Write(&opaqueBuf, byteOrder, uint64(edge.MaxAssetHTLC))
if err != nil {
return err
}
Expand Down Expand Up @@ -4786,7 +4822,14 @@ func deserializeChanEdgePolicyRaw(r io.Reader) (*ChannelEdgePolicy, error) {
if err := binary.Read(r, byteOrder, &n); err != nil {
return nil, err
}
edge.MinHTLC = lnwire.MilliSatoshi(n)
edge.MinBtcHTLC = lnwire.MilliSatoshi(n)

/*obd add wxf*/
var minAssetHtlc uint64
if err := binary.Read(r, byteOrder, &minAssetHtlc); err != nil {
return nil, err
}
edge.MinAssetHTLC = omnicore.Amount(minAssetHtlc)

if err := binary.Read(r, byteOrder, &n); err != nil {
return nil, err
Expand Down Expand Up @@ -4831,8 +4874,11 @@ func deserializeChanEdgePolicyRaw(r io.Reader) (*ChannelEdgePolicy, error) {
return edge, ErrEdgePolicyOptionalFieldNotFound
}

maxHtlc := byteOrder.Uint64(opq[:8])
edge.MaxHTLC = lnwire.MilliSatoshi(maxHtlc)
/*obd update wxf*/
maxBtcHtlc := byteOrder.Uint64(opq[:8])
edge.MaxBtcHTLC = lnwire.MilliSatoshi(maxBtcHtlc)
maxAssetHtlc := byteOrder.Uint64(opq[8:16])
edge.MaxAssetHTLC = omnicore.Amount(maxAssetHtlc)

// Exclude the parsed field from the rest of the opaque data.
edge.ExtraOpaqueData = opq[8:]
Expand Down
Loading

0 comments on commit d3eafab

Please sign in to comment.