@@ -2325,6 +2325,15 @@ fn claim_htlc_outputs_single_tx() {
2325
2325
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
2326
2326
nodes[ 1 ] . block_notifier . block_connected ( & Block { header, txdata : vec ! [ revoked_local_txn[ 0 ] . clone( ) ] } , 200 ) ;
2327
2327
check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
2328
+
2329
+ // Expect pending failures, but we don't bother trying to update the channel state with them.
2330
+ let events = nodes[ 0 ] . node . get_and_clear_pending_events ( ) ;
2331
+ assert_eq ! ( events. len( ) , 1 ) ;
2332
+ match events[ 0 ] {
2333
+ Event :: PendingHTLCsForwardable { .. } => { } ,
2334
+ _ => panic ! ( "Unexpected event" ) ,
2335
+ } ;
2336
+
2328
2337
connect_blocks ( & nodes[ 1 ] . block_notifier , ANTI_REORG_DELAY - 1 , 200 , true , header. bitcoin_hash ( ) ) ;
2329
2338
2330
2339
let events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
@@ -3658,6 +3667,49 @@ fn test_drop_messages_peer_disconnect_dual_htlc() {
3658
3667
claim_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , payment_preimage_2, 1_000_000 ) ;
3659
3668
}
3660
3669
3670
+ #[ test]
3671
+ fn test_htlc_timeout ( ) {
3672
+ // If the user fails to claim/fail an HTLC within the HTLC CLTV timeout we fail it for them
3673
+ // to avoid our counterparty failing the channel.
3674
+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
3675
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
3676
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
3677
+ let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
3678
+
3679
+ create_announced_chan_between_nodes ( & nodes, 0 , 1 , InitFeatures :: supported ( ) , InitFeatures :: supported ( ) ) ;
3680
+ let ( _, our_payment_hash) = route_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , 100000 ) ;
3681
+
3682
+ let mut header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
3683
+ nodes[ 0 ] . block_notifier . block_connected_checked ( & header, 101 , & [ ] , & [ ] ) ;
3684
+ nodes[ 1 ] . block_notifier . block_connected_checked ( & header, 101 , & [ ] , & [ ] ) ;
3685
+ for i in 102 ..TEST_FINAL_CLTV + 100 + 1 - CLTV_CLAIM_BUFFER - LATENCY_GRACE_PERIOD_BLOCKS {
3686
+ header. prev_blockhash = header. bitcoin_hash ( ) ;
3687
+ nodes[ 0 ] . block_notifier . block_connected_checked ( & header, i, & [ ] , & [ ] ) ;
3688
+ nodes[ 1 ] . block_notifier . block_connected_checked ( & header, i, & [ ] , & [ ] ) ;
3689
+ }
3690
+
3691
+ expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
3692
+
3693
+ check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
3694
+ let htlc_timeout_updates = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
3695
+ assert ! ( htlc_timeout_updates. update_add_htlcs. is_empty( ) ) ;
3696
+ assert_eq ! ( htlc_timeout_updates. update_fail_htlcs. len( ) , 1 ) ;
3697
+ assert ! ( htlc_timeout_updates. update_fail_malformed_htlcs. is_empty( ) ) ;
3698
+ assert ! ( htlc_timeout_updates. update_fee. is_none( ) ) ;
3699
+
3700
+ nodes[ 0 ] . node . handle_update_fail_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & htlc_timeout_updates. update_fail_htlcs [ 0 ] ) ;
3701
+ commitment_signed_dance ! ( nodes[ 0 ] , nodes[ 1 ] , htlc_timeout_updates. commitment_signed, false ) ;
3702
+ let events = nodes[ 0 ] . node . get_and_clear_pending_events ( ) ;
3703
+ match events[ 0 ] {
3704
+ Event :: PaymentFailed { payment_hash, rejected_by_dest, error_code } => {
3705
+ assert_eq ! ( payment_hash, our_payment_hash) ;
3706
+ assert ! ( rejected_by_dest) ;
3707
+ assert_eq ! ( error_code. unwrap( ) , 0x4000 | 15 ) ;
3708
+ } ,
3709
+ _ => panic ! ( "Unexpected event" ) ,
3710
+ }
3711
+ }
3712
+
3661
3713
#[ test]
3662
3714
fn test_invalid_channel_announcement ( ) {
3663
3715
//Test BOLT 7 channel_announcement msg requirement for final node, gather data to build customed channel_announcement msgs
@@ -7145,6 +7197,15 @@ fn test_bump_penalty_txn_on_revoked_htlcs() {
7145
7197
7146
7198
// Broadcast set of revoked txn on A
7147
7199
let header_128 = connect_blocks ( & nodes[ 0 ] . block_notifier , 128 , 0 , true , header. bitcoin_hash ( ) ) ;
7200
+
7201
+ // Expect pending failures, but we don't bother trying to update the channel state with them.
7202
+ let events = nodes[ 0 ] . node . get_and_clear_pending_events ( ) ;
7203
+ assert_eq ! ( events. len( ) , 1 ) ;
7204
+ match events[ 0 ] {
7205
+ Event :: PendingHTLCsForwardable { .. } => { } ,
7206
+ _ => panic ! ( "Unexpected event" ) ,
7207
+ } ;
7208
+
7148
7209
let header_129 = BlockHeader { version : 0x20000000 , prev_blockhash : header_128, merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
7149
7210
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 ) ;
7150
7211
let first;
@@ -7477,6 +7538,15 @@ fn test_bump_txn_sanitize_tracking_maps() {
7477
7538
7478
7539
// Broadcast set of revoked txn on A
7479
7540
let header_128 = connect_blocks ( & nodes[ 0 ] . block_notifier , 128 , 0 , false , Default :: default ( ) ) ;
7541
+
7542
+ // Expect pending failures, but we don't bother trying to update the channel state with them.
7543
+ let events = nodes[ 0 ] . node . get_and_clear_pending_events ( ) ;
7544
+ assert_eq ! ( events. len( ) , 1 ) ;
7545
+ match events[ 0 ] {
7546
+ Event :: PendingHTLCsForwardable { .. } => { } ,
7547
+ _ => panic ! ( "Unexpected event" ) ,
7548
+ } ;
7549
+
7480
7550
let header_129 = BlockHeader { version : 0x20000000 , prev_blockhash : header_128, merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
7481
7551
nodes[ 0 ] . block_notifier . block_connected ( & Block { header : header_129, txdata : vec ! [ revoked_local_txn[ 0 ] . clone( ) ] } , 129 ) ;
7482
7552
check_closed_broadcast ! ( nodes[ 0 ] , false ) ;
0 commit comments