@@ -32,8 +32,8 @@ use crate::ln::channel::{
32
32
MIN_CHAN_DUST_LIMIT_SATOSHIS , UNFUNDED_CHANNEL_AGE_LIMIT_TICKS ,
33
33
} ;
34
34
use crate :: ln:: channelmanager:: {
35
- PaymentId , RAACommitmentOrder , RecipientOnionFields , BREAKDOWN_TIMEOUT , DISABLE_GOSSIP_TICKS ,
36
- ENABLE_GOSSIP_TICKS , MIN_CLTV_EXPIRY_DELTA ,
35
+ PaymentId , RAACommitmentOrder , RecipientOnionFields , Retry , BREAKDOWN_TIMEOUT ,
36
+ DISABLE_GOSSIP_TICKS , ENABLE_GOSSIP_TICKS , MIN_CLTV_EXPIRY_DELTA ,
37
37
} ;
38
38
use crate :: ln:: msgs;
39
39
use crate :: ln:: msgs:: {
@@ -9680,3 +9680,82 @@ pub fn test_multi_post_event_actions() {
9680
9680
do_test_multi_post_event_actions ( true ) ;
9681
9681
do_test_multi_post_event_actions ( false ) ;
9682
9682
}
9683
+
9684
+ #[ xtest( feature = "_externalize_tests" ) ]
9685
+ fn test_stale_force_close_with_identical_htlcs ( ) {
9686
+ let chanmon_cfgs = create_chanmon_cfgs ( 3 ) ;
9687
+ let node_cfgs = create_node_cfgs ( 3 , & chanmon_cfgs) ;
9688
+ let node_chanmgrs = create_node_chanmgrs ( 3 , & node_cfgs, & [ None , None , None ] ) ;
9689
+ let nodes = create_network ( 3 , & node_cfgs, & node_chanmgrs) ;
9690
+
9691
+ let chan_a_b = create_announced_chan_between_nodes ( & nodes, 0 , 1 ) ;
9692
+ let _chan_b_c = create_announced_chan_between_nodes ( & nodes, 1 , 2 ) ;
9693
+
9694
+ let stale_tx = get_local_commitment_txn ! ( nodes[ 0 ] , chan_a_b. 2 ) [ 0 ] . clone ( ) ;
9695
+
9696
+ let ( _payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash ! ( nodes[ 2 ] ) ;
9697
+
9698
+ let make_event = |pid : PaymentId | {
9699
+ let payment_params = PaymentParameters :: from_node_id ( nodes[ 2 ] . node . get_our_node_id ( ) , 42 ) ;
9700
+ let route_params = RouteParameters :: from_payment_params_and_value ( payment_params, 10_000 ) ;
9701
+ nodes[ 0 ]
9702
+ . node
9703
+ . send_payment (
9704
+ payment_hash,
9705
+ RecipientOnionFields :: secret_only ( payment_secret) ,
9706
+ pid,
9707
+ route_params,
9708
+ Retry :: Attempts ( 0 ) ,
9709
+ )
9710
+ . unwrap ( ) ;
9711
+ check_added_monitors ! ( & nodes[ 0 ] , 1 ) ;
9712
+ let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
9713
+ remove_first_msg_event_to_node ( & nodes[ 1 ] . node . get_our_node_id ( ) , & mut events)
9714
+ } ;
9715
+
9716
+ let first_event = make_event ( PaymentId ( [ 1 ; 32 ] ) ) ;
9717
+ do_pass_along_path (
9718
+ PassAlongPathArgs :: new (
9719
+ & nodes[ 0 ] ,
9720
+ & [ & nodes[ 1 ] , & nodes[ 2 ] ] ,
9721
+ 10_000 ,
9722
+ payment_hash,
9723
+ first_event,
9724
+ )
9725
+ . with_payment_secret ( payment_secret)
9726
+ . without_clearing_recipient_events ( )
9727
+ . without_claimable_event ( ) ,
9728
+ ) ;
9729
+
9730
+ let second_event = make_event ( PaymentId ( [ 2 ; 32 ] ) ) ;
9731
+ do_pass_along_path (
9732
+ PassAlongPathArgs :: new (
9733
+ & nodes[ 0 ] ,
9734
+ & [ & nodes[ 1 ] , & nodes[ 2 ] ] ,
9735
+ 10_000 ,
9736
+ payment_hash,
9737
+ second_event,
9738
+ )
9739
+ . with_payment_secret ( payment_secret)
9740
+ . without_clearing_recipient_events ( )
9741
+ . without_claimable_event ( ) ,
9742
+ ) ;
9743
+
9744
+ mine_transaction ( & nodes[ 1 ] , & stale_tx) ;
9745
+ check_added_monitors ( & nodes[ 1 ] , 1 ) ;
9746
+ nodes[ 1 ] . node . process_pending_htlc_forwards ( ) ;
9747
+
9748
+ let events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
9749
+ let failed = events
9750
+ . iter ( )
9751
+ . filter ( |e| matches ! ( e, crate :: events:: Event :: HTLCHandlingFailed { .. } ) )
9752
+ . count ( ) ;
9753
+ assert_eq ! (
9754
+ failed, 2 ,
9755
+ "ChannelMonitor should immediately surface two HTLC failures after stale close"
9756
+ ) ;
9757
+
9758
+ nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
9759
+ nodes[ 2 ] . node . get_and_clear_pending_events ( ) ;
9760
+ nodes[ 2 ] . node . get_and_clear_pending_msg_events ( ) ;
9761
+ }
0 commit comments