mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-27 14:11:04 +02:00
multi: update PaymentAddr to use fn.Option
Since it is allowed to not be set and so can lead to nil deref panics if it is a pointer.
This commit is contained in:
@@ -111,7 +111,7 @@ type finalHopParams struct {
|
||||
cltvDelta uint16
|
||||
|
||||
records record.CustomSet
|
||||
paymentAddr *[32]byte
|
||||
paymentAddr fn.Option[[32]byte]
|
||||
|
||||
// metadata is additional data that is sent along with the payment to
|
||||
// the payee.
|
||||
@@ -226,7 +226,7 @@ func newRoute(sourceVertex route.Vertex,
|
||||
// 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 {
|
||||
if !payAddr && finalHop.paymentAddr.IsSome() {
|
||||
return nil, errors.New("cannot attach " +
|
||||
"payment addr")
|
||||
}
|
||||
@@ -234,12 +234,9 @@ func newRoute(sourceVertex route.Vertex,
|
||||
// Otherwise attach the mpp record if it exists.
|
||||
// TODO(halseth): move this to payment life cycle,
|
||||
// where AMP options are set.
|
||||
if finalHop.paymentAddr != nil {
|
||||
mpp = record.NewMPP(
|
||||
finalHop.totalAmt,
|
||||
*finalHop.paymentAddr,
|
||||
)
|
||||
}
|
||||
finalHop.paymentAddr.WhenSome(func(addr [32]byte) {
|
||||
mpp = record.NewMPP(finalHop.totalAmt, addr)
|
||||
})
|
||||
|
||||
metadata = finalHop.metadata
|
||||
|
||||
@@ -452,7 +449,7 @@ type RestrictParams struct {
|
||||
// PaymentAddr is a random 32-byte value generated by the receiver to
|
||||
// mitigate probing vectors and payment sniping attacks on overpaid
|
||||
// invoices.
|
||||
PaymentAddr *[32]byte
|
||||
PaymentAddr fn.Option[[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
|
||||
@@ -608,7 +605,7 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig,
|
||||
// checking that it supports the features we need. If the caller has a
|
||||
// payment address to attach, check that our destination feature vector
|
||||
// supports them.
|
||||
if r.PaymentAddr != nil &&
|
||||
if r.PaymentAddr.IsSome() &&
|
||||
!features.HasFeature(lnwire.PaymentAddrOptional) {
|
||||
|
||||
return nil, 0, errNoPaymentAddr
|
||||
@@ -1435,9 +1432,9 @@ func lastHopPayloadSize(r *RestrictParams, finalHtlcExpiry int32,
|
||||
}
|
||||
|
||||
var mpp *record.MPP
|
||||
if r.PaymentAddr != nil {
|
||||
mpp = record.NewMPP(amount, *r.PaymentAddr)
|
||||
}
|
||||
r.PaymentAddr.WhenSome(func(addr [32]byte) {
|
||||
mpp = record.NewMPP(amount, addr)
|
||||
})
|
||||
|
||||
var amp *record.AMP
|
||||
if r.Amp != nil {
|
||||
|
Reference in New Issue
Block a user