@@ -300,12 +300,13 @@ fn test_fee_failures() {
300300 claim_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] , & nodes[ 2 ] ] , payment_preimage_success) ;
301301
302302 // 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.
304305 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 ;
306307 run_onion_failure_test ( "fee_insufficient" , 0 , & nodes, & route, & payment_hash, & payment_secret, |msg| {
307308 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) ) ;
309310
310311 // In an earlier version, we spuriously failed to forward payments if the expected feerate
311312 // changed between the channel open and the payment.
@@ -478,7 +479,9 @@ fn test_onion_failure() {
478479 let session_priv = SecretKey :: from_slice ( & [ 3 ; 32 ] ) . unwrap ( ) ;
479480 let onion_keys = onion_utils:: construct_onion_keys ( & Secp256k1 :: new ( ) , & route. paths [ 0 ] , & session_priv) . unwrap ( ) ;
480481 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) ) ;
482485
483486 // Check we can still handle onion failures that include channel updates without a type prefix
484487 let err_data_without_type = chan_update. encode_with_len ( ) ;
@@ -488,7 +491,9 @@ fn test_onion_failure() {
488491 let session_priv = SecretKey :: from_slice ( & [ 3 ; 32 ] ) . unwrap ( ) ;
489492 let onion_keys = onion_utils:: construct_onion_keys ( & Secp256k1 :: new ( ) , & route. paths [ 0 ] , & session_priv) . unwrap ( ) ;
490493 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) ) ;
492497
493498 let short_channel_id = channels[ 1 ] . 0 . contents . short_channel_id ;
494499 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() {
523528 let mut bogus_route = route. clone ( ) ;
524529 let route_len = bogus_route. paths [ 0 ] . hops . len ( ) ;
525530 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) ) ;
527534
528535 // Clear pending payments so that the following positive test has the correct payment hash.
529536 for node in nodes. iter ( ) {
@@ -535,24 +542,28 @@ fn test_onion_failure() {
535542 let preimage = send_along_route ( & nodes[ 0 ] , bogus_route, & [ & nodes[ 1 ] , & nodes[ 2 ] ] , amt_to_forward+1 ) . 0 ;
536543 claim_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] , & nodes[ 2 ] ] , preimage) ;
537544
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 ;
539548 run_onion_failure_test ( "fee_insufficient" , 0 , & nodes, & route, & payment_hash, & payment_secret, |msg| {
540549 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) ) ;
542551
543- let short_channel_id = channels[ 0 ] . 0 . contents . short_channel_id ;
552+ let short_channel_id = channels[ 1 ] . 0 . contents . short_channel_id ;
544553 run_onion_failure_test ( "incorrect_cltv_expiry" , 0 , & nodes, & route, & payment_hash, & payment_secret, |msg| {
545554 // need to violate: cltv_expiry - cltv_expiry_delta >= outgoing_cltv_value
546555 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) ) ;
548557
549558 let short_channel_id = channels[ 1 ] . 0 . contents . short_channel_id ;
550559 run_onion_failure_test ( "expiry_too_soon" , 0 , & nodes, & route, & payment_hash, & payment_secret, |msg| {
551560 let height = msg. cltv_expiry - CLTV_CLAIM_BUFFER - LATENCY_GRACE_PERIOD_BLOCKS + 1 ;
552561 connect_blocks ( & nodes[ 0 ] , height - nodes[ 0 ] . best_block_info ( ) . 1 ) ;
553562 connect_blocks ( & nodes[ 1 ] , height - nodes[ 1 ] . best_block_info ( ) . 1 ) ;
554563 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) ) ;
556567
557568 run_onion_failure_test ( "unknown_payment_hash" , 2 , & nodes, & route, & payment_hash, & payment_secret, |_| { } , || {
558569 nodes[ 2 ] . node . fail_htlc_backwards ( & payment_hash) ;
@@ -596,7 +607,9 @@ fn test_onion_failure() {
596607 // disconnect event to the channel between nodes[1] ~ nodes[2]
597608 nodes[ 1 ] . node . peer_disconnected ( & nodes[ 2 ] . node . get_our_node_id ( ) ) ;
598609 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) ) ;
600613 run_onion_failure_test ( "channel_disabled" , 0 , & nodes, & route, & payment_hash, & payment_secret, |_| { } , || {
601614 // disconnect event to the channel between nodes[1] ~ nodes[2]
602615 for _ in 0 ..DISABLE_GOSSIP_TICKS + 1 {
@@ -605,7 +618,9 @@ fn test_onion_failure() {
605618 }
606619 nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
607620 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) ) ;
609624 reconnect_nodes ( ReconnectArgs :: new ( & nodes[ 1 ] , & nodes[ 2 ] ) ) ;
610625
611626 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) {
844859 // We'll be attempting to route payments using the default ChannelUpdate for channels. This will
845860 // lead to onion failures at the first hop once we update the ChannelConfig for the
846861 // 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 | {
848863 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 } ;
850865 run_onion_failure_test (
851866 name, 0 , & nodes, & route, & payment_hash, & payment_secret, |_| { } , || { } , true ,
852867 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) {
878893 // Connect a block, which should expire the previous config, leading to a failure when
879894 // forwarding the HTLC.
880895 expire_prev_config ( ) ;
881- expect_onion_failure ( "fee_insufficient" , UPDATE |12 , & msg ) ;
896+ expect_onion_failure ( "fee_insufficient" , UPDATE |12 ) ;
882897
883898 // Redundant updates should not trigger a new ChannelUpdate.
884899 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) {
891906 // new ChannelUpdate.
892907 config. forwarding_fee_base_msat = default_config. forwarding_fee_base_msat ;
893908 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 ) ;
896911
897912 // Reset the proportional fee and increase the CLTV expiry delta which should trigger a new
898913 // ChannelUpdate.
899914 config. cltv_expiry_delta = default_config. cltv_expiry_delta ;
900915 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 ) ;
903918
904919 // To test persistence of the updated config, we'll re-initialize the ChannelManager.
905920 let config_after_restart = {
@@ -1530,10 +1545,10 @@ fn do_test_phantom_dust_exposure_failure(multiplier_dust_limit: bool) {
15301545 err_data. extend_from_slice ( & channel. 1 . encode ( ) ) ;
15311546
15321547 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 )
15341549 . blamed_chan_closed ( false )
15351550 . 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) ;
15371552}
15381553
15391554#[ test]
0 commit comments