routing/pathfind: set single-shot MPP if payment addr is known

This commit is contained in:
Conner Fromknecht committed 2019-12-18 23:56:42 -08:00
1 parent 7965cb08db
commit 0993256b77
2 files changed
+62 -8

No files matched your search

+22 -4
View File
@@ -99,11 +99,12 @@ type edgePolicyWithSource struct {
// finalHopParams encapsulates various parameters for route construction that
// apply to the final hop in a route. These features include basic payment data
// such as amounts and cltvs, as well as more complex features like destination
// custom records.
// custom records and payment address.
type finalHopParams struct {
amt lnwire.MilliSatoshi
cltvDelta uint16
records record.CustomSet
amt lnwire.MilliSatoshi
cltvDelta uint16
records record.CustomSet
paymentAddr *[32]byte
}
// newRoute constructs a route using the provided path and final hop constraints.
@@ -152,6 +153,7 @@ func newRoute(sourceVertex route.Vertex,
outgoingTimeLock uint32
tlvPayload bool
customRecords record.CustomSet
mpp *record.MPP
)
// Define a helper function that checks this edge's feature
@@ -191,6 +193,21 @@ func newRoute(sourceVertex route.Vertex,
"custom records")
}
customRecords = finalHop.records
// If we're attaching a payment addr but the receiver
// doesn't support both TLV and payment addrs, fail.
payAddr := supports(lnwire.PaymentAddrOptional)
if !payAddr && finalHop.paymentAddr != nil {
return nil, errors.New("cannot attach " +
"payment addr")
}
// Otherwise attach the mpp record if it exists.
if finalHop.paymentAddr != nil {
mpp = record.NewMPP(
finalHop.amt, *finalHop.paymentAddr,
)
}
} else {
// The amount that the current hop needs to forward is
// equal to the incoming amount of the next hop.
@@ -220,6 +237,7 @@ func newRoute(sourceVertex route.Vertex,
OutgoingTimeLock: outgoingTimeLock,
LegacyPayload: !tlvPayload,
CustomRecords: customRecords,
MPP: mpp,
}
hops = append([]*route.Hop{currentHop}, hops...)