@@ -1280,23 +1280,41 @@ fn test_duplicate_htlc_different_direction_onchain() {
12801280 check_closed_event!(nodes[0], 1, ClosureReason::CommitmentTxConfirmed);
12811281 connect_blocks(&nodes[0], TEST_FINAL_CLTV - 1); // Confirm blocks until the HTLC expires
12821282
1283- // Check we only broadcast 1 timeout tx
12841283 let claim_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().clone();
12851284 assert_eq!(claim_txn.len(), 8);
1286- assert_eq!(claim_txn[1], claim_txn[4]);
1287- assert_eq!(claim_txn[2], claim_txn[5]);
1288- check_spends!(claim_txn[1], chan_1.3);
1289- check_spends!(claim_txn[2], claim_txn[1]);
1290- check_spends!(claim_txn[7], claim_txn[1]);
1285+
1286+ check_spends!(claim_txn[0], remote_txn[0]); // Immediate HTLC claim with preimage
1287+
1288+ check_spends!(claim_txn[1], chan_1.3); // Alternative commitment tx
1289+ check_spends!(claim_txn[2], claim_txn[1]); // HTLC spend in alternative commitment tx
1290+
1291+ let bump_tx = if claim_txn[1] == claim_txn[4] {
1292+ assert_eq!(claim_txn[1], claim_txn[4]);
1293+ assert_eq!(claim_txn[2], claim_txn[5]);
1294+
1295+ check_spends!(claim_txn[7], claim_txn[1]); // HTLC timeout on alternative commitment tx
1296+
1297+ check_spends!(claim_txn[3], remote_txn[0]); // HTLC timeout on broadcasted commitment tx
1298+ &claim_txn[3]
1299+ } else {
1300+ assert_eq!(claim_txn[1], claim_txn[3]);
1301+ assert_eq!(claim_txn[2], claim_txn[4]);
1302+
1303+ check_spends!(claim_txn[5], claim_txn[1]); // HTLC timeout on alternative commitment tx
1304+
1305+ check_spends!(claim_txn[7], remote_txn[0]); // HTLC timeout on broadcasted commitment tx
1306+
1307+ &claim_txn[7]
1308+ };
12911309
12921310 assert_eq!(claim_txn[0].input.len(), 1);
1293- assert_eq!(claim_txn[3] .input.len(), 1);
1294- assert_eq!(claim_txn[0].input[0].previous_output, claim_txn[3] .input[0].previous_output);
1311+ assert_eq!(bump_tx .input.len(), 1);
1312+ assert_eq!(claim_txn[0].input[0].previous_output, bump_tx .input[0].previous_output);
12951313
12961314 assert_eq!(claim_txn[0].input.len(), 1);
12971315 assert_eq!(claim_txn[0].input[0].witness.last().unwrap().len(), OFFERED_HTLC_SCRIPT_WEIGHT); // HTLC 1 <--> 0, preimage tx
1298- check_spends!(claim_txn[0], remote_txn[0]);
12991316 assert_eq!(remote_txn[0].output[claim_txn[0].input[0].previous_output.vout as usize].value, 800);
1317+
13001318 assert_eq!(claim_txn[6].input.len(), 1);
13011319 assert_eq!(claim_txn[6].input[0].witness.last().unwrap().len(), ACCEPTED_HTLC_SCRIPT_WEIGHT); // HTLC 0 <--> 1, timeout tx
13021320 check_spends!(claim_txn[6], remote_txn[0]);
@@ -2351,7 +2369,8 @@ fn test_justice_tx() {
23512369 chanmon_cfgs[1].keys_manager.disable_revocation_policy_check = true;
23522370 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
23532371 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &user_cfgs);
2354- let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
2372+ let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs);
2373+ *nodes[0].connect_style.borrow_mut() = ConnectStyle::FullBlockViaListen;
23552374 // Create some new channels:
23562375 let chan_5 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known());
23572376
@@ -2583,11 +2602,7 @@ fn claim_htlc_outputs_single_tx() {
25832602 expect_payment_failed!(nodes[1], payment_hash_2, true);
25842603
25852604 let node_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap();
2586- assert_eq!(node_txn.len(), 9);
2587- // ChannelMonitor: justice tx revoked offered htlc, justice tx revoked received htlc, justice tx revoked to_local (3)
2588- // ChannelManager: local commmitment + local HTLC-timeout (2)
2589- // ChannelMonitor: bumped justice tx, after one increase, bumps on HTLC aren't generated not being substantial anymore, bump on revoked to_local isn't generated due to more room for expiration (2)
2590- // ChannelMonitor: local commitment + local HTLC-timeout (2)
2605+ assert!(node_txn.len() == 9 || node_txn.len() == 10);
25912606
25922607 // Check the pair local commitment and HTLC-timeout broadcast due to HTLC expiration
25932608 assert_eq!(node_txn[0].input.len(), 1);
@@ -5283,21 +5298,30 @@ fn test_duplicate_payment_hash_one_failure_one_success() {
52835298 let htlc_timeout_tx;
52845299 { // Extract one of the two HTLC-Timeout transaction
52855300 let node_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap();
5286- // ChannelMonitor: timeout tx * 3, ChannelManager: local commitment tx
5287- assert_eq !(node_txn.len(), 4 );
5301+ // ChannelMonitor: timeout tx * 2-or- 3, ChannelManager: local commitment tx
5302+ assert !(node_txn.len() == 4 || node_txn.len() == 3 );
52885303 check_spends!(node_txn[0], chan_2.3);
52895304
52905305 check_spends!(node_txn[1], commitment_txn[0]);
52915306 assert_eq!(node_txn[1].input.len(), 1);
5292- check_spends!(node_txn[2], commitment_txn[0]);
5293- assert_eq!(node_txn[2].input.len(), 1);
5294- assert_eq!(node_txn[1].input[0].previous_output, node_txn[2].input[0].previous_output);
5295- check_spends!(node_txn[3], commitment_txn[0]);
5296- assert_ne!(node_txn[1].input[0].previous_output, node_txn[3].input[0].previous_output);
5307+
5308+ if node_txn.len() > 3 {
5309+ check_spends!(node_txn[2], commitment_txn[0]);
5310+ assert_eq!(node_txn[2].input.len(), 1);
5311+ assert_eq!(node_txn[1].input[0].previous_output, node_txn[2].input[0].previous_output);
5312+
5313+ check_spends!(node_txn[3], commitment_txn[0]);
5314+ assert_ne!(node_txn[1].input[0].previous_output, node_txn[3].input[0].previous_output);
5315+ } else {
5316+ check_spends!(node_txn[2], commitment_txn[0]);
5317+ assert_ne!(node_txn[1].input[0].previous_output, node_txn[2].input[0].previous_output);
5318+ }
52975319
52985320 assert_eq!(node_txn[1].input[0].witness.last().unwrap().len(), ACCEPTED_HTLC_SCRIPT_WEIGHT);
52995321 assert_eq!(node_txn[2].input[0].witness.last().unwrap().len(), ACCEPTED_HTLC_SCRIPT_WEIGHT);
5300- assert_eq!(node_txn[3].input[0].witness.last().unwrap().len(), ACCEPTED_HTLC_SCRIPT_WEIGHT);
5322+ if node_txn.len() > 3 {
5323+ assert_eq!(node_txn[3].input[0].witness.last().unwrap().len(), ACCEPTED_HTLC_SCRIPT_WEIGHT);
5324+ }
53015325 htlc_timeout_tx = node_txn[1].clone();
53025326 }
53035327
@@ -7957,13 +7981,24 @@ fn test_bump_penalty_txn_on_remote_commitment() {
79577981 assert_eq!(node_txn[6].input.len(), 1);
79587982 check_spends!(node_txn[0], remote_txn[0]);
79597983 check_spends!(node_txn[6], remote_txn[0]);
7960- assert_eq!(node_txn[0].input[0].previous_output, node_txn[3].input[0].previous_output);
7961- preimage_bump = node_txn[3].clone();
79627984
79637985 check_spends!(node_txn[1], chan.3);
79647986 check_spends!(node_txn[2], node_txn[1]);
7965- assert_eq!(node_txn[1], node_txn[4]);
7966- assert_eq!(node_txn[2], node_txn[5]);
7987+
7988+ if node_txn[0].input[0].previous_output == node_txn[3].input[0].previous_output {
7989+ preimage_bump = node_txn[3].clone();
7990+ check_spends!(node_txn[3], remote_txn[0]);
7991+
7992+ assert_eq!(node_txn[1], node_txn[4]);
7993+ assert_eq!(node_txn[2], node_txn[5]);
7994+ } else {
7995+ preimage_bump = node_txn[7].clone();
7996+ check_spends!(node_txn[7], remote_txn[0]);
7997+ assert_eq!(node_txn[0].input[0].previous_output, node_txn[7].input[0].previous_output);
7998+
7999+ assert_eq!(node_txn[1], node_txn[3]);
8000+ assert_eq!(node_txn[2], node_txn[4]);
8001+ }
79678002
79688003 timeout = node_txn[6].txid();
79698004 let index = node_txn[6].input[0].previous_output.vout;
0 commit comments