Skip to content

Commit a6b28c8

Browse files
committed
f - extend test to cover forward channel confirmation
1 parent bc7c716 commit a6b28c8

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

lightning/src/ln/functional_tests.rs

+33-5
Original file line numberDiff line numberDiff line change
@@ -2213,6 +2213,11 @@ fn channel_reserve_in_flight_removes() {
22132213

22142214
#[test]
22152215
fn test_fail_back_before_backwards_timeout() {
2216+
do_test_fail_back_before_backwards_timeout(false);
2217+
do_test_fail_back_before_backwards_timeout(true);
2218+
}
2219+
2220+
fn do_test_fail_back_before_backwards_timeout(forward_claims: bool) {
22162221
// Test that we fail an HTLC upstream if we are still waiting for confirmation downstream
22172222
// just before the upstream timeout expires
22182223
let chanmon_cfgs = create_chanmon_cfgs(3);
@@ -2227,21 +2232,21 @@ fn test_fail_back_before_backwards_timeout() {
22272232
connect_blocks(&nodes[1], 2*CHAN_CONFIRM_DEPTH + 1 - nodes[1].best_block_info().1);
22282233
connect_blocks(&nodes[2], 2*CHAN_CONFIRM_DEPTH + 1 - nodes[2].best_block_info().1);
22292234

2230-
let (_, payment_hash_1, _) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 3_000_000);
2235+
let (payment_preimage, payment_hash, _) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 3_000_000);
22312236

22322237
// Force close downstream with timeout
22332238
nodes[1].node.force_close_broadcasting_latest_txn(&chan_2.2, &nodes[2].node.get_our_node_id()).unwrap();
22342239
check_added_monitors!(nodes[1], 1);
22352240
check_closed_broadcast!(nodes[1], true);
22362241

22372242
connect_blocks(&nodes[1], TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS + 1);
2238-
test_txn_broadcast(&nodes[1], &chan_2, None, HTLCType::TIMEOUT);
2239-
check_closed_event!(nodes[1], 1, ClosureReason::HolderForceClosed);
2243+
let node_1_txn = test_txn_broadcast(&nodes[1], &chan_2, None, HTLCType::TIMEOUT);
2244+
check_closed_event(&nodes[1], 1, ClosureReason::HolderForceClosed, false);
22402245

22412246
// Nothing is confirmed for a while
22422247
connect_blocks(&nodes[1], MIN_CLTV_EXPIRY_DELTA as u32 - LATENCY_GRACE_PERIOD_BLOCKS - TIMEOUT_FAIL_BACK_BUFFER);
22432248

2244-
// Check that node 2 fails the HTLC upstream
2249+
// Check that nodes[1] fails the HTLC upstream
22452250
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], vec![HTLCDestination::NextHopChannel { node_id: Some(nodes[2].node.get_our_node_id()), channel_id: chan_2.2 }]);
22462251
check_added_monitors!(nodes[1], 1);
22472252
let events = nodes[1].node.get_and_clear_pending_msg_events();
@@ -2260,7 +2265,30 @@ fn test_fail_back_before_backwards_timeout() {
22602265

22612266
nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &update_fail);
22622267
commitment_signed_dance!(nodes[0], nodes[1], commitment_signed, false);
2263-
expect_payment_failed_conditions(&nodes[0], payment_hash_1, false, PaymentFailedConditions::new().blamed_chan_closed(true));
2268+
expect_payment_failed_conditions(&nodes[0], payment_hash, false, PaymentFailedConditions::new().blamed_chan_closed(true));
2269+
2270+
// Make sure we don't generate duplicate fails from monitor events
2271+
if forward_claims {
2272+
// Claim and force close as nodes[2]
2273+
nodes[2].node.claim_funds(payment_preimage);
2274+
expect_payment_claimed!(nodes[2], payment_hash, 3_000_000);
2275+
check_added_monitors!(nodes[2], 1);
2276+
get_htlc_update_msgs(&nodes[2], &nodes[1].node.get_our_node_id());
2277+
2278+
connect_blocks(&nodes[2], TEST_FINAL_CLTV - CLTV_CLAIM_BUFFER + 2);
2279+
let node_2_txn = test_txn_broadcast(&nodes[2], &chan_2, None, HTLCType::SUCCESS);
2280+
check_closed_broadcast!(nodes[2], true);
2281+
check_closed_event(&nodes[2], 1, ClosureReason::CommitmentTxConfirmed, false);
2282+
check_added_monitors!(nodes[2], 1);
2283+
2284+
// Confirm nodes[2]'s claim with preimage
2285+
mine_transaction(&nodes[1], &node_2_txn[0]); // Commitment
2286+
mine_transaction(&nodes[1], &node_2_txn[1]); // HTLC success
2287+
} else {
2288+
// Confirm nodes[1]'s claim with timeout, make sure we don't fail upstream again
2289+
mine_transaction(&nodes[1], &node_1_txn[0]); // Commitment
2290+
mine_transaction(&nodes[1], &node_1_txn[1]); // HTLC timeout
2291+
}
22642292
}
22652293

22662294
#[test]

0 commit comments

Comments
 (0)