@@ -2323,6 +2323,15 @@ fn claim_htlc_outputs_single_tx() {
2323
2323
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
2324
2324
nodes[ 1 ] . block_notifier . block_connected ( & Block { header, txdata : vec ! [ revoked_local_txn[ 0 ] . clone( ) ] } , 200 ) ;
2325
2325
check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
2326
+
2327
+ // Expect pending failures, but we don't bother trying to update the channel state with them.
2328
+ let events = nodes[ 0 ] . node . get_and_clear_pending_events ( ) ;
2329
+ assert_eq ! ( events. len( ) , 1 ) ;
2330
+ match events[ 0 ] {
2331
+ Event :: PendingHTLCsForwardable { .. } => { } ,
2332
+ _ => panic ! ( "Unexpected event" ) ,
2333
+ } ;
2334
+
2326
2335
connect_blocks ( & nodes[ 1 ] . block_notifier , ANTI_REORG_DELAY - 1 , 200 , true , header. bitcoin_hash ( ) ) ;
2327
2336
2328
2337
let events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
@@ -3680,6 +3689,49 @@ fn test_drop_messages_peer_disconnect_dual_htlc() {
3680
3689
claim_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , payment_preimage_2, 1_000_000 ) ;
3681
3690
}
3682
3691
3692
+ #[ test]
3693
+ fn test_htlc_timeout ( ) {
3694
+ // If the user fails to claim/fail an HTLC within the HTLC CLTV timeout we fail it for them
3695
+ // to avoid our counterparty failing the channel.
3696
+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
3697
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
3698
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
3699
+ let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
3700
+
3701
+ create_announced_chan_between_nodes ( & nodes, 0 , 1 , InitFeatures :: supported ( ) , InitFeatures :: supported ( ) ) ;
3702
+ let ( _, our_payment_hash) = route_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , 100000 ) ;
3703
+
3704
+ let mut header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
3705
+ nodes[ 0 ] . block_notifier . block_connected_checked ( & header, 101 , & [ ] , & [ ] ) ;
3706
+ nodes[ 1 ] . block_notifier . block_connected_checked ( & header, 101 , & [ ] , & [ ] ) ;
3707
+ for i in 102 ..TEST_FINAL_CLTV + 100 + 1 - CLTV_CLAIM_BUFFER - LATENCY_GRACE_PERIOD_BLOCKS {
3708
+ header. prev_blockhash = header. bitcoin_hash ( ) ;
3709
+ nodes[ 0 ] . block_notifier . block_connected_checked ( & header, i, & [ ] , & [ ] ) ;
3710
+ nodes[ 1 ] . block_notifier . block_connected_checked ( & header, i, & [ ] , & [ ] ) ;
3711
+ }
3712
+
3713
+ expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
3714
+
3715
+ check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
3716
+ let htlc_timeout_updates = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
3717
+ assert ! ( htlc_timeout_updates. update_add_htlcs. is_empty( ) ) ;
3718
+ assert_eq ! ( htlc_timeout_updates. update_fail_htlcs. len( ) , 1 ) ;
3719
+ assert ! ( htlc_timeout_updates. update_fail_malformed_htlcs. is_empty( ) ) ;
3720
+ assert ! ( htlc_timeout_updates. update_fee. is_none( ) ) ;
3721
+
3722
+ nodes[ 0 ] . node . handle_update_fail_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & htlc_timeout_updates. update_fail_htlcs [ 0 ] ) ;
3723
+ commitment_signed_dance ! ( nodes[ 0 ] , nodes[ 1 ] , htlc_timeout_updates. commitment_signed, false ) ;
3724
+ let events = nodes[ 0 ] . node . get_and_clear_pending_events ( ) ;
3725
+ match events[ 0 ] {
3726
+ Event :: PaymentFailed { payment_hash, rejected_by_dest, error_code } => {
3727
+ assert_eq ! ( payment_hash, our_payment_hash) ;
3728
+ assert ! ( rejected_by_dest) ;
3729
+ assert_eq ! ( error_code. unwrap( ) , 0x4000 | 15 ) ;
3730
+ } ,
3731
+ _ => panic ! ( "Unexpected event" ) ,
3732
+ }
3733
+ }
3734
+
3683
3735
#[ test]
3684
3736
fn test_invalid_channel_announcement ( ) {
3685
3737
//Test BOLT 7 channel_announcement msg requirement for final node, gather data to build customed channel_announcement msgs
@@ -7159,6 +7211,15 @@ fn test_bump_penalty_txn_on_revoked_htlcs() {
7159
7211
7160
7212
// Broadcast set of revoked txn on A
7161
7213
let header_128 = connect_blocks ( & nodes[ 0 ] . block_notifier , 128 , 0 , true , header. bitcoin_hash ( ) ) ;
7214
+
7215
+ // Expect pending failures, but we don't bother trying to update the channel state with them.
7216
+ let events = nodes[ 0 ] . node . get_and_clear_pending_events ( ) ;
7217
+ assert_eq ! ( events. len( ) , 1 ) ;
7218
+ match events[ 0 ] {
7219
+ Event :: PendingHTLCsForwardable { .. } => { } ,
7220
+ _ => panic ! ( "Unexpected event" ) ,
7221
+ } ;
7222
+
7162
7223
let header_129 = BlockHeader { version : 0x20000000 , prev_blockhash : header_128, merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
7163
7224
nodes[ 0 ] . block_notifier . block_connected ( & Block { header : header_129, txdata : vec ! [ revoked_local_txn[ 0 ] . clone( ) , revoked_htlc_txn[ 0 ] . clone( ) , revoked_htlc_txn[ 1 ] . clone( ) ] } , 129 ) ;
7164
7225
let first;
@@ -7491,6 +7552,15 @@ fn test_bump_txn_sanitize_tracking_maps() {
7491
7552
7492
7553
// Broadcast set of revoked txn on A
7493
7554
let header_128 = connect_blocks ( & nodes[ 0 ] . block_notifier , 128 , 0 , false , Default :: default ( ) ) ;
7555
+
7556
+ // Expect pending failures, but we don't bother trying to update the channel state with them.
7557
+ let events = nodes[ 0 ] . node . get_and_clear_pending_events ( ) ;
7558
+ assert_eq ! ( events. len( ) , 1 ) ;
7559
+ match events[ 0 ] {
7560
+ Event :: PendingHTLCsForwardable { .. } => { } ,
7561
+ _ => panic ! ( "Unexpected event" ) ,
7562
+ } ;
7563
+
7494
7564
let header_129 = BlockHeader { version : 0x20000000 , prev_blockhash : header_128, merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
7495
7565
nodes[ 0 ] . block_notifier . block_connected ( & Block { header : header_129, txdata : vec ! [ revoked_local_txn[ 0 ] . clone( ) ] } , 129 ) ;
7496
7566
check_closed_broadcast ! ( nodes[ 0 ] , false ) ;
0 commit comments