@@ -1307,18 +1307,22 @@ fn test_duplicate_htlc_different_direction_onchain() {
1307
1307
1308
1308
let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1);
1309
1309
1310
+ // post-bump fee (288 satoshis) + dust threshold for output type (294 satoshis) = 582
1311
+ let payment_value_sats = 582;
1312
+ let payment_value_msats = payment_value_sats * 1000;
1313
+
1310
1314
// balancing
1311
1315
send_payment(&nodes[0], &vec!(&nodes[1])[..], 8000000);
1312
1316
1313
1317
let (payment_preimage, payment_hash, ..) = route_payment(&nodes[0], &vec!(&nodes[1])[..], 900_000);
1314
1318
1315
- let (route, _, _, _) = get_route_and_payment_hash!(nodes[1], nodes[0], 800_000 );
1319
+ let (route, _, _, _) = get_route_and_payment_hash!(nodes[1], nodes[0], payment_value_msats );
1316
1320
let node_a_payment_secret = nodes[0].node.create_inbound_payment_for_hash(payment_hash, None, 7200, None).unwrap();
1317
- send_along_route_with_secret(&nodes[1], route, &[&[&nodes[0]]], 800_000 , payment_hash, node_a_payment_secret);
1321
+ send_along_route_with_secret(&nodes[1], route, &[&[&nodes[0]]], payment_value_msats , payment_hash, node_a_payment_secret);
1318
1322
1319
1323
// Provide preimage to node 0 by claiming payment
1320
1324
nodes[0].node.claim_funds(payment_preimage);
1321
- expect_payment_claimed!(nodes[0], payment_hash, 800_000 );
1325
+ expect_payment_claimed!(nodes[0], payment_hash, payment_value_msats );
1322
1326
check_added_monitors!(nodes[0], 1);
1323
1327
1324
1328
// Broadcast node 1 commitment txn
@@ -1327,7 +1331,7 @@ fn test_duplicate_htlc_different_direction_onchain() {
1327
1331
assert_eq!(remote_txn[0].output.len(), 4); // 1 local, 1 remote, 1 htlc inbound, 1 htlc outbound
1328
1332
let mut has_both_htlcs = 0; // check htlcs match ones committed
1329
1333
for outp in remote_txn[0].output.iter() {
1330
- if outp.value.to_sat() == 800_000 / 1000 {
1334
+ if outp.value.to_sat() == payment_value_sats {
1331
1335
has_both_htlcs += 1;
1332
1336
} else if outp.value.to_sat() == 900_000 / 1000 {
1333
1337
has_both_htlcs += 1;
@@ -1347,18 +1351,15 @@ fn test_duplicate_htlc_different_direction_onchain() {
1347
1351
check_spends!(claim_txn[1], remote_txn[0]);
1348
1352
check_spends!(claim_txn[2], remote_txn[0]);
1349
1353
let preimage_tx = &claim_txn[0];
1350
- let (preimage_bump_tx, timeout_tx) = if claim_txn[1].input[0].previous_output == preimage_tx.input[0].previous_output {
1351
- (&claim_txn[1], &claim_txn[2])
1352
- } else {
1353
- (&claim_txn[2], &claim_txn[1])
1354
- };
1354
+ let timeout_tx = claim_txn.iter().skip(1).find(|t| t.input[0].previous_output != preimage_tx.input[0].previous_output).unwrap();
1355
+ let preimage_bump_tx = claim_txn.iter().skip(1).find(|t| t.input[0].previous_output == preimage_tx.input[0].previous_output).unwrap();
1355
1356
1356
1357
assert_eq!(preimage_tx.input.len(), 1);
1357
1358
assert_eq!(preimage_bump_tx.input.len(), 1);
1358
1359
1359
1360
assert_eq!(preimage_tx.input.len(), 1);
1360
1361
assert_eq!(preimage_tx.input[0].witness.last().unwrap().len(), OFFERED_HTLC_SCRIPT_WEIGHT); // HTLC 1 <--> 0, preimage tx
1361
- assert_eq!(remote_txn[0].output[preimage_tx.input[0].previous_output.vout as usize].value.to_sat(), 800 );
1362
+ assert_eq!(remote_txn[0].output[preimage_tx.input[0].previous_output.vout as usize].value.to_sat(), payment_value_sats );
1362
1363
1363
1364
assert_eq!(timeout_tx.input.len(), 1);
1364
1365
assert_eq!(timeout_tx.input[0].witness.last().unwrap().len(), ACCEPTED_HTLC_SCRIPT_WEIGHT); // HTLC 0 <--> 1, timeout tx
@@ -7923,22 +7924,31 @@ fn test_bump_penalty_txn_on_remote_commitment() {
7923
7924
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
7924
7925
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
7925
7926
7926
- let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 59000000);
7927
- let (payment_preimage, payment_hash, ..) = route_payment(&nodes[0], &[&nodes[1]], 3_000_000);
7928
- route_payment(&nodes[1], &vec!(&nodes[0])[..], 3000000).0;
7929
-
7930
- // Remote commitment txn with 4 outputs : to_local, to_remote, 1 outgoing HTLC, 1 incoming HTLC
7931
- let remote_txn = get_local_commitment_txn!(nodes[0], chan.2);
7932
- assert_eq!(remote_txn[0].output.len(), 4);
7933
- assert_eq!(remote_txn[0].input.len(), 1);
7934
- assert_eq!(remote_txn[0].input[0].previous_output.txid, chan.3.compute_txid());
7935
-
7936
- // Claim a HTLC without revocation (provide B monitor with preimage)
7937
- nodes[1].node.claim_funds(payment_preimage);
7938
- expect_payment_claimed!(nodes[1], payment_hash, 3_000_000);
7939
- mine_transaction(&nodes[1], &remote_txn[0]);
7940
- check_added_monitors!(nodes[1], 2);
7941
- connect_blocks(&nodes[1], TEST_FINAL_CLTV); // Confirm blocks until the HTLC expires
7927
+ let remote_txn = {
7928
+ // post-bump fee (288 satoshis) + dust threshold for output type (294 satoshis) = 582
7929
+ let htlc_value_a_msats = 582_000;
7930
+ let htlc_value_b_msats = 583_000;
7931
+
7932
+ let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 59000000);
7933
+ let (payment_preimage, payment_hash, ..) = route_payment(&nodes[0], &[&nodes[1]], htlc_value_a_msats);
7934
+ route_payment(&nodes[1], &vec!(&nodes[0])[..], htlc_value_b_msats);
7935
+
7936
+ // Remote commitment txn with 4 outputs : to_local, to_remote, 1 outgoing HTLC, 1 incoming HTLC
7937
+ let remote_txn = get_local_commitment_txn!(nodes[0], chan.2);
7938
+ assert_eq!(remote_txn[0].output.len(), 4);
7939
+ assert_eq!(remote_txn[0].input.len(), 1);
7940
+ assert_eq!(remote_txn[0].input[0].previous_output.txid, chan.3.compute_txid());
7941
+
7942
+ // Claim a HTLC without revocation (provide B monitor with preimage)
7943
+ nodes[1].node.claim_funds(payment_preimage);
7944
+ expect_payment_claimed!(nodes[1], payment_hash, htlc_value_a_msats);
7945
+ mine_transaction(&nodes[1], &remote_txn[0]);
7946
+ check_added_monitors!(nodes[1], 2);
7947
+ connect_blocks(&nodes[1], TEST_FINAL_CLTV); // Confirm blocks until the HTLC expires
7948
+ // depending on the block connection style, node 1 may have broadcast either 3 or 10 txs
7949
+
7950
+ remote_txn
7951
+ };
7942
7952
7943
7953
// One or more claim tx should have been broadcast, check it
7944
7954
let timeout;
0 commit comments