@@ -1267,44 +1267,32 @@ fn test_duplicate_htlc_different_direction_onchain() {
1267
1267
connect_blocks(&nodes[0], TEST_FINAL_CLTV - 1); // Confirm blocks until the HTLC expires
1268
1268
1269
1269
let claim_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().clone();
1270
- assert_eq!(claim_txn.len(), 8 );
1270
+ assert_eq!(claim_txn.len(), 5 );
1271
1271
1272
1272
check_spends!(claim_txn[0], remote_txn[0]); // Immediate HTLC claim with preimage
1273
-
1274
1273
check_spends!(claim_txn[1], chan_1.3); // Alternative commitment tx
1275
1274
check_spends!(claim_txn[2], claim_txn[1]); // HTLC spend in alternative commitment tx
1276
1275
1277
- let bump_tx = if claim_txn[1] == claim_txn[4] {
1278
- assert_eq!(claim_txn[1], claim_txn[4]);
1279
- assert_eq!(claim_txn[2], claim_txn[5]);
1280
-
1281
- check_spends!(claim_txn[7], claim_txn[1]); // HTLC timeout on alternative commitment tx
1282
-
1283
- check_spends!(claim_txn[3], remote_txn[0]); // HTLC timeout on broadcasted commitment tx
1284
- &claim_txn[3]
1276
+ check_spends!(claim_txn[3], remote_txn[0]);
1277
+ check_spends!(claim_txn[4], remote_txn[0]);
1278
+ let preimage_tx = &claim_txn[0];
1279
+ let (preimage_bump_tx, timeout_tx) = if claim_txn[3].input[0].previous_output == preimage_tx.input[0].previous_output {
1280
+ (&claim_txn[3], &claim_txn[4])
1285
1281
} else {
1286
- assert_eq!(claim_txn[1], claim_txn[3]);
1287
- assert_eq!(claim_txn[2], claim_txn[4]);
1288
-
1289
- check_spends!(claim_txn[5], claim_txn[1]); // HTLC timeout on alternative commitment tx
1290
-
1291
- check_spends!(claim_txn[7], remote_txn[0]); // HTLC timeout on broadcasted commitment tx
1292
-
1293
- &claim_txn[7]
1282
+ (&claim_txn[4], &claim_txn[3])
1294
1283
};
1295
1284
1296
- assert_eq!(claim_txn[0].input.len(), 1);
1297
- assert_eq!(bump_tx.input.len(), 1);
1298
- assert_eq!(claim_txn[0].input[0].previous_output, bump_tx.input[0].previous_output);
1285
+ assert_eq!(preimage_tx.input.len(), 1);
1286
+ assert_eq!(preimage_bump_tx.input.len(), 1);
1299
1287
1300
- assert_eq!(claim_txn[0] .input.len(), 1);
1301
- assert_eq!(claim_txn[0] .input[0].witness.last().unwrap().len(), OFFERED_HTLC_SCRIPT_WEIGHT); // HTLC 1 <--> 0, preimage tx
1302
- assert_eq!(remote_txn[0].output[claim_txn[0] .input[0].previous_output.vout as usize].value, 800);
1288
+ assert_eq!(preimage_tx .input.len(), 1);
1289
+ assert_eq!(preimage_tx .input[0].witness.last().unwrap().len(), OFFERED_HTLC_SCRIPT_WEIGHT); // HTLC 1 <--> 0, preimage tx
1290
+ assert_eq!(remote_txn[0].output[preimage_tx .input[0].previous_output.vout as usize].value, 800);
1303
1291
1304
- assert_eq!(claim_txn[6] .input.len(), 1);
1305
- assert_eq!(claim_txn[6] .input[0].witness.last().unwrap().len(), ACCEPTED_HTLC_SCRIPT_WEIGHT); // HTLC 0 <--> 1, timeout tx
1306
- check_spends!(claim_txn[6] , remote_txn[0]);
1307
- assert_eq!(remote_txn[0].output[claim_txn[6] .input[0].previous_output.vout as usize].value, 900);
1292
+ assert_eq!(timeout_tx .input.len(), 1);
1293
+ assert_eq!(timeout_tx .input[0].witness.last().unwrap().len(), ACCEPTED_HTLC_SCRIPT_WEIGHT); // HTLC 0 <--> 1, timeout tx
1294
+ check_spends!(timeout_tx , remote_txn[0]);
1295
+ assert_eq!(remote_txn[0].output[timeout_tx .input[0].previous_output.vout as usize].value, 900);
1308
1296
1309
1297
let events = nodes[0].node.get_and_clear_pending_msg_events();
1310
1298
assert_eq!(events.len(), 3);
@@ -8036,45 +8024,40 @@ fn test_bump_penalty_txn_on_remote_commitment() {
8036
8024
let feerate_preimage;
8037
8025
{
8038
8026
let mut node_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap();
8039
- // 9 transactions including:
8040
- // 1*2 ChannelManager local broadcasts of commitment + HTLC-Success
8041
- // 1*3 ChannelManager local broadcasts of commitment + HTLC-Success + HTLC-Timeout
8042
- // 2 * HTLC-Success (one RBF bump we'll check later)
8043
- // 1 * HTLC-Timeout
8044
- assert_eq!(node_txn.len(), 8);
8027
+ // 5 transactions including:
8028
+ // local commitment + HTLC-Success
8029
+ // preimage and timeout sweeps from remote commitment + preimage sweep bump
8030
+ assert_eq!(node_txn.len(), 5);
8045
8031
assert_eq!(node_txn[0].input.len(), 1);
8046
- assert_eq!(node_txn[6].input.len(), 1);
8032
+ assert_eq!(node_txn[3].input.len(), 1);
8033
+ assert_eq!(node_txn[4].input.len(), 1);
8047
8034
check_spends!(node_txn[0], remote_txn[0]);
8048
- check_spends!(node_txn[6], remote_txn[0]);
8049
-
8050
- check_spends!(node_txn[1], chan.3);
8051
- check_spends!(node_txn[2], node_txn[1]);
8052
-
8053
- if node_txn[0].input[0].previous_output == node_txn[3].input[0].previous_output {
8054
- preimage_bump = node_txn[3].clone();
8055
- check_spends!(node_txn[3], remote_txn[0]);
8035
+ check_spends!(node_txn[3], remote_txn[0]);
8036
+ check_spends!(node_txn[4], remote_txn[0]);
8056
8037
8057
- assert_eq!(node_txn[1], node_txn[4]);
8058
- assert_eq!(node_txn[2], node_txn[5]);
8059
- } else {
8060
- preimage_bump = node_txn[7].clone();
8061
- check_spends!(node_txn[7], remote_txn[0]);
8062
- assert_eq!(node_txn[0].input[0].previous_output, node_txn[7].input[0].previous_output);
8063
-
8064
- assert_eq!(node_txn[1], node_txn[3]);
8065
- assert_eq!(node_txn[2], node_txn[4]);
8066
- }
8067
-
8068
- timeout = node_txn[6].txid();
8069
- let index = node_txn[6].input[0].previous_output.vout;
8070
- let fee = remote_txn[0].output[index as usize].value - node_txn[6].output[0].value;
8071
- feerate_timeout = fee * 1000 / node_txn[6].weight() as u64;
8038
+ check_spends!(node_txn[1], chan.3); // local commitment
8039
+ check_spends!(node_txn[2], node_txn[1]); // local HTLC-Success
8072
8040
8073
8041
preimage = node_txn[0].txid();
8074
8042
let index = node_txn[0].input[0].previous_output.vout;
8075
8043
let fee = remote_txn[0].output[index as usize].value - node_txn[0].output[0].value;
8076
8044
feerate_preimage = fee * 1000 / node_txn[0].weight() as u64;
8077
8045
8046
+ let (preimage_bump_tx, timeout_tx) = if node_txn[3].input[0].previous_output == node_txn[0].input[0].previous_output {
8047
+ (node_txn[3].clone(), node_txn[4].clone())
8048
+ } else {
8049
+ (node_txn[4].clone(), node_txn[3].clone())
8050
+ };
8051
+
8052
+ preimage_bump = preimage_bump_tx;
8053
+ check_spends!(preimage_bump, remote_txn[0]);
8054
+ assert_eq!(node_txn[0].input[0].previous_output, preimage_bump.input[0].previous_output);
8055
+
8056
+ timeout = timeout_tx.txid();
8057
+ let index = timeout_tx.input[0].previous_output.vout;
8058
+ let fee = remote_txn[0].output[index as usize].value - timeout_tx.output[0].value;
8059
+ feerate_timeout = fee * 1000 / timeout_tx.weight() as u64;
8060
+
8078
8061
node_txn.clear();
8079
8062
};
8080
8063
assert_ne!(feerate_timeout, 0);
@@ -8950,11 +8933,8 @@ fn test_concurrent_monitor_claim() {
8950
8933
watchtower_alice.chain_monitor.block_connected(&Block { header, txdata: vec![bob_state_y.clone()] }, CHAN_CONFIRM_DEPTH + 2 + TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS);
8951
8934
{
8952
8935
let htlc_txn = chanmon_cfgs[0].tx_broadcaster.txn_broadcasted.lock().unwrap();
8953
- // We broadcast twice the transaction, once due to the HTLC-timeout, once due
8954
- // the onchain detection of the HTLC output
8955
- assert_eq!(htlc_txn.len(), 2);
8936
+ assert_eq!(htlc_txn.len(), 1);
8956
8937
check_spends!(htlc_txn[0], bob_state_y);
8957
- check_spends!(htlc_txn[1], bob_state_y);
8958
8938
}
8959
8939
}
8960
8940
0 commit comments