Skip to content

Commit 7d6938a

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 56491d9 commit 7d6938a

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
@@ -1499,16 +1499,17 @@ fn test_duplicate_htlc_different_direction_onchain() {
14991499

15001500
// Check we only broadcast 1 timeout tx
15011501
let claim_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().clone();
1502-
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()) };
15031502
assert_eq!(claim_txn.len(), 5);
15041503
check_spends!(claim_txn[2], chan_1.3);
15051504
check_spends!(claim_txn[3], claim_txn[2]);
1506-
assert_eq!(htlc_pair.0.input.len(), 1);
1507-
assert_eq!(htlc_pair.0.input[0].witness.last().unwrap().len(), OFFERED_HTLC_SCRIPT_WEIGHT); // HTLC 1 <--> 0, preimage tx
1508-
check_spends!(htlc_pair.0, remote_txn[0]);
1509-
assert_eq!(htlc_pair.1.input.len(), 1);
1510-
assert_eq!(htlc_pair.1.input[0].witness.last().unwrap().len(), ACCEPTED_HTLC_SCRIPT_WEIGHT); // HTLC 0 <--> 1, timeout tx
1511-
check_spends!(htlc_pair.1, remote_txn[0]);
1505+
assert_eq!(claim_txn[1].input.len(), 1);
1506+
assert_eq!(claim_txn[1].input[0].witness.last().unwrap().len(), OFFERED_HTLC_SCRIPT_WEIGHT); // HTLC 1 <--> 0, preimage tx
1507+
check_spends!(claim_txn[1], remote_txn[0]);
1508+
assert_eq!(remote_txn[0].output[claim_txn[1].input[0].previous_output.vout as usize].value, 800);
1509+
assert_eq!(claim_txn[0].input.len(), 1);
1510+
assert_eq!(claim_txn[0].input[0].witness.last().unwrap().len(), ACCEPTED_HTLC_SCRIPT_WEIGHT); // HTLC 0 <--> 1, timeout tx
1511+
check_spends!(claim_txn[0], remote_txn[0]);
1512+
assert_eq!(remote_txn[0].output[claim_txn[0].input[0].previous_output.vout as usize].value, 900);
15121513

15131514
let events = nodes[0].node.get_and_clear_pending_msg_events();
15141515
assert_eq!(events.len(), 3);
@@ -5308,11 +5309,20 @@ fn test_duplicate_payment_hash_one_failure_one_success() {
53085309
let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::known(), InitFeatures::known());
53095310
create_announced_chan_between_nodes(&nodes, 2, 3, InitFeatures::known(), InitFeatures::known());
53105311

5312+
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;
5313+
connect_blocks(&nodes[0], node_max_height - nodes[0].best_block_info().1);
5314+
connect_blocks(&nodes[1], node_max_height - nodes[1].best_block_info().1);
5315+
connect_blocks(&nodes[2], node_max_height - nodes[2].best_block_info().1);
5316+
connect_blocks(&nodes[3], node_max_height - nodes[3].best_block_info().1);
5317+
53115318
let (our_payment_preimage, duplicate_payment_hash, _) = route_payment(&nodes[0], &vec!(&nodes[1], &nodes[2])[..], 900000);
53125319

53135320
let payment_secret = nodes[3].node.create_inbound_payment_for_hash(duplicate_payment_hash, None, 7200, 0).unwrap();
5321+
// We reduce the final CLTV here by a somewhat arbitrary constant to keep it under the one-byte
5322+
// script push size limit so that the below script length checks match
5323+
// ACCEPTED_HTLC_SCRIPT_WEIGHT.
53145324
let route = get_route(&nodes[0].node.get_our_node_id(), &nodes[0].net_graph_msg_handler.network_graph.read().unwrap(),
5315-
&nodes[3].node.get_our_node_id(), Some(InvoiceFeatures::known()), None, &Vec::new(), 900000, TEST_FINAL_CLTV, nodes[0].logger).unwrap();
5325+
&nodes[3].node.get_our_node_id(), Some(InvoiceFeatures::known()), None, &Vec::new(), 900000, TEST_FINAL_CLTV - 40, nodes[0].logger).unwrap();
53165326
send_along_route_with_secret(&nodes[0], route, &[&[&nodes[1], &nodes[2], &nodes[3]]], 900000, duplicate_payment_hash, payment_secret);
53175327

53185328
let commitment_txn = get_local_commitment_txn!(nodes[2], chan_2.2);
@@ -5355,18 +5365,17 @@ fn test_duplicate_payment_hash_one_failure_one_success() {
53555365
}
53565366
let htlc_success_txn: Vec<_> = nodes[2].tx_broadcaster.txn_broadcasted.lock().unwrap().clone();
53575367
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)
5358-
check_spends!(htlc_success_txn[2], chan_2.3);
5359-
check_spends!(htlc_success_txn[3], htlc_success_txn[2]);
5360-
check_spends!(htlc_success_txn[4], htlc_success_txn[2]);
5361-
assert_eq!(htlc_success_txn[0], htlc_success_txn[3]);
5368+
check_spends!(htlc_success_txn[0], commitment_txn[0]);
5369+
check_spends!(htlc_success_txn[1], commitment_txn[0]);
53625370
assert_eq!(htlc_success_txn[0].input.len(), 1);
53635371
assert_eq!(htlc_success_txn[0].input[0].witness.last().unwrap().len(), ACCEPTED_HTLC_SCRIPT_WEIGHT);
5364-
assert_eq!(htlc_success_txn[1], htlc_success_txn[4]);
53655372
assert_eq!(htlc_success_txn[1].input.len(), 1);
53665373
assert_eq!(htlc_success_txn[1].input[0].witness.last().unwrap().len(), ACCEPTED_HTLC_SCRIPT_WEIGHT);
53675374
assert_ne!(htlc_success_txn[0].input[0], htlc_success_txn[1].input[0]);
5368-
check_spends!(htlc_success_txn[0], commitment_txn[0]);
5369-
check_spends!(htlc_success_txn[1], commitment_txn[0]);
5375+
assert_eq!(htlc_success_txn[2], commitment_txn[0]);
5376+
assert_eq!(htlc_success_txn[3], htlc_success_txn[0]);
5377+
assert_eq!(htlc_success_txn[4], htlc_success_txn[1]);
5378+
53705379

53715380
mine_transaction(&nodes[1], &htlc_timeout_tx);
53725381
connect_blocks(&nodes[1], ANTI_REORG_DELAY - 1);

0 commit comments

Comments
 (0)