@@ -10,7 +10,6 @@ import (
10
10
"github.com/btcsuite/btcd/btcutil"
11
11
"github.com/lightningnetwork/lnd/chainreg"
12
12
"github.com/lightningnetwork/lnd/lnrpc"
13
- "github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
14
13
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
15
14
"github.com/lightningnetwork/lnd/lntest"
16
15
"github.com/lightningnetwork/lnd/lntest/node"
@@ -346,223 +345,6 @@ func testForwardInterceptorBasic(ht *lntest.HarnessTest) {
346
345
}
347
346
}
348
347
349
- // testForwardInterceptorModifiedHtlc tests that the interceptor can modify the
350
- // amount and custom records of an intercepted HTLC and resume it.
351
- func testForwardInterceptorModifiedHtlc (ht * lntest.HarnessTest ) {
352
- const chanAmt = btcutil .Amount (300000 )
353
- p := lntest.OpenChannelParams {Amt : chanAmt }
354
-
355
- // Initialize the test context with 3 connected nodes.
356
- cfgs := [][]string {nil , nil , nil }
357
-
358
- // Open and wait for channels.
359
- _ , nodes := ht .CreateSimpleNetwork (cfgs , p )
360
- alice , bob , carol := nodes [0 ], nodes [1 ], nodes [2 ]
361
-
362
- // Init the scenario.
363
- ts := & interceptorTestScenario {
364
- ht : ht ,
365
- alice : alice ,
366
- bob : bob ,
367
- carol : carol ,
368
- }
369
-
370
- // Connect an interceptor to Bob's node.
371
- bobInterceptor , cancelBobInterceptor := bob .RPC .HtlcInterceptor ()
372
-
373
- // We're going to modify the payment amount and want Carol to accept the
374
- // payment, so we set up an invoice acceptor on Dave.
375
- carolAcceptor , carolCancel := carol .RPC .InvoiceHtlcModifier ()
376
- defer carolCancel ()
377
-
378
- // Prepare the test cases.
379
- invoiceValueAmtMsat := int64 (20_000_000 )
380
- req := & lnrpc.Invoice {ValueMsat : invoiceValueAmtMsat }
381
- addResponse := carol .RPC .AddInvoice (req )
382
- invoice := carol .RPC .LookupInvoice (addResponse .RHash )
383
- tc := & interceptorTestCase {
384
- amountMsat : invoiceValueAmtMsat ,
385
- invoice : invoice ,
386
- payAddr : invoice .PaymentAddr ,
387
- }
388
-
389
- // We initiate a payment from Alice.
390
- done := make (chan struct {})
391
- go func () {
392
- // Signal that all the payments have been sent.
393
- defer close (done )
394
-
395
- ts .sendPaymentAndAssertAction (tc )
396
- }()
397
-
398
- // We start the htlc interceptor with a simple implementation that saves
399
- // all intercepted packets. These packets are held to simulate a
400
- // pending payment.
401
- packet := ht .ReceiveHtlcInterceptor (bobInterceptor )
402
-
403
- // Resume the intercepted HTLC with a modified amount and custom
404
- // records.
405
- customRecords := make (map [uint64 ][]byte )
406
-
407
- // Add custom records entry.
408
- crKey := uint64 (65537 )
409
- crValue := []byte ("custom-records-test-value" )
410
- customRecords [crKey ] = crValue
411
-
412
- // Modify the amount of the HTLC, so we send out less than the original
413
- // amount.
414
- const modifyAmount = 5_000_000
415
- newOutAmountMsat := packet .OutgoingAmountMsat - modifyAmount
416
- err := bobInterceptor .Send (& routerrpc.ForwardHtlcInterceptResponse {
417
- IncomingCircuitKey : packet .IncomingCircuitKey ,
418
- OutAmountMsat : newOutAmountMsat ,
419
- OutWireCustomRecords : customRecords ,
420
- Action : actionResumeModify ,
421
- })
422
- require .NoError (ht , err , "failed to send request" )
423
-
424
- invoicePacket := ht .ReceiveInvoiceHtlcModification (carolAcceptor )
425
- require .EqualValues (
426
- ht , newOutAmountMsat , invoicePacket .ExitHtlcAmt ,
427
- )
428
- amtPaid := newOutAmountMsat + modifyAmount
429
- err = carolAcceptor .Send (& invoicesrpc.HtlcModifyResponse {
430
- CircuitKey : invoicePacket .ExitHtlcCircuitKey ,
431
- AmtPaid : & amtPaid ,
432
- })
433
- require .NoError (ht , err , "carol acceptor response" )
434
-
435
- // Cancel the context, which will disconnect Bob's interceptor.
436
- cancelBobInterceptor ()
437
-
438
- // Make sure all goroutines are finished.
439
- select {
440
- case <- done :
441
- case <- time .After (defaultTimeout ):
442
- require .Fail (ht , "timeout waiting for sending payment" )
443
- }
444
-
445
- // Assert that the payment was successful.
446
- var preimage lntypes.Preimage
447
- copy (preimage [:], invoice .RPreimage )
448
- ht .AssertPaymentStatus (alice , preimage , lnrpc .Payment_SUCCEEDED )
449
- }
450
-
451
- // testForwardInterceptorWireRecords tests that the interceptor can read any
452
- // wire custom records provided by the sender of a payment as part of the
453
- // update_add_htlc message.
454
- func testForwardInterceptorWireRecords (ht * lntest.HarnessTest ) {
455
- const chanAmt = btcutil .Amount (300000 )
456
- p := lntest.OpenChannelParams {Amt : chanAmt }
457
-
458
- // Initialize the test context with 4 connected nodes.
459
- cfgs := [][]string {nil , nil , nil , nil }
460
-
461
- // Open and wait for channels.
462
- _ , nodes := ht .CreateSimpleNetwork (cfgs , p )
463
- alice , bob , carol , dave := nodes [0 ], nodes [1 ], nodes [2 ], nodes [3 ]
464
-
465
- // Connect an interceptor to Bob's node.
466
- bobInterceptor , cancelBobInterceptor := bob .RPC .HtlcInterceptor ()
467
- defer cancelBobInterceptor ()
468
-
469
- // Also connect an interceptor on Carol's node to check whether we're
470
- // relaying the TLVs send in update_add_htlc over Alice -> Bob on the
471
- // Bob -> Carol link.
472
- carolInterceptor , cancelCarolInterceptor := carol .RPC .HtlcInterceptor ()
473
- defer cancelCarolInterceptor ()
474
-
475
- // We're going to modify the payment amount and want Dave to accept the
476
- // payment, so we set up an invoice acceptor on Dave.
477
- daveAcceptor , daveCancel := dave .RPC .InvoiceHtlcModifier ()
478
- defer daveCancel ()
479
-
480
- req := & lnrpc.Invoice {ValueMsat : 20_000_000 }
481
- addResponse := dave .RPC .AddInvoice (req )
482
- invoice := dave .RPC .LookupInvoice (addResponse .RHash )
483
-
484
- customRecords := map [uint64 ][]byte {
485
- 65537 : []byte ("test" ),
486
- }
487
- sendReq := & routerrpc.SendPaymentRequest {
488
- PaymentRequest : invoice .PaymentRequest ,
489
- TimeoutSeconds : int32 (wait .PaymentTimeout .Seconds ()),
490
- FeeLimitMsat : noFeeLimitMsat ,
491
- FirstHopCustomRecords : customRecords ,
492
- }
493
- ht .SendPaymentAssertInflight (alice , sendReq )
494
-
495
- // We start the htlc interceptor with a simple implementation that saves
496
- // all intercepted packets. These packets are held to simulate a
497
- // pending payment.
498
- packet := ht .ReceiveHtlcInterceptor (bobInterceptor )
499
- require .Equal (ht , lntest .CustomRecordsWithUnendorsed (
500
- customRecords ,
501
- ), packet .InWireCustomRecords )
502
-
503
- // Just resume the payment on Bob.
504
- err := bobInterceptor .Send (& routerrpc.ForwardHtlcInterceptResponse {
505
- IncomingCircuitKey : packet .IncomingCircuitKey ,
506
- Action : actionResume ,
507
- })
508
- require .NoError (ht , err , "failed to send request" )
509
-
510
- // Assert that the Alice -> Bob custom records in update_add_htlc are
511
- // not propagated on the Bob -> Carol link, just an endorsement signal.
512
- packet = ht .ReceiveHtlcInterceptor (carolInterceptor )
513
- require .Equal (ht , lntest .CustomRecordsWithUnendorsed (nil ),
514
- packet .InWireCustomRecords )
515
-
516
- // We're going to tell Carol to forward 5k sats less to Dave. We need to
517
- // set custom records on the HTLC as well, to make sure the HTLC isn't
518
- // rejected outright and actually gets to the invoice acceptor.
519
- const modifyAmount = 5_000_000
520
- newOutAmountMsat := packet .OutgoingAmountMsat - modifyAmount
521
- err = carolInterceptor .Send (& routerrpc.ForwardHtlcInterceptResponse {
522
- IncomingCircuitKey : packet .IncomingCircuitKey ,
523
- OutAmountMsat : newOutAmountMsat ,
524
- OutWireCustomRecords : customRecords ,
525
- Action : actionResumeModify ,
526
- })
527
- require .NoError (ht , err , "carol interceptor response" )
528
-
529
- // The payment should get to Dave, and we should be able to intercept
530
- // and modify it, telling Dave to accept it.
531
- invoicePacket := ht .ReceiveInvoiceHtlcModification (daveAcceptor )
532
- require .EqualValues (
533
- ht , newOutAmountMsat , invoicePacket .ExitHtlcAmt ,
534
- )
535
- amtPaid := newOutAmountMsat + modifyAmount
536
- err = daveAcceptor .Send (& invoicesrpc.HtlcModifyResponse {
537
- CircuitKey : invoicePacket .ExitHtlcCircuitKey ,
538
- AmtPaid : & amtPaid ,
539
- })
540
- require .NoError (ht , err , "dave acceptor response" )
541
-
542
- // Assert that the payment was successful.
543
- var preimage lntypes.Preimage
544
- copy (preimage [:], invoice .RPreimage )
545
- ht .AssertPaymentStatus (
546
- alice , preimage , lnrpc .Payment_SUCCEEDED ,
547
- func (p * lnrpc.Payment ) error {
548
- recordsEqual := reflect .DeepEqual (
549
- p .FirstHopCustomRecords ,
550
- lntest .CustomRecordsWithUnendorsed (
551
- customRecords ,
552
- ),
553
- )
554
- if ! recordsEqual {
555
- return fmt .Errorf ("expected custom records to " +
556
- "be equal, got %v expected %v" ,
557
- p .FirstHopCustomRecords ,
558
- sendReq .FirstHopCustomRecords )
559
- }
560
-
561
- return nil
562
- },
563
- )
564
- }
565
-
566
348
// testForwardInterceptorRestart tests that the interceptor can read any wire
567
349
// custom records provided by the sender of a payment as part of the
568
350
// update_add_htlc message and that those records are persisted correctly and
0 commit comments