multi: Fix final hop payload size for AMP payments.
This commit is contained in:
7 files changed
+44
-1
No files matched your search
@@ -408,6 +408,11 @@ type RestrictParams struct {
|
||||
// invoices.
|
||||
PaymentAddr *[32]byte
|
||||
|
||||
// Amp signals to the pathfinder that this payment is an AMP payment
|
||||
// and therefore it needs to account for additional AMP data in the
|
||||
// final hop payload size calculation.
|
||||
Amp *AMPOptions
|
||||
|
||||
// Metadata is additional data that is sent along with the payment to
|
||||
// the payee.
|
||||
Metadata []byte
|
||||
@@ -1134,12 +1139,21 @@ func lastHopPayloadSize(r *RestrictParams, finalHtlcExpiry int32,
|
||||
mpp = record.NewMPP(amount, *r.PaymentAddr)
|
||||
}
|
||||
|
||||
var amp *record.AMP
|
||||
if r.Amp != nil {
|
||||
// The AMP payload is not easy accessible at this point but we
|
||||
// are only interested in the size of the payload so we just use
|
||||
// the AMP record dummy.
|
||||
amp = &record.MaxAmpPayLoadSize
|
||||
}
|
||||
|
||||
finalHop := route.Hop{
|
||||
AmtToForward: amount,
|
||||
OutgoingTimeLock: uint32(finalHtlcExpiry),
|
||||
CustomRecords: r.DestCustomRecords,
|
||||
LegacyPayload: legacy,
|
||||
MPP: mpp,
|
||||
AMP: amp,
|
||||
Metadata: r.Metadata,
|
||||
}
|
||||
|
||||
|
||||
@@ -3469,6 +3469,7 @@ func TestLastHopPayloadSize(t *testing.T) {
|
||||
)
|
||||
_, blindedPoint = btcec.PrivKeyFromBytes([]byte{5})
|
||||
paymentAddr = &[32]byte{1}
|
||||
ampOptions = &Options{}
|
||||
amtToForward = lnwire.MilliSatoshi(10000)
|
||||
finalHopExpiry int32 = 144
|
||||
|
||||
@@ -3510,6 +3511,7 @@ func TestLastHopPayloadSize(t *testing.T) {
|
||||
PaymentAddr: paymentAddr,
|
||||
DestCustomRecords: customRecords,
|
||||
Metadata: metadata,
|
||||
Amp: ampOptions,
|
||||
},
|
||||
amount: amtToForward,
|
||||
finalHopExpiry: finalHopExpiry,
|
||||
@@ -3524,6 +3526,7 @@ func TestLastHopPayloadSize(t *testing.T) {
|
||||
PaymentAddr: paymentAddr,
|
||||
DestCustomRecords: customRecords,
|
||||
Metadata: metadata,
|
||||
Amp: ampOptions,
|
||||
},
|
||||
amount: amtToForward,
|
||||
finalHopExpiry: finalHopExpiry,
|
||||
@@ -3560,6 +3563,13 @@ func TestLastHopPayloadSize(t *testing.T) {
|
||||
)
|
||||
}
|
||||
|
||||
// In case it's an AMP payment we use the max AMP record
|
||||
// size to estimate the final hop size.
|
||||
var amp *record.AMP
|
||||
if tc.restrictions.Amp != nil {
|
||||
amp = &record.MaxAmpPayLoadSize
|
||||
}
|
||||
|
||||
var finalHop route.Hop
|
||||
if tc.restrictions.BlindedPayment != nil {
|
||||
blindedPath := tc.restrictions.BlindedPayment.
|
||||
@@ -3586,6 +3596,7 @@ func TestLastHopPayloadSize(t *testing.T) {
|
||||
OutgoingTimeLock: uint32(tc.finalHopExpiry),
|
||||
Metadata: tc.restrictions.Metadata,
|
||||
MPP: mpp,
|
||||
AMP: amp,
|
||||
CustomRecords: tc.restrictions.DestCustomRecords,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -628,7 +628,7 @@ func (p *paymentLifecycle) createNewPaymentAttempt(rt *route.Route,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// It this shard carries MPP or AMP options, add them to the last hop
|
||||
// If this shard carries MPP or AMP options, add them to the last hop
|
||||
// on the route.
|
||||
hop := rt.Hops[len(rt.Hops)-1]
|
||||
if shard.MPP() != nil {
|
||||
|
||||
@@ -258,6 +258,7 @@ func (p *paymentSession) RequestRoute(maxAmt, feeLimit lnwire.MilliSatoshi,
|
||||
DestCustomRecords: p.payment.DestCustomRecords,
|
||||
DestFeatures: p.payment.DestFeatures,
|
||||
PaymentAddr: p.payment.PaymentAddr,
|
||||
Amp: p.payment.amp,
|
||||
Metadata: p.payment.Metadata,
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user