@@ -1312,18 +1312,21 @@ fn test_duplicate_htlc_different_direction_onchain() {
1312
1312
1313
1313
let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1);
1314
1314
1315
+ let payment_value_sats = 546;
1316
+ let payment_value_msats = payment_value_sats * 1000;
1317
+
1315
1318
// balancing
1316
1319
send_payment(&nodes[0], &vec!(&nodes[1])[..], 8000000);
1317
1320
1318
1321
let (payment_preimage, payment_hash, ..) = route_payment(&nodes[0], &vec!(&nodes[1])[..], 900_000);
1319
1322
1320
- let (route, _, _, _) = get_route_and_payment_hash!(nodes[1], nodes[0], 800_000 );
1323
+ let (route, _, _, _) = get_route_and_payment_hash!(nodes[1], nodes[0], payment_value_msats );
1321
1324
let node_a_payment_secret = nodes[0].node.create_inbound_payment_for_hash(payment_hash, None, 7200, None).unwrap();
1322
- send_along_route_with_secret(&nodes[1], route, &[&[&nodes[0]]], 800_000 , payment_hash, node_a_payment_secret);
1325
+ send_along_route_with_secret(&nodes[1], route, &[&[&nodes[0]]], payment_value_msats , payment_hash, node_a_payment_secret);
1323
1326
1324
1327
// Provide preimage to node 0 by claiming payment
1325
1328
nodes[0].node.claim_funds(payment_preimage);
1326
- expect_payment_claimed!(nodes[0], payment_hash, 800_000 );
1329
+ expect_payment_claimed!(nodes[0], payment_hash, payment_value_msats );
1327
1330
check_added_monitors!(nodes[0], 1);
1328
1331
1329
1332
// Broadcast node 1 commitment txn
@@ -1332,7 +1335,7 @@ fn test_duplicate_htlc_different_direction_onchain() {
1332
1335
assert_eq!(remote_txn[0].output.len(), 4); // 1 local, 1 remote, 1 htlc inbound, 1 htlc outbound
1333
1336
let mut has_both_htlcs = 0; // check htlcs match ones committed
1334
1337
for outp in remote_txn[0].output.iter() {
1335
- if outp.value.to_sat() == 800_000 / 1000 {
1338
+ if outp.value.to_sat() == payment_value_sats {
1336
1339
has_both_htlcs += 1;
1337
1340
} else if outp.value.to_sat() == 900_000 / 1000 {
1338
1341
has_both_htlcs += 1;
@@ -1346,24 +1349,22 @@ fn test_duplicate_htlc_different_direction_onchain() {
1346
1349
connect_blocks(&nodes[0], TEST_FINAL_CLTV); // Confirm blocks until the HTLC expires
1347
1350
1348
1351
let claim_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().clone();
1349
- assert_eq!(claim_txn.len(), 3);
1352
+ assert!(claim_txn.len() >= 3);
1353
+ assert!(claim_txn.len() <= 5);
1350
1354
1351
1355
check_spends!(claim_txn[0], remote_txn[0]); // Immediate HTLC claim with preimage
1352
1356
check_spends!(claim_txn[1], remote_txn[0]);
1353
1357
check_spends!(claim_txn[2], remote_txn[0]);
1354
1358
let preimage_tx = &claim_txn[0];
1355
- let (preimage_bump_tx, timeout_tx) = if claim_txn[1].input[0].previous_output == preimage_tx.input[0].previous_output {
1356
- (&claim_txn[1], &claim_txn[2])
1357
- } else {
1358
- (&claim_txn[2], &claim_txn[1])
1359
- };
1359
+ let timeout_tx = claim_txn.iter().skip(1).find(|t| t.input[0].previous_output != preimage_tx.input[0].previous_output).unwrap();
1360
+ let preimage_bump_tx = claim_txn.iter().skip(1).find(|t| t.input[0].previous_output == preimage_tx.input[0].previous_output).unwrap();
1360
1361
1361
1362
assert_eq!(preimage_tx.input.len(), 1);
1362
1363
assert_eq!(preimage_bump_tx.input.len(), 1);
1363
1364
1364
1365
assert_eq!(preimage_tx.input.len(), 1);
1365
1366
assert_eq!(preimage_tx.input[0].witness.last().unwrap().len(), OFFERED_HTLC_SCRIPT_WEIGHT); // HTLC 1 <--> 0, preimage tx
1366
- assert_eq!(remote_txn[0].output[preimage_tx.input[0].previous_output.vout as usize].value.to_sat(), 800 );
1367
+ assert_eq!(remote_txn[0].output[preimage_tx.input[0].previous_output.vout as usize].value.to_sat(), payment_value_sats );
1367
1368
1368
1369
assert_eq!(timeout_tx.input.len(), 1);
1369
1370
assert_eq!(timeout_tx.input[0].witness.last().unwrap().len(), ACCEPTED_HTLC_SCRIPT_WEIGHT); // HTLC 0 <--> 1, timeout tx
0 commit comments