@@ -1499,16 +1499,17 @@ fn test_duplicate_htlc_different_direction_onchain() {
1499
1499
1500
1500
// Check we only broadcast 1 timeout tx
1501
1501
let claim_txn = nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ;
1502
- let htlc_pair = if claim_txn[ 0 ] . output [ 0 ] . value == 800_000 / 1000 { ( claim_txn[ 0 ] . clone ( ) , claim_txn[ 1 ] . clone ( ) ) } else { ( claim_txn[ 1 ] . clone ( ) , claim_txn[ 0 ] . clone ( ) ) } ;
1503
1502
assert_eq ! ( claim_txn. len( ) , 5 ) ;
1504
1503
check_spends ! ( claim_txn[ 2 ] , chan_1. 3 ) ;
1505
1504
check_spends ! ( claim_txn[ 3 ] , claim_txn[ 2 ] ) ;
1506
- assert_eq ! ( htlc_pair. 0 . input. len( ) , 1 ) ;
1507
- assert_eq ! ( htlc_pair. 0 . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , OFFERED_HTLC_SCRIPT_WEIGHT ) ; // HTLC 1 <--> 0, preimage tx
1508
- check_spends ! ( htlc_pair. 0 , remote_txn[ 0 ] ) ;
1509
- assert_eq ! ( htlc_pair. 1 . input. len( ) , 1 ) ;
1510
- assert_eq ! ( htlc_pair. 1 . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , ACCEPTED_HTLC_SCRIPT_WEIGHT ) ; // HTLC 0 <--> 1, timeout tx
1511
- check_spends ! ( htlc_pair. 1 , remote_txn[ 0 ] ) ;
1505
+ assert_eq ! ( claim_txn[ 1 ] . input. len( ) , 1 ) ;
1506
+ assert_eq ! ( claim_txn[ 1 ] . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , OFFERED_HTLC_SCRIPT_WEIGHT ) ; // HTLC 1 <--> 0, preimage tx
1507
+ check_spends ! ( claim_txn[ 1 ] , remote_txn[ 0 ] ) ;
1508
+ assert_eq ! ( remote_txn[ 0 ] . output[ claim_txn[ 1 ] . input[ 0 ] . previous_output. vout as usize ] . value, 800 ) ;
1509
+ assert_eq ! ( claim_txn[ 0 ] . input. len( ) , 1 ) ;
1510
+ assert_eq ! ( claim_txn[ 0 ] . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , ACCEPTED_HTLC_SCRIPT_WEIGHT ) ; // HTLC 0 <--> 1, timeout tx
1511
+ check_spends ! ( claim_txn[ 0 ] , remote_txn[ 0 ] ) ;
1512
+ assert_eq ! ( remote_txn[ 0 ] . output[ claim_txn[ 0 ] . input[ 0 ] . previous_output. vout as usize ] . value, 900 ) ;
1512
1513
1513
1514
let events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
1514
1515
assert_eq ! ( events. len( ) , 3 ) ;
@@ -5308,11 +5309,20 @@ fn test_duplicate_payment_hash_one_failure_one_success() {
5308
5309
let chan_2 = create_announced_chan_between_nodes ( & nodes, 1 , 2 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
5309
5310
create_announced_chan_between_nodes ( & nodes, 2 , 3 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
5310
5311
5312
+ let node_max_height = std:: cmp:: max ( std:: cmp:: max ( nodes[ 0 ] . blocks . borrow ( ) . len ( ) , nodes[ 1 ] . blocks . borrow ( ) . len ( ) ) , std:: cmp:: max ( nodes[ 2 ] . blocks . borrow ( ) . len ( ) , nodes[ 3 ] . blocks . borrow ( ) . len ( ) ) ) as u32 ;
5313
+ connect_blocks ( & nodes[ 0 ] , node_max_height - nodes[ 0 ] . best_block_info ( ) . 1 ) ;
5314
+ connect_blocks ( & nodes[ 1 ] , node_max_height - nodes[ 1 ] . best_block_info ( ) . 1 ) ;
5315
+ connect_blocks ( & nodes[ 2 ] , node_max_height - nodes[ 2 ] . best_block_info ( ) . 1 ) ;
5316
+ connect_blocks ( & nodes[ 3 ] , node_max_height - nodes[ 3 ] . best_block_info ( ) . 1 ) ;
5317
+
5311
5318
let ( our_payment_preimage, duplicate_payment_hash, _) = route_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] , & nodes[ 2 ] ) [ ..] , 900000 ) ;
5312
5319
5313
5320
let payment_secret = nodes[ 3 ] . node . create_inbound_payment_for_hash ( duplicate_payment_hash, None , 7200 , 0 ) . unwrap ( ) ;
5321
+ // We reduce the final CLTV here by a somewhat arbitrary constant to keep it under the one-byte
5322
+ // script push size limit so that the below script length checks match
5323
+ // ACCEPTED_HTLC_SCRIPT_WEIGHT.
5314
5324
let route = get_route ( & nodes[ 0 ] . node . get_our_node_id ( ) , & nodes[ 0 ] . net_graph_msg_handler . network_graph . read ( ) . unwrap ( ) ,
5315
- & nodes[ 3 ] . node . get_our_node_id ( ) , Some ( InvoiceFeatures :: known ( ) ) , None , & Vec :: new ( ) , 900000 , TEST_FINAL_CLTV , nodes[ 0 ] . logger ) . unwrap ( ) ;
5325
+ & nodes[ 3 ] . node . get_our_node_id ( ) , Some ( InvoiceFeatures :: known ( ) ) , None , & Vec :: new ( ) , 900000 , TEST_FINAL_CLTV - 40 , nodes[ 0 ] . logger ) . unwrap ( ) ;
5316
5326
send_along_route_with_secret ( & nodes[ 0 ] , route, & [ & [ & nodes[ 1 ] , & nodes[ 2 ] , & nodes[ 3 ] ] ] , 900000 , duplicate_payment_hash, payment_secret) ;
5317
5327
5318
5328
let commitment_txn = get_local_commitment_txn ! ( nodes[ 2 ] , chan_2. 2 ) ;
@@ -5355,18 +5365,17 @@ fn test_duplicate_payment_hash_one_failure_one_success() {
5355
5365
}
5356
5366
let htlc_success_txn: Vec < _ > = nodes[ 2 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ;
5357
5367
assert_eq ! ( htlc_success_txn. len( ) , 5 ) ; // ChannelMonitor: HTLC-Success txn (*2 due to 2-HTLC outputs), ChannelManager: local commitment tx + HTLC-Success txn (*2 due to 2-HTLC outputs)
5358
- check_spends ! ( htlc_success_txn[ 2 ] , chan_2. 3 ) ;
5359
- check_spends ! ( htlc_success_txn[ 3 ] , htlc_success_txn[ 2 ] ) ;
5360
- check_spends ! ( htlc_success_txn[ 4 ] , htlc_success_txn[ 2 ] ) ;
5361
- assert_eq ! ( htlc_success_txn[ 0 ] , htlc_success_txn[ 3 ] ) ;
5368
+ check_spends ! ( htlc_success_txn[ 0 ] , commitment_txn[ 0 ] ) ;
5369
+ check_spends ! ( htlc_success_txn[ 1 ] , commitment_txn[ 0 ] ) ;
5362
5370
assert_eq ! ( htlc_success_txn[ 0 ] . input. len( ) , 1 ) ;
5363
5371
assert_eq ! ( htlc_success_txn[ 0 ] . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , ACCEPTED_HTLC_SCRIPT_WEIGHT ) ;
5364
- assert_eq ! ( htlc_success_txn[ 1 ] , htlc_success_txn[ 4 ] ) ;
5365
5372
assert_eq ! ( htlc_success_txn[ 1 ] . input. len( ) , 1 ) ;
5366
5373
assert_eq ! ( htlc_success_txn[ 1 ] . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , ACCEPTED_HTLC_SCRIPT_WEIGHT ) ;
5367
5374
assert_ne ! ( htlc_success_txn[ 0 ] . input[ 0 ] , htlc_success_txn[ 1 ] . input[ 0 ] ) ;
5368
- check_spends ! ( htlc_success_txn[ 0 ] , commitment_txn[ 0 ] ) ;
5369
- check_spends ! ( htlc_success_txn[ 1 ] , commitment_txn[ 0 ] ) ;
5375
+ assert_eq ! ( htlc_success_txn[ 2 ] , commitment_txn[ 0 ] ) ;
5376
+ assert_eq ! ( htlc_success_txn[ 3 ] , htlc_success_txn[ 0 ] ) ;
5377
+ assert_eq ! ( htlc_success_txn[ 4 ] , htlc_success_txn[ 1 ] ) ;
5378
+
5370
5379
5371
5380
mine_transaction ( & nodes[ 1 ] , & htlc_timeout_tx) ;
5372
5381
connect_blocks ( & nodes[ 1 ] , ANTI_REORG_DELAY - 1 ) ;
0 commit comments