@@ -593,43 +593,83 @@ fn test_onion_failure() {
593
593
} , true , Some ( 23 ) , None , None ) ;
594
594
}
595
595
596
- #[ test]
597
- fn test_onion_failure_stale_channel_update ( ) {
596
+ fn do_test_onion_failure_stale_channel_update ( announced_channel : bool ) {
598
597
// Create a network of three nodes and two channels connecting them. We'll be updating the
599
598
// HTLC relay policy of the second channel, causing forwarding failures at the first hop.
599
+ let mut config = UserConfig :: default ( ) ;
600
+ config. channel_handshake_config . announced_channel = announced_channel;
601
+ config. channel_handshake_limits . force_announced_channel_preference = false ;
602
+ config. accept_forwards_to_priv_channels = !announced_channel;
600
603
let chanmon_cfgs = create_chanmon_cfgs ( 3 ) ;
601
604
let node_cfgs = create_node_cfgs ( 3 , & chanmon_cfgs) ;
602
- let node_chanmgrs = create_node_chanmgrs ( 3 , & node_cfgs, & [ None , None , None ] ) ;
605
+ let node_chanmgrs = create_node_chanmgrs ( 3 , & node_cfgs, & [ None , Some ( config ) , None ] ) ;
603
606
let mut nodes = create_network ( 3 , & node_cfgs, & node_chanmgrs) ;
604
607
605
- let other_channel = create_announced_chan_between_nodes (
606
- & nodes, 0 , 1 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ,
607
- ) ;
608
- let channel_to_update = create_announced_chan_between_nodes (
609
- & nodes, 1 , 2 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ,
608
+ let other_channel = create_chan_between_nodes (
609
+ & nodes[ 0 ] , & nodes[ 1 ] , InitFeatures :: known ( ) , InitFeatures :: known ( ) ,
610
610
) ;
611
+ let channel_to_update = if announced_channel {
612
+ let channel = create_announced_chan_between_nodes (
613
+ & nodes, 1 , 2 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ,
614
+ ) ;
615
+ ( channel. 2 , channel. 0 . contents . short_channel_id )
616
+ } else {
617
+ let channel = create_unannounced_chan_between_nodes_with_value (
618
+ & nodes, 1 , 2 , 100000 , 10001 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ,
619
+ ) ;
620
+ ( channel. 0 . channel_id , channel. 0 . short_channel_id_alias . unwrap ( ) )
621
+ } ;
611
622
let channel_to_update_counterparty = & nodes[ 2 ] . node . get_our_node_id ( ) ;
612
623
613
624
let default_config = ChannelConfig :: default ( ) ;
614
625
615
- // A test payment should succeed as the HTLC relay paramters have not been changed yet.
626
+ // A test payment should succeed as the ChannelConfig has not been changed yet.
616
627
const PAYMENT_AMT : u64 = 40000 ;
617
- send_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] , & nodes[ 2 ] ] , PAYMENT_AMT ) ;
628
+ let ( route, payment_hash, payment_preimage, payment_secret) = if announced_channel {
629
+ get_route_and_payment_hash ! ( nodes[ 0 ] , nodes[ 2 ] , PAYMENT_AMT )
630
+ } else {
631
+ let hop_hints = vec ! [ RouteHint ( vec![ RouteHintHop {
632
+ src_node_id: nodes[ 1 ] . node. get_our_node_id( ) ,
633
+ short_channel_id: channel_to_update. 1 ,
634
+ fees: RoutingFees {
635
+ base_msat: default_config. forwarding_fee_base_msat,
636
+ proportional_millionths: default_config. forwarding_fee_proportional_millionths,
637
+ } ,
638
+ cltv_expiry_delta: default_config. cltv_expiry_delta,
639
+ htlc_maximum_msat: None ,
640
+ htlc_minimum_msat: None ,
641
+ } ] ) ] ;
642
+ let payment_params = PaymentParameters :: from_node_id ( * channel_to_update_counterparty)
643
+ . with_features ( InvoiceFeatures :: known ( ) )
644
+ . with_route_hints ( hop_hints) ;
645
+ get_route_and_payment_hash ! ( nodes[ 0 ] , nodes[ 2 ] , payment_params, PAYMENT_AMT , TEST_FINAL_CLTV )
646
+ } ;
647
+ send_along_route_with_secret ( & nodes[ 0 ] , route. clone ( ) , & [ & [ & nodes[ 1 ] , & nodes[ 2 ] ] ] , PAYMENT_AMT ,
648
+ payment_hash, payment_secret) ;
649
+ claim_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] , & nodes[ 2 ] ] , payment_preimage) ;
618
650
619
651
// Closure to update and retrieve the latest ChannelUpdate.
620
652
let update_and_get_channel_update = |config : & ChannelConfig , expect_new_update : bool ,
621
653
prev_update : Option < & msgs:: ChannelUpdate > | -> Option < msgs:: ChannelUpdate > {
622
654
nodes[ 1 ] . node . update_channel_config (
623
- channel_to_update_counterparty, & [ channel_to_update. 2 ] , config,
655
+ channel_to_update_counterparty, & [ channel_to_update. 0 ] , config,
624
656
) . unwrap ( ) ;
625
657
let events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
626
658
assert_eq ! ( events. len( ) , expect_new_update as usize ) ;
627
659
if !expect_new_update {
628
660
return None ;
629
661
}
630
662
let new_update = match & events[ 0 ] {
631
- MessageSendEvent :: BroadcastChannelUpdate { msg, .. } => msg. clone ( ) ,
632
- _ => panic ! ( "expected BroadcastChannelUpdate event" ) ,
663
+ MessageSendEvent :: BroadcastChannelUpdate { msg } => {
664
+ assert ! ( announced_channel) ;
665
+ msg. clone ( )
666
+ } ,
667
+ MessageSendEvent :: SendChannelUpdate { node_id, msg } => {
668
+ assert_eq ! ( node_id, channel_to_update_counterparty) ;
669
+ assert ! ( !announced_channel) ;
670
+ msg. clone ( )
671
+ } ,
672
+ _ => panic ! ( "expected Broadcast/SendChannelUpdate event" ) ,
633
673
} ;
634
674
if prev_update. is_some ( ) {
635
675
assert ! ( new_update. contents. timestamp > prev_update. unwrap( ) . contents. timestamp)
@@ -638,13 +678,10 @@ fn test_onion_failure_stale_channel_update() {
638
678
} ;
639
679
640
680
// We'll be attempting to route payments using the default ChannelUpdate for channels. This will
641
- // lead to onion failures at the first hop once we update the HTLC relay parameters for the
681
+ // lead to onion failures at the first hop once we update the ChannelConfig for the
642
682
// second hop.
643
- let ( route, payment_hash, _, payment_secret) = get_route_and_payment_hash ! (
644
- nodes[ 0 ] , nodes[ 2 ] , PAYMENT_AMT
645
- ) ;
646
683
let expect_onion_failure = |name : & str , error_code : u16 , channel_update : & msgs:: ChannelUpdate | {
647
- let short_channel_id = channel_to_update. 0 . contents . short_channel_id ;
684
+ let short_channel_id = channel_to_update. 1 ;
648
685
let network_update = NetworkUpdate :: ChannelUpdateMessage { msg : channel_update. clone ( ) } ;
649
686
run_onion_failure_test (
650
687
name, 0 , & nodes, & route, & payment_hash, & payment_secret, |_| { } , || { } , true ,
@@ -656,15 +693,15 @@ fn test_onion_failure_stale_channel_update() {
656
693
let mut invalid_config = default_config. clone ( ) ;
657
694
invalid_config. cltv_expiry_delta = 0 ;
658
695
match nodes[ 1 ] . node . update_channel_config (
659
- channel_to_update_counterparty, & [ channel_to_update. 2 ] , & invalid_config,
696
+ channel_to_update_counterparty, & [ channel_to_update. 0 ] , & invalid_config,
660
697
) {
661
698
Err ( APIError :: APIMisuseError { .. } ) => { } ,
662
699
_ => panic ! ( "unexpected result applying invalid cltv_expiry_delta" ) ,
663
700
}
664
701
665
702
// Increase the base fee which should trigger a new ChannelUpdate.
666
703
let mut config = nodes[ 1 ] . node . list_usable_channels ( ) . iter ( )
667
- . find ( |channel| channel. channel_id == channel_to_update. 2 ) . unwrap ( )
704
+ . find ( |channel| channel. channel_id == channel_to_update. 0 ) . unwrap ( )
668
705
. config . unwrap ( ) ;
669
706
config. forwarding_fee_base_msat = u32:: max_value ( ) ;
670
707
let msg = update_and_get_channel_update ( & config, true , None ) . unwrap ( ) ;
@@ -700,10 +737,10 @@ fn test_onion_failure_stale_channel_update() {
700
737
) ;
701
738
702
739
let mut chanmon_1 = <( _ , ChannelMonitor < _ > ) >:: read (
703
- & mut & get_monitor ! ( nodes[ 1 ] , other_channel. 2 ) . encode ( ) [ ..] , nodes[ 1 ] . keys_manager ,
740
+ & mut & get_monitor ! ( nodes[ 1 ] , other_channel. 3 ) . encode ( ) [ ..] , nodes[ 1 ] . keys_manager ,
704
741
) . unwrap ( ) . 1 ;
705
742
let mut chanmon_2 = <( _ , ChannelMonitor < _ > ) >:: read (
706
- & mut & get_monitor ! ( nodes[ 1 ] , channel_to_update. 2 ) . encode ( ) [ ..] , nodes[ 1 ] . keys_manager ,
743
+ & mut & get_monitor ! ( nodes[ 1 ] , channel_to_update. 0 ) . encode ( ) [ ..] , nodes[ 1 ] . keys_manager ,
707
744
) . unwrap ( ) . 1 ;
708
745
let mut channel_monitors = HashMap :: new ( ) ;
709
746
channel_monitors. insert ( chanmon_1. get_funding_txo ( ) . 0 , & mut chanmon_1) ;
@@ -721,12 +758,18 @@ fn test_onion_failure_stale_channel_update() {
721
758
} ,
722
759
) . unwrap ( ) . 1 ;
723
760
chanmgr. list_channels ( ) . iter ( )
724
- . find ( |channel| channel. channel_id == channel_to_update. 2 ) . unwrap ( )
761
+ . find ( |channel| channel. channel_id == channel_to_update. 0 ) . unwrap ( )
725
762
. config . unwrap ( )
726
763
} ;
727
764
assert_eq ! ( config, config_after_restart) ;
728
765
}
729
766
767
+ #[ test]
768
+ fn test_onion_failure_stale_channel_update ( ) {
769
+ do_test_onion_failure_stale_channel_update ( false ) ;
770
+ do_test_onion_failure_stale_channel_update ( true ) ;
771
+ }
772
+
730
773
#[ test]
731
774
fn test_default_to_onion_payload_tlv_format ( ) {
732
775
// Tests that we default to creating tlv format onion payloads when no `NodeAnnouncementInfo`
0 commit comments