@@ -300,12 +300,13 @@ fn test_fee_failures() {
300
300
claim_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] , & nodes[ 2 ] ] , payment_preimage_success) ;
301
301
302
302
// If the hop gives fee_insufficient but enough fees were provided, then the previous hop
303
- // malleated the payment before forwarding, taking funds when they shouldn't have.
303
+ // malleated the payment before forwarding, taking funds when they shouldn't have. However,
304
+ // because we ignore channel update contents, we will still blame the 2nd channel.
304
305
let ( _, payment_hash, payment_secret) = get_payment_preimage_hash ! ( nodes[ 2 ] ) ;
305
- let short_channel_id = channels[ 0 ] . 0 . contents . short_channel_id ;
306
+ let short_channel_id = channels[ 1 ] . 0 . contents . short_channel_id ;
306
307
run_onion_failure_test ( "fee_insufficient" , 0 , & nodes, & route, & payment_hash, & payment_secret, |msg| {
307
308
msg. amount_msat -= 1 ;
308
- } , || { } , true , Some ( UPDATE |12 ) , Some ( NetworkUpdate :: ChannelFailure { short_channel_id, is_permanent : true } ) , Some ( short_channel_id) ) ;
309
+ } , || { } , true , Some ( UPDATE |12 ) , Some ( NetworkUpdate :: ChannelFailure { short_channel_id, is_permanent : false } ) , Some ( short_channel_id) ) ;
309
310
310
311
// In an earlier version, we spuriously failed to forward payments if the expected feerate
311
312
// changed between the channel open and the payment.
@@ -478,7 +479,9 @@ fn test_onion_failure() {
478
479
let session_priv = SecretKey :: from_slice ( & [ 3 ; 32 ] ) . unwrap ( ) ;
479
480
let onion_keys = onion_utils:: construct_onion_keys ( & Secp256k1 :: new ( ) , & route. paths [ 0 ] , & session_priv) . unwrap ( ) ;
480
481
msg. reason = onion_utils:: build_first_hop_failure_packet ( onion_keys[ 0 ] . shared_secret . as_ref ( ) , UPDATE |7 , & err_data) ;
481
- } , ||{ } , true , Some ( UPDATE |7 ) , Some ( NetworkUpdate :: ChannelUpdateMessage { msg : chan_update. clone ( ) } ) , Some ( short_channel_id) ) ;
482
+ } , ||{ } , true , Some ( UPDATE |7 ) ,
483
+ Some ( NetworkUpdate :: ChannelFailure { short_channel_id, is_permanent : false } ) ,
484
+ Some ( short_channel_id) ) ;
482
485
483
486
// Check we can still handle onion failures that include channel updates without a type prefix
484
487
let err_data_without_type = chan_update. encode_with_len ( ) ;
@@ -488,7 +491,9 @@ fn test_onion_failure() {
488
491
let session_priv = SecretKey :: from_slice ( & [ 3 ; 32 ] ) . unwrap ( ) ;
489
492
let onion_keys = onion_utils:: construct_onion_keys ( & Secp256k1 :: new ( ) , & route. paths [ 0 ] , & session_priv) . unwrap ( ) ;
490
493
msg. reason = onion_utils:: build_first_hop_failure_packet ( onion_keys[ 0 ] . shared_secret . as_ref ( ) , UPDATE |7 , & err_data_without_type) ;
491
- } , ||{ } , true , Some ( UPDATE |7 ) , Some ( NetworkUpdate :: ChannelUpdateMessage { msg : chan_update} ) , Some ( short_channel_id) ) ;
494
+ } , ||{ } , true , Some ( UPDATE |7 ) ,
495
+ Some ( NetworkUpdate :: ChannelFailure { short_channel_id, is_permanent : false } ) ,
496
+ Some ( short_channel_id) ) ;
492
497
493
498
let short_channel_id = channels[ 1 ] . 0 . contents . short_channel_id ;
494
499
run_onion_failure_test_with_fail_intercept ( "permanent_channel_failure" , 100 , & nodes, & route, & payment_hash, & payment_secret, |msg| {
@@ -523,7 +528,9 @@ fn test_onion_failure() {
523
528
let mut bogus_route = route. clone ( ) ;
524
529
let route_len = bogus_route. paths [ 0 ] . hops . len ( ) ;
525
530
bogus_route. paths [ 0 ] . hops [ route_len-1 ] . fee_msat = amt_to_forward;
526
- run_onion_failure_test ( "amount_below_minimum" , 0 , & nodes, & bogus_route, & payment_hash, & payment_secret, |_| { } , ||{ } , true , Some ( UPDATE |11 ) , Some ( NetworkUpdate :: ChannelUpdateMessage { msg : ChannelUpdate :: dummy ( short_channel_id) } ) , Some ( short_channel_id) ) ;
531
+ run_onion_failure_test ( "amount_below_minimum" , 0 , & nodes, & bogus_route, & payment_hash, & payment_secret, |_| { } , ||{ } , true , Some ( UPDATE |11 ) ,
532
+ Some ( NetworkUpdate :: ChannelFailure { short_channel_id, is_permanent : false } ) ,
533
+ Some ( short_channel_id) ) ;
527
534
528
535
// Clear pending payments so that the following positive test has the correct payment hash.
529
536
for node in nodes. iter ( ) {
@@ -535,24 +542,28 @@ fn test_onion_failure() {
535
542
let preimage = send_along_route ( & nodes[ 0 ] , bogus_route, & [ & nodes[ 1 ] , & nodes[ 2 ] ] , amt_to_forward+1 ) . 0 ;
536
543
claim_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] , & nodes[ 2 ] ] , preimage) ;
537
544
538
- let short_channel_id = channels[ 0 ] . 0 . contents . short_channel_id ;
545
+ // We ignore channel update contents in onion errors, so will blame the 2nd channel even though
546
+ // the first node is the one that messed up.
547
+ let short_channel_id = channels[ 1 ] . 0 . contents . short_channel_id ;
539
548
run_onion_failure_test ( "fee_insufficient" , 0 , & nodes, & route, & payment_hash, & payment_secret, |msg| {
540
549
msg. amount_msat -= 1 ;
541
- } , || { } , true , Some ( UPDATE |12 ) , Some ( NetworkUpdate :: ChannelFailure { short_channel_id, is_permanent : true } ) , Some ( short_channel_id) ) ;
550
+ } , || { } , true , Some ( UPDATE |12 ) , Some ( NetworkUpdate :: ChannelFailure { short_channel_id, is_permanent : false } ) , Some ( short_channel_id) ) ;
542
551
543
- let short_channel_id = channels[ 0 ] . 0 . contents . short_channel_id ;
552
+ let short_channel_id = channels[ 1 ] . 0 . contents . short_channel_id ;
544
553
run_onion_failure_test ( "incorrect_cltv_expiry" , 0 , & nodes, & route, & payment_hash, & payment_secret, |msg| {
545
554
// need to violate: cltv_expiry - cltv_expiry_delta >= outgoing_cltv_value
546
555
msg. cltv_expiry -= 1 ;
547
- } , || { } , true , Some ( UPDATE |13 ) , Some ( NetworkUpdate :: ChannelFailure { short_channel_id, is_permanent : true } ) , Some ( short_channel_id) ) ;
556
+ } , || { } , true , Some ( UPDATE |13 ) , Some ( NetworkUpdate :: ChannelFailure { short_channel_id, is_permanent : false } ) , Some ( short_channel_id) ) ;
548
557
549
558
let short_channel_id = channels[ 1 ] . 0 . contents . short_channel_id ;
550
559
run_onion_failure_test ( "expiry_too_soon" , 0 , & nodes, & route, & payment_hash, & payment_secret, |msg| {
551
560
let height = msg. cltv_expiry - CLTV_CLAIM_BUFFER - LATENCY_GRACE_PERIOD_BLOCKS + 1 ;
552
561
connect_blocks ( & nodes[ 0 ] , height - nodes[ 0 ] . best_block_info ( ) . 1 ) ;
553
562
connect_blocks ( & nodes[ 1 ] , height - nodes[ 1 ] . best_block_info ( ) . 1 ) ;
554
563
connect_blocks ( & nodes[ 2 ] , height - nodes[ 2 ] . best_block_info ( ) . 1 ) ;
555
- } , ||{ } , true , Some ( UPDATE |14 ) , Some ( NetworkUpdate :: ChannelUpdateMessage { msg : ChannelUpdate :: dummy ( short_channel_id) } ) , Some ( short_channel_id) ) ;
564
+ } , ||{ } , true , Some ( UPDATE |14 ) ,
565
+ Some ( NetworkUpdate :: ChannelFailure { short_channel_id, is_permanent : false } ) ,
566
+ Some ( short_channel_id) ) ;
556
567
557
568
run_onion_failure_test ( "unknown_payment_hash" , 2 , & nodes, & route, & payment_hash, & payment_secret, |_| { } , || {
558
569
nodes[ 2 ] . node . fail_htlc_backwards ( & payment_hash) ;
@@ -596,7 +607,9 @@ fn test_onion_failure() {
596
607
// disconnect event to the channel between nodes[1] ~ nodes[2]
597
608
nodes[ 1 ] . node . peer_disconnected ( & nodes[ 2 ] . node . get_our_node_id ( ) ) ;
598
609
nodes[ 2 ] . node . peer_disconnected ( & nodes[ 1 ] . node . get_our_node_id ( ) ) ;
599
- } , true , Some ( UPDATE |7 ) , Some ( NetworkUpdate :: ChannelUpdateMessage { msg : ChannelUpdate :: dummy ( short_channel_id) } ) , Some ( short_channel_id) ) ;
610
+ } , true , Some ( UPDATE |7 ) ,
611
+ Some ( NetworkUpdate :: ChannelFailure { short_channel_id, is_permanent : false } ) ,
612
+ Some ( short_channel_id) ) ;
600
613
run_onion_failure_test ( "channel_disabled" , 0 , & nodes, & route, & payment_hash, & payment_secret, |_| { } , || {
601
614
// disconnect event to the channel between nodes[1] ~ nodes[2]
602
615
for _ in 0 ..DISABLE_GOSSIP_TICKS + 1 {
@@ -605,7 +618,9 @@ fn test_onion_failure() {
605
618
}
606
619
nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
607
620
nodes[ 2 ] . node . get_and_clear_pending_msg_events ( ) ;
608
- } , true , Some ( UPDATE |20 ) , Some ( NetworkUpdate :: ChannelUpdateMessage { msg : ChannelUpdate :: dummy ( short_channel_id) } ) , Some ( short_channel_id) ) ;
621
+ } , true , Some ( UPDATE |20 ) ,
622
+ Some ( NetworkUpdate :: ChannelFailure { short_channel_id, is_permanent : false } ) ,
623
+ Some ( short_channel_id) ) ;
609
624
reconnect_nodes ( ReconnectArgs :: new ( & nodes[ 1 ] , & nodes[ 2 ] ) ) ;
610
625
611
626
run_onion_failure_test ( "expiry_too_far" , 0 , & nodes, & route, & payment_hash, & payment_secret, |msg| {
@@ -844,9 +859,9 @@ fn do_test_onion_failure_stale_channel_update(announced_channel: bool) {
844
859
// We'll be attempting to route payments using the default ChannelUpdate for channels. This will
845
860
// lead to onion failures at the first hop once we update the ChannelConfig for the
846
861
// second hop.
847
- let expect_onion_failure = |name : & str , error_code : u16 , channel_update : & msgs :: ChannelUpdate | {
862
+ let expect_onion_failure = |name : & str , error_code : u16 | {
848
863
let short_channel_id = channel_to_update. 1 ;
849
- let network_update = NetworkUpdate :: ChannelUpdateMessage { msg : channel_update . clone ( ) } ;
864
+ let network_update = NetworkUpdate :: ChannelFailure { short_channel_id , is_permanent : false } ;
850
865
run_onion_failure_test (
851
866
name, 0 , & nodes, & route, & payment_hash, & payment_secret, |_| { } , || { } , true ,
852
867
Some ( error_code) , Some ( network_update) , Some ( short_channel_id) ,
@@ -878,7 +893,7 @@ fn do_test_onion_failure_stale_channel_update(announced_channel: bool) {
878
893
// Connect a block, which should expire the previous config, leading to a failure when
879
894
// forwarding the HTLC.
880
895
expire_prev_config ( ) ;
881
- expect_onion_failure ( "fee_insufficient" , UPDATE |12 , & msg ) ;
896
+ expect_onion_failure ( "fee_insufficient" , UPDATE |12 ) ;
882
897
883
898
// Redundant updates should not trigger a new ChannelUpdate.
884
899
assert ! ( update_and_get_channel_update( & config, false , None , false ) . is_none( ) ) ;
@@ -891,15 +906,15 @@ fn do_test_onion_failure_stale_channel_update(announced_channel: bool) {
891
906
// new ChannelUpdate.
892
907
config. forwarding_fee_base_msat = default_config. forwarding_fee_base_msat ;
893
908
config. cltv_expiry_delta = u16:: max_value ( ) ;
894
- let msg = update_and_get_channel_update ( & config, true , Some ( & msg) , true ) . unwrap ( ) ;
895
- expect_onion_failure ( "incorrect_cltv_expiry" , UPDATE |13 , & msg ) ;
909
+ assert ! ( update_and_get_channel_update( & config, true , Some ( & msg) , true ) . is_some ( ) ) ;
910
+ expect_onion_failure ( "incorrect_cltv_expiry" , UPDATE |13 ) ;
896
911
897
912
// Reset the proportional fee and increase the CLTV expiry delta which should trigger a new
898
913
// ChannelUpdate.
899
914
config. cltv_expiry_delta = default_config. cltv_expiry_delta ;
900
915
config. forwarding_fee_proportional_millionths = u32:: max_value ( ) ;
901
- let msg = update_and_get_channel_update ( & config, true , Some ( & msg) , true ) . unwrap ( ) ;
902
- expect_onion_failure ( "fee_insufficient" , UPDATE |12 , & msg ) ;
916
+ assert ! ( update_and_get_channel_update( & config, true , Some ( & msg) , true ) . is_some ( ) ) ;
917
+ expect_onion_failure ( "fee_insufficient" , UPDATE |12 ) ;
903
918
904
919
// To test persistence of the updated config, we'll re-initialize the ChannelManager.
905
920
let config_after_restart = {
@@ -1530,10 +1545,10 @@ fn do_test_phantom_dust_exposure_failure(multiplier_dust_limit: bool) {
1530
1545
err_data. extend_from_slice ( & channel. 1 . encode ( ) ) ;
1531
1546
1532
1547
let mut fail_conditions = PaymentFailedConditions :: new ( )
1533
- . blamed_scid ( channel . 0 . contents . short_channel_id )
1548
+ . blamed_scid ( route . paths [ 0 ] . hops . last ( ) . as_ref ( ) . unwrap ( ) . short_channel_id )
1534
1549
. blamed_chan_closed ( false )
1535
1550
. expected_htlc_error_data ( 0x1000 | 7 , & err_data) ;
1536
- expect_payment_failed_conditions ( & nodes[ 0 ] , payment_hash, false , fail_conditions) ;
1551
+ expect_payment_failed_conditions ( & nodes[ 0 ] , payment_hash, false , fail_conditions) ;
1537
1552
}
1538
1553
1539
1554
#[ test]
0 commit comments