@@ -2302,6 +2302,15 @@ fn claim_htlc_outputs_single_tx() {
2302
2302
let header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
2303
2303
nodes[ 0 ] . block_notifier . block_connected ( & Block { header, txdata : vec ! [ revoked_local_txn[ 0 ] . clone( ) ] } , 200 ) ;
2304
2304
nodes[ 1 ] . block_notifier . block_connected ( & Block { header, txdata : vec ! [ revoked_local_txn[ 0 ] . clone( ) ] } , 200 ) ;
2305
+
2306
+ // Expect pending failures, but we don't bother trying to update the channel state with them.
2307
+ let events = nodes[ 0 ] . node . get_and_clear_pending_events ( ) ;
2308
+ assert_eq ! ( events. len( ) , 1 ) ;
2309
+ match events[ 0 ] {
2310
+ Event :: PendingHTLCsForwardable { .. } => { } ,
2311
+ _ => panic ! ( "Unexpected event" ) ,
2312
+ } ;
2313
+
2305
2314
connect_blocks ( & nodes[ 1 ] . block_notifier , ANTI_REORG_DELAY - 1 , 200 , true , header. bitcoin_hash ( ) ) ;
2306
2315
2307
2316
let events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
@@ -3572,6 +3581,49 @@ fn test_drop_messages_peer_disconnect_dual_htlc() {
3572
3581
claim_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , payment_preimage_2, 1_000_000 ) ;
3573
3582
}
3574
3583
3584
+ #[ test]
3585
+ fn test_htlc_timeout ( ) {
3586
+ // If the user fails to claim/fail an HTLC within the HTLC CLTV timeout we fail it for them
3587
+ // to avoid our counterparty failing the channel.
3588
+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
3589
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
3590
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
3591
+ let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
3592
+
3593
+ create_announced_chan_between_nodes ( & nodes, 0 , 1 , InitFeatures :: supported ( ) , InitFeatures :: supported ( ) ) ;
3594
+ let ( _, our_payment_hash) = route_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , 100000 ) ;
3595
+
3596
+ let mut header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
3597
+ nodes[ 0 ] . block_notifier . block_connected_checked ( & header, 101 , & [ ] , & [ ] ) ;
3598
+ nodes[ 1 ] . block_notifier . block_connected_checked ( & header, 101 , & [ ] , & [ ] ) ;
3599
+ for i in 102 ..TEST_FINAL_CLTV + 100 + 1 - CLTV_CLAIM_BUFFER - LATENCY_GRACE_PERIOD_BLOCKS {
3600
+ header. prev_blockhash = header. bitcoin_hash ( ) ;
3601
+ nodes[ 0 ] . block_notifier . block_connected_checked ( & header, i, & [ ] , & [ ] ) ;
3602
+ nodes[ 1 ] . block_notifier . block_connected_checked ( & header, i, & [ ] , & [ ] ) ;
3603
+ }
3604
+
3605
+ expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
3606
+
3607
+ check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
3608
+ let htlc_timeout_updates = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
3609
+ assert ! ( htlc_timeout_updates. update_add_htlcs. is_empty( ) ) ;
3610
+ assert_eq ! ( htlc_timeout_updates. update_fail_htlcs. len( ) , 1 ) ;
3611
+ assert ! ( htlc_timeout_updates. update_fail_malformed_htlcs. is_empty( ) ) ;
3612
+ assert ! ( htlc_timeout_updates. update_fee. is_none( ) ) ;
3613
+
3614
+ nodes[ 0 ] . node . handle_update_fail_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & htlc_timeout_updates. update_fail_htlcs [ 0 ] ) ;
3615
+ commitment_signed_dance ! ( nodes[ 0 ] , nodes[ 1 ] , htlc_timeout_updates. commitment_signed, false ) ;
3616
+ let events = nodes[ 0 ] . node . get_and_clear_pending_events ( ) ;
3617
+ match events[ 0 ] {
3618
+ Event :: PaymentFailed { payment_hash, rejected_by_dest, error_code } => {
3619
+ assert_eq ! ( payment_hash, our_payment_hash) ;
3620
+ assert ! ( rejected_by_dest) ;
3621
+ assert_eq ! ( error_code. unwrap( ) , 0x4000 | 15 ) ;
3622
+ } ,
3623
+ _ => panic ! ( "Unexpected event" ) ,
3624
+ }
3625
+ }
3626
+
3575
3627
#[ test]
3576
3628
fn test_invalid_channel_announcement ( ) {
3577
3629
//Test BOLT 7 channel_announcement msg requirement for final node, gather data to build customed channel_announcement msgs
@@ -6879,6 +6931,15 @@ fn test_bump_penalty_txn_on_revoked_htlcs() {
6879
6931
6880
6932
// Broadcast set of revoked txn on A
6881
6933
let header_128 = connect_blocks ( & nodes[ 0 ] . block_notifier , 128 , 0 , true , header. bitcoin_hash ( ) ) ;
6934
+
6935
+ // Expect pending failures, but we don't bother trying to update the channel state with them.
6936
+ let events = nodes[ 0 ] . node . get_and_clear_pending_events ( ) ;
6937
+ assert_eq ! ( events. len( ) , 1 ) ;
6938
+ match events[ 0 ] {
6939
+ Event :: PendingHTLCsForwardable { .. } => { } ,
6940
+ _ => panic ! ( "Unexpected event" ) ,
6941
+ } ;
6942
+
6882
6943
let header_129 = BlockHeader { version : 0x20000000 , prev_blockhash : header_128, merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
6883
6944
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 ) ;
6884
6945
let first;
@@ -7201,6 +7262,15 @@ fn test_bump_txn_sanitize_tracking_maps() {
7201
7262
7202
7263
// Broadcast set of revoked txn on A
7203
7264
let header_128 = connect_blocks ( & nodes[ 0 ] . block_notifier , 128 , 0 , false , Default :: default ( ) ) ;
7265
+
7266
+ // Expect pending failures, but we don't bother trying to update the channel state with them.
7267
+ let events = nodes[ 0 ] . node . get_and_clear_pending_events ( ) ;
7268
+ assert_eq ! ( events. len( ) , 1 ) ;
7269
+ match events[ 0 ] {
7270
+ Event :: PendingHTLCsForwardable { .. } => { } ,
7271
+ _ => panic ! ( "Unexpected event" ) ,
7272
+ } ;
7273
+
7204
7274
let header_129 = BlockHeader { version : 0x20000000 , prev_blockhash : header_128, merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
7205
7275
nodes[ 0 ] . block_notifier . block_connected ( & Block { header : header_129, txdata : vec ! [ revoked_local_txn[ 0 ] . clone( ) ] } , 129 ) ;
7206
7276
check_closed_broadcast ! ( nodes[ 0 ] , false ) ;
0 commit comments