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:
Elle Mouton committed 2024-09-25 11:14:35 +09:00
1 parent 84c91f701c
commit 7dc86acb8c
14 files changed
+87 -70

No files matched your search

+10 -12
View File
@@ -1367,7 +1367,7 @@ func TestNewRoute(t *testing.T) {
// overwrite the final hop's feature vector in the graph.
destFeatures *lnwire.FeatureVector
paymentAddr *[32]byte
paymentAddr fn.Option[[32]byte]
// metadata is the payment metadata to attach to the route.
metadata []byte
@@ -1446,7 +1446,7 @@ func TestNewRoute(t *testing.T) {
// a fee to receive the payment.
name: "two hop single shot mpp",
destFeatures: tlvPayAddrFeatures,
paymentAddr: &testPaymentAddr,
paymentAddr: fn.Some(testPaymentAddr),
paymentAmount: 100000,
hops: []*models.CachedEdgePolicy{
createHop(0, 1000, 1000000, 10),
@@ -1911,7 +1911,7 @@ func runDestPaymentAddr(t *testing.T, useCache bool) {
luoji := ctx.keyFromAlias("luoji")
// Add payment address w/o any invoice features.
ctx.restrictParams.PaymentAddr = &[32]byte{1}
ctx.restrictParams.PaymentAddr = fn.Some([32]byte{1})
// Add empty destination features. This should cause us to fail, since
// this overrides anything in the graph.
@@ -2955,7 +2955,7 @@ func runInboundFees(t *testing.T, useCache bool) {
ctx := newPathFindingTestContext(t, useCache, testChannels, "a")
payAddr := [32]byte{1}
ctx.restrictParams.PaymentAddr = &payAddr
ctx.restrictParams.PaymentAddr = fn.Some(payAddr)
ctx.restrictParams.DestFeatures = tlvPayAddrFeatures
const (
@@ -2974,7 +2974,7 @@ func runInboundFees(t *testing.T, useCache bool) {
amt: paymentAmt,
cltvDelta: finalHopCLTV,
records: nil,
paymentAddr: &payAddr,
paymentAddr: fn.Some(payAddr),
totalAmt: paymentAmt,
},
nil,
@@ -3469,7 +3469,7 @@ func TestLastHopPayloadSize(t *testing.T) {
{
name: "Non blinded final hop",
restrictions: &RestrictParams{
PaymentAddr: paymentAddr,
PaymentAddr: fn.Some(*paymentAddr),
DestCustomRecords: customRecords,
Metadata: metadata,
Amp: ampOptions,
@@ -3501,12 +3501,10 @@ func TestLastHopPayloadSize(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
var mpp *record.MPP
if tc.restrictions.PaymentAddr != nil {
mpp = record.NewMPP(
tc.amount, *tc.restrictions.PaymentAddr,
)
}
mpp := fn.MapOptionZ(tc.restrictions.PaymentAddr,
func(addr [32]byte) *record.MPP {
return record.NewMPP(tc.amount, addr)
})
// In case it's an AMP payment we use the max AMP record
// size to estimate the final hop size.