Skip to content

Commit bf1d7fa

Browse files
committed
Simplify tx checks in functional tests to make later commits simpler
This cleans up some of the transaction format verification and docs to make it easier when we delay CLTV-locked transactions to update the tests.
1 parent 697b794 commit bf1d7fa

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

lightning/src/ln/functional_tests.rs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,16 +1497,17 @@ fn test_duplicate_htlc_different_direction_onchain() {
14971497

14981498
// Check we only broadcast 1 timeout tx
14991499
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()) };
15011500
assert_eq!(claim_txn.len(), 5);
15021501
check_spends!(claim_txn[2], chan_1.3);
15031502
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);
15101511

15111512
let events = nodes[0].node.get_and_clear_pending_msg_events();
15121513
assert_eq!(events.len(), 3);
@@ -5306,11 +5307,20 @@ fn test_duplicate_payment_hash_one_failure_one_success() {
53065307
let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::known(), InitFeatures::known());
53075308
create_announced_chan_between_nodes(&nodes, 2, 3, InitFeatures::known(), InitFeatures::known());
53085309

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+
53095316
let (our_payment_preimage, duplicate_payment_hash, _) = route_payment(&nodes[0], &vec!(&nodes[1], &nodes[2])[..], 900000);
53105317

53115318
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.
53125322
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();
53145324
send_along_route_with_secret(&nodes[0], route, &[&[&nodes[1], &nodes[2], &nodes[3]]], 900000, duplicate_payment_hash, payment_secret);
53155325

53165326
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() {
53535363
}
53545364
let htlc_success_txn: Vec<_> = nodes[2].tx_broadcaster.txn_broadcasted.lock().unwrap().clone();
53555365
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]);
53605368
assert_eq!(htlc_success_txn[0].input.len(), 1);
53615369
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]);
53635370
assert_eq!(htlc_success_txn[1].input.len(), 1);
53645371
assert_eq!(htlc_success_txn[1].input[0].witness.last().unwrap().len(), ACCEPTED_HTLC_SCRIPT_WEIGHT);
53655372
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+
53685377

53695378
mine_transaction(&nodes[1], &htlc_timeout_tx);
53705379
connect_blocks(&nodes[1], ANTI_REORG_DELAY - 1);

0 commit comments

Comments
 (0)