@@ -616,9 +616,25 @@ fn test_onion_failure_stale_channel_update() {
616
616
const PAYMENT_AMT : u64 = 40000 ;
617
617
send_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] , & nodes[ 2 ] ] , PAYMENT_AMT ) ;
618
618
619
+ // Closure to connect a block with a timestamp that will increase a channel's
620
+ // `update_time_counter`.
621
+ let connect_block = |timestamp : u32 | {
622
+ connect_block ( & nodes[ 1 ] , & bitcoin:: Block {
623
+ header : bitcoin:: BlockHeader {
624
+ version : 2 ,
625
+ prev_blockhash : nodes[ 1 ] . best_block_hash ( ) ,
626
+ merkle_root : Default :: default ( ) ,
627
+ time : timestamp,
628
+ bits : 42 ,
629
+ nonce : 42 ,
630
+ } ,
631
+ txdata : vec ! [ ] ,
632
+ } ) ;
633
+ } ;
634
+
619
635
// Closure to update and retrieve the latest ChannelUpdate.
620
636
let update_and_get_channel_update = |config : & ChannelConfig , expect_new_update : bool ,
621
- prev_update : Option < & msgs:: ChannelUpdate > | -> Option < msgs:: ChannelUpdate > {
637
+ prev_update : Option < & msgs:: ChannelUpdate > , expire_prev_config : bool | -> Option < msgs:: ChannelUpdate > {
622
638
nodes[ 1 ] . node . update_channel_config (
623
639
channel_to_update_counterparty, & [ channel_to_update. 2 ] , config,
624
640
) . unwrap ( ) ;
@@ -634,13 +650,16 @@ fn test_onion_failure_stale_channel_update() {
634
650
if prev_update. is_some ( ) {
635
651
assert ! ( new_update. contents. timestamp > prev_update. unwrap( ) . contents. timestamp)
636
652
}
653
+ if expire_prev_config {
654
+ connect_block ( new_update. contents . timestamp + 1 ) ;
655
+ }
637
656
Some ( new_update)
638
657
} ;
639
658
640
659
// We'll be attempting to route payments using the default ChannelUpdate for channels. This will
641
660
// lead to onion failures at the first hop once we update the HTLC relay parameters for the
642
661
// second hop.
643
- let ( route, payment_hash, _ , payment_secret) = get_route_and_payment_hash ! (
662
+ let ( route, payment_hash, payment_preimage , payment_secret) = get_route_and_payment_hash ! (
644
663
nodes[ 0 ] , nodes[ 2 ] , PAYMENT_AMT
645
664
) ;
646
665
let expect_onion_failure = |name : & str , error_code : u16 , channel_update : & msgs:: ChannelUpdate | {
@@ -667,28 +686,37 @@ fn test_onion_failure_stale_channel_update() {
667
686
. find ( |channel| channel. channel_id == channel_to_update. 2 ) . unwrap ( )
668
687
. config . unwrap ( ) ;
669
688
config. forwarding_fee_base_msat = u32:: max_value ( ) ;
670
- let msg = update_and_get_channel_update ( & config, true , None ) . unwrap ( ) ;
689
+ let msg = update_and_get_channel_update ( & config, true , None , false ) . unwrap ( ) ;
690
+
691
+ // The old policy should still be in effect until a new block is connected.
692
+ send_along_route_with_secret ( & nodes[ 0 ] , route. clone ( ) , & [ & [ & nodes[ 1 ] , & nodes[ 2 ] ] ] , PAYMENT_AMT ,
693
+ payment_hash, payment_secret) ;
694
+ claim_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] , & nodes[ 2 ] ] , payment_preimage) ;
695
+
696
+ // Connect a block, which should expire the previous config, leading to a failure when
697
+ // forwarding the HTLC.
698
+ connect_block ( msg. contents . timestamp + 1 ) ;
671
699
expect_onion_failure ( "fee_insufficient" , UPDATE |12 , & msg) ;
672
700
673
701
// Redundant updates should not trigger a new ChannelUpdate.
674
- assert ! ( update_and_get_channel_update( & config, false , None ) . is_none( ) ) ;
702
+ assert ! ( update_and_get_channel_update( & config, false , None , false ) . is_none( ) ) ;
675
703
676
704
// Similarly, updates that do not have an affect on ChannelUpdate should not trigger a new one.
677
705
config. force_close_avoidance_max_fee_satoshis *= 2 ;
678
- assert ! ( update_and_get_channel_update( & config, false , None ) . is_none( ) ) ;
706
+ assert ! ( update_and_get_channel_update( & config, false , None , false ) . is_none( ) ) ;
679
707
680
708
// Reset the base fee to the default and increase the proportional fee which should trigger a
681
709
// new ChannelUpdate.
682
710
config. forwarding_fee_base_msat = default_config. forwarding_fee_base_msat ;
683
711
config. cltv_expiry_delta = u16:: max_value ( ) ;
684
- let msg = update_and_get_channel_update ( & config, true , Some ( & msg) ) . unwrap ( ) ;
712
+ let msg = update_and_get_channel_update ( & config, true , Some ( & msg) , true ) . unwrap ( ) ;
685
713
expect_onion_failure ( "incorrect_cltv_expiry" , UPDATE |13 , & msg) ;
686
714
687
715
// Reset the proportional fee and increase the CLTV expiry delta which should trigger a new
688
716
// ChannelUpdate.
689
717
config. cltv_expiry_delta = default_config. cltv_expiry_delta ;
690
718
config. forwarding_fee_proportional_millionths = u32:: max_value ( ) ;
691
- let msg = update_and_get_channel_update ( & config, true , Some ( & msg) ) . unwrap ( ) ;
719
+ let msg = update_and_get_channel_update ( & config, true , Some ( & msg) , true ) . unwrap ( ) ;
692
720
expect_onion_failure ( "fee_insufficient" , UPDATE |12 , & msg) ;
693
721
694
722
// To test persistence of the updated config, we'll re-initialize the ChannelManager.
0 commit comments