@@ -3413,32 +3413,48 @@ func TestLastHopPayloadSize(t *testing.T) {
3413
3413
customRecords = map [uint64 ][]byte {
3414
3414
record .CustomTypeStart : {1 , 2 , 3 },
3415
3415
}
3416
- sizeEncryptedData = 100
3417
- encrypedData = bytes .Repeat (
3418
- []byte {1 }, sizeEncryptedData ,
3416
+
3417
+ encrypedDataSmall = bytes .Repeat (
3418
+ []byte {1 }, 5 ,
3419
+ )
3420
+ encrypedDataLarge = bytes .Repeat (
3421
+ []byte {1 }, 100 ,
3419
3422
)
3420
- _ , blindedPoint = btcec .PrivKeyFromBytes ([]byte {5 })
3421
- paymentAddr = & [32 ]byte {1 }
3422
- ampOptions = & AMPOptions {}
3423
- amtToForward = lnwire .MilliSatoshi (10000 )
3424
- finalHopExpiry int32 = 144
3423
+ _ , blindedPoint = btcec .PrivKeyFromBytes ([]byte {5 })
3424
+ paymentAddr = & [32 ]byte {1 }
3425
+ ampOptions = & AMPOptions {}
3426
+ amtToForward = lnwire .MilliSatoshi (10000 )
3427
+ emptyEncryptedData = []byte {}
3428
+ finalHopExpiry int32 = 144
3425
3429
3426
3430
oneHopPath = & sphinx.BlindedPath {
3427
3431
BlindedHops : []* sphinx.BlindedHopInfo {
3428
3432
{
3429
- CipherText : encrypedData ,
3433
+ CipherText : emptyEncryptedData ,
3434
+ },
3435
+ },
3436
+ BlindingPoint : blindedPoint ,
3437
+ }
3438
+
3439
+ twoHopPathSmallHopSize = & sphinx.BlindedPath {
3440
+ BlindedHops : []* sphinx.BlindedHopInfo {
3441
+ {
3442
+ CipherText : encrypedDataLarge ,
3443
+ },
3444
+ {
3445
+ CipherText : encrypedDataLarge ,
3430
3446
},
3431
3447
},
3432
3448
BlindingPoint : blindedPoint ,
3433
3449
}
3434
3450
3435
- twoHopPath = & sphinx.BlindedPath {
3451
+ twoHopPathLargeHopSize = & sphinx.BlindedPath {
3436
3452
BlindedHops : []* sphinx.BlindedHopInfo {
3437
3453
{
3438
- CipherText : encrypedData ,
3454
+ CipherText : encrypedDataSmall ,
3439
3455
},
3440
3456
{
3441
- CipherText : encrypedData ,
3457
+ CipherText : encrypedDataSmall ,
3442
3458
},
3443
3459
},
3444
3460
BlindingPoint : blindedPoint ,
@@ -3451,15 +3467,19 @@ func TestLastHopPayloadSize(t *testing.T) {
3451
3467
require .NoError (t , err )
3452
3468
3453
3469
twoHopBlindedPayment , err := NewBlindedPaymentPathSet (
3454
- []* BlindedPayment {{BlindedPath : twoHopPath }},
3470
+ []* BlindedPayment {
3471
+ {BlindedPath : twoHopPathLargeHopSize },
3472
+ {BlindedPath : twoHopPathSmallHopSize },
3473
+ },
3455
3474
)
3456
3475
require .NoError (t , err )
3457
3476
3458
3477
testCases := []struct {
3459
- name string
3460
- restrictions * RestrictParams
3461
- finalHopExpiry int32
3462
- amount lnwire.MilliSatoshi
3478
+ name string
3479
+ restrictions * RestrictParams
3480
+ finalHopExpiry int32
3481
+ amount lnwire.MilliSatoshi
3482
+ expectedEncryptedData []byte
3463
3483
}{
3464
3484
{
3465
3485
name : "Non blinded final hop" ,
@@ -3477,16 +3497,18 @@ func TestLastHopPayloadSize(t *testing.T) {
3477
3497
restrictions : & RestrictParams {
3478
3498
BlindedPaymentPathSet : oneHopBlindedPayment ,
3479
3499
},
3480
- amount : amtToForward ,
3481
- finalHopExpiry : finalHopExpiry ,
3500
+ amount : amtToForward ,
3501
+ finalHopExpiry : finalHopExpiry ,
3502
+ expectedEncryptedData : emptyEncryptedData ,
3482
3503
},
3483
3504
{
3484
3505
name : "Blinded final hop of a two hop payment" ,
3485
3506
restrictions : & RestrictParams {
3486
3507
BlindedPaymentPathSet : twoHopBlindedPayment ,
3487
3508
},
3488
- amount : amtToForward ,
3489
- finalHopExpiry : finalHopExpiry ,
3509
+ amount : amtToForward ,
3510
+ finalHopExpiry : finalHopExpiry ,
3511
+ expectedEncryptedData : encrypedDataLarge ,
3490
3512
},
3491
3513
}
3492
3514
@@ -3510,16 +3532,23 @@ func TestLastHopPayloadSize(t *testing.T) {
3510
3532
3511
3533
var finalHop route.Hop
3512
3534
if tc .restrictions .BlindedPaymentPathSet != nil {
3513
- path := tc .restrictions .BlindedPaymentPathSet .
3514
- LargestLastHopPayloadPath ()
3535
+ bPSet := tc .restrictions .BlindedPaymentPathSet
3536
+ path , err := bPSet .LargestLastHopPayloadPath ()
3537
+ require .NotNil (t , path )
3538
+
3539
+ require .NoError (t , err )
3540
+
3515
3541
blindedPath := path .BlindedPath .BlindedHops
3516
3542
blindedPoint := path .BlindedPath .BlindingPoint
3543
+ lastHop := blindedPath [len (blindedPath )- 1 ]
3544
+ require .Equal (t , lastHop .CipherText ,
3545
+ tc .expectedEncryptedData )
3517
3546
3518
3547
//nolint:ll
3519
3548
finalHop = route.Hop {
3520
3549
AmtToForward : tc .amount ,
3521
3550
OutgoingTimeLock : uint32 (tc .finalHopExpiry ),
3522
- EncryptedData : blindedPath [ len ( blindedPath ) - 1 ] .CipherText ,
3551
+ EncryptedData : lastHop .CipherText ,
3523
3552
}
3524
3553
if len (blindedPath ) == 1 {
3525
3554
finalHop .BlindingPoint = blindedPoint
@@ -3539,11 +3568,11 @@ func TestLastHopPayloadSize(t *testing.T) {
3539
3568
payLoad , err := createHopPayload (finalHop , 0 , true )
3540
3569
require .NoErrorf (t , err , "failed to create hop payload" )
3541
3570
3542
- expectedPayloadSize := lastHopPayloadSize (
3571
+ expectedPayloadSize , err := lastHopPayloadSize (
3543
3572
tc .restrictions , tc .finalHopExpiry ,
3544
3573
tc .amount ,
3545
3574
)
3546
-
3575
+ require . NoError ( t , err )
3547
3576
require .Equal (
3548
3577
t , expectedPayloadSize ,
3549
3578
uint64 (payLoad .NumBytes ()),
0 commit comments