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