@@ -2106,6 +2106,15 @@ fn claim_htlc_outputs_single_tx() {
2106
2106
let header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
2107
2107
nodes[ 0 ] . block_notifier . block_connected ( & Block { header, txdata : vec ! [ revoked_local_txn[ 0 ] . clone( ) ] } , 200 ) ;
2108
2108
nodes[ 1 ] . block_notifier . block_connected ( & Block { header, txdata : vec ! [ revoked_local_txn[ 0 ] . clone( ) ] } , 200 ) ;
2109
+
2110
+ // Expect pending failures, but we don't bother trying to update the channel state with them.
2111
+ let events = nodes[ 0 ] . node . get_and_clear_pending_events ( ) ;
2112
+ assert_eq ! ( events. len( ) , 1 ) ;
2113
+ match events[ 0 ] {
2114
+ Event :: PendingHTLCsForwardable { .. } => { } ,
2115
+ _ => panic ! ( "Unexpected event" ) ,
2116
+ } ;
2117
+
2109
2118
connect_blocks ( & nodes[ 1 ] . block_notifier , ANTI_REORG_DELAY - 1 , 200 , true , header. bitcoin_hash ( ) ) ;
2110
2119
2111
2120
let events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
@@ -3338,6 +3347,47 @@ fn test_drop_messages_peer_disconnect_dual_htlc() {
3338
3347
claim_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , payment_preimage_2, 1_000_000 ) ;
3339
3348
}
3340
3349
3350
+
3351
+ #[ test]
3352
+ fn test_htlc_timeout ( ) {
3353
+ // If the user fails to claim/fail an HTLC within the HTLC CLTV timeout we fail it for them
3354
+ // to avoid our counterparty failing the channel.
3355
+ let nodes = create_network ( 2 , & [ None , None ] ) ;
3356
+
3357
+ create_announced_chan_between_nodes ( & nodes, 0 , 1 , InitFeatures :: supported ( ) , InitFeatures :: supported ( ) ) ;
3358
+ let ( _, our_payment_hash) = route_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , 100000 ) ;
3359
+
3360
+ let mut header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
3361
+ nodes[ 0 ] . block_notifier . block_connected_checked ( & header, 101 , & [ ] , & [ ] ) ;
3362
+ nodes[ 1 ] . block_notifier . block_connected_checked ( & header, 101 , & [ ] , & [ ] ) ;
3363
+ for i in 102 ..TEST_FINAL_CLTV + 100 + 1 - CLTV_CLAIM_BUFFER - LATENCY_GRACE_PERIOD_BLOCKS {
3364
+ header. prev_blockhash = header. bitcoin_hash ( ) ;
3365
+ nodes[ 0 ] . block_notifier . block_connected_checked ( & header, i, & [ ] , & [ ] ) ;
3366
+ nodes[ 1 ] . block_notifier . block_connected_checked ( & header, i, & [ ] , & [ ] ) ;
3367
+ }
3368
+
3369
+ expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
3370
+
3371
+ check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
3372
+ let htlc_timeout_updates = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
3373
+ assert ! ( htlc_timeout_updates. update_add_htlcs. is_empty( ) ) ;
3374
+ assert_eq ! ( htlc_timeout_updates. update_fail_htlcs. len( ) , 1 ) ;
3375
+ assert ! ( htlc_timeout_updates. update_fail_malformed_htlcs. is_empty( ) ) ;
3376
+ assert ! ( htlc_timeout_updates. update_fee. is_none( ) ) ;
3377
+
3378
+ nodes[ 0 ] . node . handle_update_fail_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & htlc_timeout_updates. update_fail_htlcs [ 0 ] ) ;
3379
+ commitment_signed_dance ! ( nodes[ 0 ] , nodes[ 1 ] , htlc_timeout_updates. commitment_signed, false ) ;
3380
+ let events = nodes[ 0 ] . node . get_and_clear_pending_events ( ) ;
3381
+ match events[ 0 ] {
3382
+ Event :: PaymentFailed { payment_hash, rejected_by_dest, error_code } => {
3383
+ assert_eq ! ( payment_hash, our_payment_hash) ;
3384
+ assert ! ( rejected_by_dest) ;
3385
+ assert_eq ! ( error_code. unwrap( ) , 0x4000 | 15 ) ;
3386
+ } ,
3387
+ _ => panic ! ( "Unexpected event" ) ,
3388
+ }
3389
+ }
3390
+
3341
3391
#[ test]
3342
3392
fn test_invalid_channel_announcement ( ) {
3343
3393
//Test BOLT 7 channel_announcement msg requirement for final node, gather data to build customed channel_announcement msgs
@@ -6479,6 +6529,15 @@ fn test_bump_penalty_txn_on_revoked_htlcs() {
6479
6529
6480
6530
// Broadcast set of revoked txn on A
6481
6531
let header_128 = connect_blocks ( & nodes[ 0 ] . block_notifier , 128 , 0 , true , header. bitcoin_hash ( ) ) ;
6532
+
6533
+ // Expect pending failures, but we don't bother trying to update the channel state with them.
6534
+ let events = nodes[ 0 ] . node . get_and_clear_pending_events ( ) ;
6535
+ assert_eq ! ( events. len( ) , 1 ) ;
6536
+ match events[ 0 ] {
6537
+ Event :: PendingHTLCsForwardable { .. } => { } ,
6538
+ _ => panic ! ( "Unexpected event" ) ,
6539
+ } ;
6540
+
6482
6541
let header_129 = BlockHeader { version : 0x20000000 , prev_blockhash : header_128, merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
6483
6542
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 ) ;
6484
6543
let first;
@@ -6795,6 +6854,15 @@ fn test_bump_txn_sanitize_tracking_maps() {
6795
6854
6796
6855
// Broadcast set of revoked txn on A
6797
6856
let header_128 = connect_blocks ( & nodes[ 0 ] . block_notifier , 128 , 0 , false , Default :: default ( ) ) ;
6857
+
6858
+ // Expect pending failures, but we don't bother trying to update the channel state with them.
6859
+ let events = nodes[ 0 ] . node . get_and_clear_pending_events ( ) ;
6860
+ assert_eq ! ( events. len( ) , 1 ) ;
6861
+ match events[ 0 ] {
6862
+ Event :: PendingHTLCsForwardable { .. } => { } ,
6863
+ _ => panic ! ( "Unexpected event" ) ,
6864
+ } ;
6865
+
6798
6866
let header_129 = BlockHeader { version : 0x20000000 , prev_blockhash : header_128, merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
6799
6867
nodes[ 0 ] . block_notifier . block_connected ( & Block { header : header_129, txdata : vec ! [ revoked_local_txn[ 0 ] . clone( ) ] } , 129 ) ;
6800
6868
check_closed_broadcast ! ( nodes[ 0 ] , false ) ;
0 commit comments