@@ -50,6 +50,7 @@ use crate::ln::functional_test_utils::*;
50
50
use crate :: ln:: onion_utils:: { construct_trampoline_onion_keys, construct_trampoline_onion_packet} ;
51
51
52
52
use super :: msgs:: OnionErrorPacket ;
53
+ use super :: onion_utils:: AttributionData ;
53
54
54
55
fn run_onion_failure_test < F1 , F2 > ( _name : & str , test_case : u8 , nodes : & Vec < Node > , route : & Route , payment_hash : & PaymentHash , payment_secret : & PaymentSecret , callback_msg : F1 , callback_node : F2 , expected_retryable : bool , expected_error_code : Option < u16 > , expected_channel_update : Option < NetworkUpdate > , expected_short_channel_id : Option < u64 > , expected_htlc_destination : Option < HTLCDestination > )
55
56
where F1 : for < ' a > FnMut ( & ' a mut msgs:: UpdateAddHTLC ) ,
@@ -411,17 +412,19 @@ fn test_onion_failure() {
411
412
// and tamper returning error message
412
413
let session_priv = SecretKey :: from_slice ( & [ 3 ; 32 ] ) . unwrap ( ) ;
413
414
let onion_keys = onion_utils:: construct_onion_keys ( & Secp256k1 :: new ( ) , & route. paths [ 0 ] , & session_priv) . unwrap ( ) ;
414
- let failure = onion_utils:: build_failure_packet ( onion_keys[ 0 ] . shared_secret . as_ref ( ) , NODE |2 , & [ 0 ; 0 ] ) ;
415
+ let failure = onion_utils:: build_failure_packet ( onion_keys[ 0 ] . shared_secret . as_ref ( ) , NODE |2 , & [ 0 ; 0 ] , 0 ) ;
415
416
msg. reason = failure. data ;
417
+ msg. attribution_data = failure. attribution_data ;
416
418
} , ||{ } , true , Some ( NODE |2 ) , Some ( NetworkUpdate :: NodeFailure { node_id : route. paths [ 0 ] . hops [ 0 ] . pubkey , is_permanent : false } ) , Some ( route. paths [ 0 ] . hops [ 0 ] . short_channel_id ) , Some ( next_hop_failure. clone ( ) ) ) ;
417
419
418
420
// final node failure
419
421
run_onion_failure_test_with_fail_intercept ( "temporary_node_failure" , 200 , & nodes, & route, & payment_hash, & payment_secret, |_msg| { } , |msg| {
420
422
// and tamper returning error message
421
423
let session_priv = SecretKey :: from_slice ( & [ 3 ; 32 ] ) . unwrap ( ) ;
422
424
let onion_keys = onion_utils:: construct_onion_keys ( & Secp256k1 :: new ( ) , & route. paths [ 0 ] , & session_priv) . unwrap ( ) ;
423
- let failure = onion_utils:: build_failure_packet ( onion_keys[ 1 ] . shared_secret . as_ref ( ) , NODE |2 , & [ 0 ; 0 ] ) ;
425
+ let failure = onion_utils:: build_failure_packet ( onion_keys[ 1 ] . shared_secret . as_ref ( ) , NODE |2 , & [ 0 ; 0 ] , 0 ) ;
424
426
msg. reason = failure. data ;
427
+ msg. attribution_data = failure. attribution_data ;
425
428
} , ||{
426
429
nodes[ 2 ] . node . fail_htlc_backwards ( & payment_hash) ;
427
430
} , true , Some ( NODE |2 ) , Some ( NetworkUpdate :: NodeFailure { node_id : route. paths [ 0 ] . hops [ 1 ] . pubkey , is_permanent : false } ) , Some ( route. paths [ 0 ] . hops [ 1 ] . short_channel_id ) , None ) ;
@@ -433,16 +436,18 @@ fn test_onion_failure() {
433
436
} , |msg| {
434
437
let session_priv = SecretKey :: from_slice ( & [ 3 ; 32 ] ) . unwrap ( ) ;
435
438
let onion_keys = onion_utils:: construct_onion_keys ( & Secp256k1 :: new ( ) , & route. paths [ 0 ] , & session_priv) . unwrap ( ) ;
436
- let failure = onion_utils:: build_failure_packet ( onion_keys[ 0 ] . shared_secret . as_ref ( ) , PERM |NODE |2 , & [ 0 ; 0 ] ) ;
439
+ let failure = onion_utils:: build_failure_packet ( onion_keys[ 0 ] . shared_secret . as_ref ( ) , PERM |NODE |2 , & [ 0 ; 0 ] , 0 ) ;
437
440
msg. reason = failure. data ;
441
+ msg. attribution_data = failure. attribution_data ;
438
442
} , ||{ } , true , Some ( PERM |NODE |2 ) , Some ( NetworkUpdate :: NodeFailure { node_id : route. paths [ 0 ] . hops [ 0 ] . pubkey , is_permanent : true } ) , Some ( route. paths [ 0 ] . hops [ 0 ] . short_channel_id ) , Some ( next_hop_failure. clone ( ) ) ) ;
439
443
440
444
// final node failure
441
445
run_onion_failure_test_with_fail_intercept ( "permanent_node_failure" , 200 , & nodes, & route, & payment_hash, & payment_secret, |_msg| { } , |msg| {
442
446
let session_priv = SecretKey :: from_slice ( & [ 3 ; 32 ] ) . unwrap ( ) ;
443
447
let onion_keys = onion_utils:: construct_onion_keys ( & Secp256k1 :: new ( ) , & route. paths [ 0 ] , & session_priv) . unwrap ( ) ;
444
- let failure = onion_utils:: build_failure_packet ( onion_keys[ 1 ] . shared_secret . as_ref ( ) , PERM |NODE |2 , & [ 0 ; 0 ] ) ;
448
+ let failure = onion_utils:: build_failure_packet ( onion_keys[ 1 ] . shared_secret . as_ref ( ) , PERM |NODE |2 , & [ 0 ; 0 ] , 0 ) ;
445
449
msg. reason = failure. data ;
450
+ msg. attribution_data = failure. attribution_data ;
446
451
} , ||{
447
452
nodes[ 2 ] . node . fail_htlc_backwards ( & payment_hash) ;
448
453
} , false , Some ( PERM |NODE |2 ) , Some ( NetworkUpdate :: NodeFailure { node_id : route. paths [ 0 ] . hops [ 1 ] . pubkey , is_permanent : true } ) , Some ( route. paths [ 0 ] . hops [ 1 ] . short_channel_id ) , None ) ;
@@ -454,8 +459,9 @@ fn test_onion_failure() {
454
459
} , |msg| {
455
460
let session_priv = SecretKey :: from_slice ( & [ 3 ; 32 ] ) . unwrap ( ) ;
456
461
let onion_keys = onion_utils:: construct_onion_keys ( & Secp256k1 :: new ( ) , & route. paths [ 0 ] , & session_priv) . unwrap ( ) ;
457
- let failure = onion_utils:: build_failure_packet ( onion_keys[ 0 ] . shared_secret . as_ref ( ) , PERM |NODE |3 , & [ 0 ; 0 ] ) ;
462
+ let failure = onion_utils:: build_failure_packet ( onion_keys[ 0 ] . shared_secret . as_ref ( ) , PERM |NODE |3 , & [ 0 ; 0 ] , 0 ) ;
458
463
msg. reason = failure. data ;
464
+ msg. attribution_data = failure. attribution_data ;
459
465
} , ||{
460
466
nodes[ 2 ] . node . fail_htlc_backwards ( & payment_hash) ;
461
467
} , true , Some ( PERM |NODE |3 ) , Some ( NetworkUpdate :: NodeFailure { node_id : route. paths [ 0 ] . hops [ 0 ] . pubkey , is_permanent : true } ) , Some ( route. paths [ 0 ] . hops [ 0 ] . short_channel_id ) , Some ( next_hop_failure. clone ( ) ) ) ;
@@ -464,8 +470,9 @@ fn test_onion_failure() {
464
470
run_onion_failure_test_with_fail_intercept ( "required_node_feature_missing" , 200 , & nodes, & route, & payment_hash, & payment_secret, |_msg| { } , |msg| {
465
471
let session_priv = SecretKey :: from_slice ( & [ 3 ; 32 ] ) . unwrap ( ) ;
466
472
let onion_keys = onion_utils:: construct_onion_keys ( & Secp256k1 :: new ( ) , & route. paths [ 0 ] , & session_priv) . unwrap ( ) ;
467
- let failure = onion_utils:: build_failure_packet ( onion_keys[ 1 ] . shared_secret . as_ref ( ) , PERM |NODE |3 , & [ 0 ; 0 ] ) ;
473
+ let failure = onion_utils:: build_failure_packet ( onion_keys[ 1 ] . shared_secret . as_ref ( ) , PERM |NODE |3 , & [ 0 ; 0 ] , 0 ) ;
468
474
msg. reason = failure. data ;
475
+ msg. attribution_data = failure. attribution_data ;
469
476
} , ||{
470
477
nodes[ 2 ] . node . fail_htlc_backwards ( & payment_hash) ;
471
478
} , false , Some ( PERM |NODE |3 ) , Some ( NetworkUpdate :: NodeFailure { node_id : route. paths [ 0 ] . hops [ 1 ] . pubkey , is_permanent : true } ) , Some ( route. paths [ 0 ] . hops [ 1 ] . short_channel_id ) , None ) ;
@@ -495,8 +502,9 @@ fn test_onion_failure() {
495
502
} , |msg| {
496
503
let session_priv = SecretKey :: from_slice ( & [ 3 ; 32 ] ) . unwrap ( ) ;
497
504
let onion_keys = onion_utils:: construct_onion_keys ( & Secp256k1 :: new ( ) , & route. paths [ 0 ] , & session_priv) . unwrap ( ) ;
498
- let failure = onion_utils:: build_failure_packet ( onion_keys[ 0 ] . shared_secret . as_ref ( ) , UPDATE |7 , & err_data) ;
505
+ let failure = onion_utils:: build_failure_packet ( onion_keys[ 0 ] . shared_secret . as_ref ( ) , UPDATE |7 , & err_data, 0 ) ;
499
506
msg. reason = failure. data ;
507
+ msg. attribution_data = failure. attribution_data ;
500
508
} , ||{ } , true , Some ( UPDATE |7 ) ,
501
509
Some ( NetworkUpdate :: ChannelFailure { short_channel_id, is_permanent : false } ) ,
502
510
Some ( short_channel_id) , Some ( next_hop_failure. clone ( ) ) ) ;
@@ -508,8 +516,9 @@ fn test_onion_failure() {
508
516
} , |msg| {
509
517
let session_priv = SecretKey :: from_slice ( & [ 3 ; 32 ] ) . unwrap ( ) ;
510
518
let onion_keys = onion_utils:: construct_onion_keys ( & Secp256k1 :: new ( ) , & route. paths [ 0 ] , & session_priv) . unwrap ( ) ;
511
- let failure = onion_utils:: build_failure_packet ( onion_keys[ 0 ] . shared_secret . as_ref ( ) , UPDATE |7 , & err_data_without_type) ;
519
+ let failure = onion_utils:: build_failure_packet ( onion_keys[ 0 ] . shared_secret . as_ref ( ) , UPDATE |7 , & err_data_without_type, 0 ) ;
512
520
msg. reason = failure. data ;
521
+ msg. attribution_data = failure. attribution_data ;
513
522
} , ||{ } , true , Some ( UPDATE |7 ) ,
514
523
Some ( NetworkUpdate :: ChannelFailure { short_channel_id, is_permanent : false } ) ,
515
524
Some ( short_channel_id) , Some ( next_hop_failure. clone ( ) ) ) ;
@@ -520,8 +529,9 @@ fn test_onion_failure() {
520
529
} , |msg| {
521
530
let session_priv = SecretKey :: from_slice ( & [ 3 ; 32 ] ) . unwrap ( ) ;
522
531
let onion_keys = onion_utils:: construct_onion_keys ( & Secp256k1 :: new ( ) , & route. paths [ 0 ] , & session_priv) . unwrap ( ) ;
523
- let failure = onion_utils:: build_failure_packet ( onion_keys[ 0 ] . shared_secret . as_ref ( ) , PERM |8 , & [ 0 ; 0 ] ) ;
532
+ let failure = onion_utils:: build_failure_packet ( onion_keys[ 0 ] . shared_secret . as_ref ( ) , PERM |8 , & [ 0 ; 0 ] , 0 ) ;
524
533
msg. reason = failure. data ;
534
+ msg. attribution_data = failure. attribution_data ;
525
535
// short_channel_id from the processing node
526
536
} , ||{ } , true , Some ( PERM |8 ) , Some ( NetworkUpdate :: ChannelFailure { short_channel_id, is_permanent : true } ) , Some ( short_channel_id) , Some ( next_hop_failure. clone ( ) ) ) ;
527
537
@@ -531,8 +541,9 @@ fn test_onion_failure() {
531
541
} , |msg| {
532
542
let session_priv = SecretKey :: from_slice ( & [ 3 ; 32 ] ) . unwrap ( ) ;
533
543
let onion_keys = onion_utils:: construct_onion_keys ( & Secp256k1 :: new ( ) , & route. paths [ 0 ] , & session_priv) . unwrap ( ) ;
534
- let failure = onion_utils:: build_failure_packet ( onion_keys[ 0 ] . shared_secret . as_ref ( ) , PERM |9 , & [ 0 ; 0 ] ) ;
544
+ let failure = onion_utils:: build_failure_packet ( onion_keys[ 0 ] . shared_secret . as_ref ( ) , PERM |9 , & [ 0 ; 0 ] , 0 ) ;
535
545
msg. reason = failure. data ;
546
+ msg. attribution_data = failure. attribution_data ;
536
547
// short_channel_id from the processing node
537
548
} , ||{ } , true , Some ( PERM |9 ) , Some ( NetworkUpdate :: ChannelFailure { short_channel_id, is_permanent : true } ) , Some ( short_channel_id) , Some ( next_hop_failure. clone ( ) ) ) ;
538
549
@@ -664,8 +675,9 @@ fn test_onion_failure() {
664
675
// Tamper returning error message
665
676
let session_priv = SecretKey :: from_slice ( & [ 3 ; 32 ] ) . unwrap ( ) ;
666
677
let onion_keys = onion_utils:: construct_onion_keys ( & Secp256k1 :: new ( ) , & route. paths [ 0 ] , & session_priv) . unwrap ( ) ;
667
- let failure = onion_utils:: build_failure_packet ( onion_keys[ 1 ] . shared_secret . as_ref ( ) , 23 , & [ 0 ; 0 ] ) ;
678
+ let failure = onion_utils:: build_failure_packet ( onion_keys[ 1 ] . shared_secret . as_ref ( ) , 23 , & [ 0 ; 0 ] , 0 ) ;
668
679
msg. reason = failure. data ;
680
+ msg. attribution_data = failure. attribution_data ;
669
681
} , ||{
670
682
nodes[ 2 ] . node . fail_htlc_backwards ( & payment_hash) ;
671
683
} , true , Some ( 23 ) , None , None , None ) ;
@@ -685,11 +697,13 @@ fn test_onion_failure() {
685
697
decoded_err_packet. hmac = Hmac :: from_engine ( hmac) . to_byte_array ( ) ;
686
698
let mut onion_error = OnionErrorPacket {
687
699
data : decoded_err_packet. encode ( ) ,
688
- attribution_data : None ,
700
+ attribution_data : Some ( AttributionData :: new ( ) ) ,
689
701
} ;
702
+ onion_error. attribution_data . as_mut ( ) . unwrap ( ) . add_hmacs ( & onion_keys[ 1 ] . shared_secret . as_ref ( ) , & onion_error. data ) ;
690
703
onion_utils:: test_crypt_failure_packet (
691
704
& onion_keys[ 1 ] . shared_secret . as_ref ( ) , & mut onion_error) ;
692
705
msg. reason = onion_error. data ;
706
+ msg. attribution_data = onion_error. attribution_data ;
693
707
} , || nodes[ 2 ] . node . fail_htlc_backwards ( & payment_hash) , false , None ,
694
708
Some ( NetworkUpdate :: NodeFailure { node_id : route. paths [ 0 ] . hops [ 1 ] . pubkey , is_permanent : true } ) ,
695
709
Some ( channels[ 1 ] . 0 . contents . short_channel_id ) , None ) ;
@@ -720,11 +734,13 @@ fn test_onion_failure() {
720
734
decoded_err_packet. hmac = Hmac :: from_engine ( hmac) . to_byte_array ( ) ;
721
735
let mut onion_error = OnionErrorPacket {
722
736
data : decoded_err_packet. encode ( ) ,
723
- attribution_data : None ,
737
+ attribution_data : Some ( AttributionData :: new ( ) ) ,
724
738
} ;
739
+ onion_error. attribution_data . as_mut ( ) . unwrap ( ) . add_hmacs ( & onion_keys[ 0 ] . shared_secret . as_ref ( ) , & onion_error. data ) ;
725
740
onion_utils:: test_crypt_failure_packet (
726
741
& onion_keys[ 0 ] . shared_secret . as_ref ( ) , & mut onion_error) ;
727
742
msg. reason = onion_error. data ;
743
+ msg. attribution_data = onion_error. attribution_data ;
728
744
} , || { } , true , Some ( 0x1000 |7 ) ,
729
745
Some ( NetworkUpdate :: ChannelFailure {
730
746
short_channel_id : channels[ 1 ] . 0 . contents . short_channel_id ,
@@ -749,11 +765,13 @@ fn test_onion_failure() {
749
765
decoded_err_packet. hmac = Hmac :: from_engine ( hmac) . to_byte_array ( ) ;
750
766
let mut onion_error = OnionErrorPacket {
751
767
data : decoded_err_packet. encode ( ) ,
752
- attribution_data : None ,
768
+ attribution_data : Some ( AttributionData :: new ( ) ) ,
753
769
} ;
770
+ onion_error. attribution_data . as_mut ( ) . unwrap ( ) . add_hmacs ( & onion_keys[ 1 ] . shared_secret . as_ref ( ) , & onion_error. data ) ;
754
771
onion_utils:: test_crypt_failure_packet (
755
772
& onion_keys[ 1 ] . shared_secret . as_ref ( ) , & mut onion_error) ;
756
773
msg. reason = onion_error. data ;
774
+ msg. attribution_data = onion_error. attribution_data ;
757
775
} , || nodes[ 2 ] . node . fail_htlc_backwards ( & payment_hash) , true , Some ( 0x1000 |7 ) ,
758
776
Some ( NetworkUpdate :: ChannelFailure {
759
777
short_channel_id : channels[ 1 ] . 0 . contents . short_channel_id ,
0 commit comments