multi: do not use tlv.Record outside wire format handling
This commit prepares for more manipulation of custom records. A list of tlv.Record types is more difficult to use than the more basic map[uint64][]byte. Furthermore fields and variables are renamed to make them more consistent.
This commit is contained in:
9 files changed
+46
-127
No files matched your search
+4
-4
@@ -11,8 +11,8 @@ import (
|
||||
"github.com/coreos/bbolt"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/record"
|
||||
"github.com/lightningnetwork/lnd/routing/route"
|
||||
"github.com/lightningnetwork/lnd/tlv"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -100,7 +100,7 @@ type edgePolicyWithSource struct {
|
||||
func newRoute(amtToSend lnwire.MilliSatoshi, sourceVertex route.Vertex,
|
||||
pathEdges []*channeldb.ChannelEdgePolicy, currentHeight uint32,
|
||||
finalCLTVDelta uint16,
|
||||
finalDestRecords []tlv.Record) (*route.Route, error) {
|
||||
destCustomRecords record.CustomSet) (*route.Route, error) {
|
||||
|
||||
var (
|
||||
hops []*route.Hop
|
||||
@@ -198,8 +198,8 @@ func newRoute(amtToSend lnwire.MilliSatoshi, sourceVertex route.Vertex,
|
||||
|
||||
// If this is the last hop, then we'll populate any TLV records
|
||||
// destined for it.
|
||||
if i == len(pathEdges)-1 && len(finalDestRecords) != 0 {
|
||||
currentHop.TLVRecords = finalDestRecords
|
||||
if i == len(pathEdges)-1 && len(destCustomRecords) != 0 {
|
||||
currentHop.CustomRecords = destCustomRecords
|
||||
}
|
||||
|
||||
hops = append([]*route.Hop{currentHop}, hops...)
|
||||
|
||||
@@ -129,7 +129,7 @@ func (p *paymentSession) RequestRoute(payment *LightningPayment,
|
||||
sourceVertex := route.Vertex(ss.SelfNode.PubKeyBytes)
|
||||
route, err := newRoute(
|
||||
payment.Amount, sourceVertex, path, height, finalCltvDelta,
|
||||
payment.FinalDestRecords,
|
||||
payment.DestCustomRecords,
|
||||
)
|
||||
if err != nil {
|
||||
// TODO(roasbeef): return which edge/vertex didn't work
|
||||
|
||||
@@ -107,9 +107,9 @@ type Hop struct {
|
||||
// only be set for the final hop.
|
||||
MPP *record.MPP
|
||||
|
||||
// TLVRecords if non-nil are a set of additional TLV records that
|
||||
// CustomRecords if non-nil are a set of additional TLV records that
|
||||
// should be included in the forwarding instructions for this node.
|
||||
TLVRecords []tlv.Record
|
||||
CustomRecords record.CustomSet
|
||||
|
||||
// LegacyPayload if true, then this signals that this node doesn't
|
||||
// understand the new TLV payload, so we must instead use the legacy
|
||||
@@ -165,7 +165,8 @@ func (h *Hop) PackHopPayload(w io.Writer, nextChanID uint64) error {
|
||||
}
|
||||
|
||||
// Append any custom types destined for this hop.
|
||||
records = append(records, h.TLVRecords...)
|
||||
tlvRecords := tlv.MapToRecords(h.CustomRecords)
|
||||
records = append(records, tlvRecords...)
|
||||
|
||||
// To ensure we produce a canonical stream, we'll sort the records
|
||||
// before encoding them as a stream in the hop payload.
|
||||
|
||||
+5
-5
@@ -24,10 +24,10 @@ import (
|
||||
"github.com/lightningnetwork/lnd/lnwallet/chanvalidate"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/multimutex"
|
||||
"github.com/lightningnetwork/lnd/record"
|
||||
"github.com/lightningnetwork/lnd/routing/chainview"
|
||||
"github.com/lightningnetwork/lnd/routing/route"
|
||||
"github.com/lightningnetwork/lnd/ticker"
|
||||
"github.com/lightningnetwork/lnd/tlv"
|
||||
"github.com/lightningnetwork/lnd/zpay32"
|
||||
)
|
||||
|
||||
@@ -1401,7 +1401,7 @@ type routingMsg struct {
|
||||
// factoring in channel capacities and cumulative fees along the route.
|
||||
func (r *ChannelRouter) FindRoute(source, target route.Vertex,
|
||||
amt lnwire.MilliSatoshi, restrictions *RestrictParams,
|
||||
destTlvRecords []tlv.Record,
|
||||
destCustomRecords record.CustomSet,
|
||||
finalExpiry ...uint16) (*route.Route, error) {
|
||||
|
||||
var finalCLTVDelta uint16
|
||||
@@ -1455,7 +1455,7 @@ func (r *ChannelRouter) FindRoute(source, target route.Vertex,
|
||||
// Create the route with absolute time lock values.
|
||||
route, err := newRoute(
|
||||
amt, source, path, uint32(currentHeight), finalCLTVDelta,
|
||||
destTlvRecords,
|
||||
destCustomRecords,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -1608,11 +1608,11 @@ type LightningPayment struct {
|
||||
// attempting to complete.
|
||||
PaymentRequest []byte
|
||||
|
||||
// FinalDestRecords are TLV records that are to be sent to the final
|
||||
// DestCustomRecords are TLV records that are to be sent to the final
|
||||
// hop in the new onion payload format. If the destination does not
|
||||
// understand this new onion payload format, then the payment will
|
||||
// fail.
|
||||
FinalDestRecords []tlv.Record
|
||||
DestCustomRecords record.CustomSet
|
||||
}
|
||||
|
||||
// SendPayment attempts to send a payment as described within the passed
|
||||
|
||||
Reference in new issue
Block a user