Skip to content

Commit 54611fe

Browse files
committed
f - test fixups
* Explicitly assert no hanging messages after off-chain actions * Get rid of manual user force-close for timeout * Connect blocks on nodes[0] to make sure they don't go on-chain * Add comment on syncing block height on nodes
1 parent ec4ed2a commit 54611fe

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

lightning/src/ln/functional_tests.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2237,23 +2237,27 @@ fn do_test_fail_back_before_backwards_timeout(post_fail_back_action: PostFailBac
22372237
create_announced_chan_between_nodes(&nodes, 0, 1);
22382238
let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2);
22392239

2240+
// Start every node on the same block height to make reasoning about timeouts easier
22402241
connect_blocks(&nodes[0], 2*CHAN_CONFIRM_DEPTH + 1 - nodes[0].best_block_info().1);
22412242
connect_blocks(&nodes[1], 2*CHAN_CONFIRM_DEPTH + 1 - nodes[1].best_block_info().1);
22422243
connect_blocks(&nodes[2], 2*CHAN_CONFIRM_DEPTH + 1 - nodes[2].best_block_info().1);
22432244

22442245
let (payment_preimage, payment_hash, _) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 3_000_000);
22452246

22462247
// Force close downstream with timeout
2247-
nodes[1].node.force_close_broadcasting_latest_txn(&chan_2.2, &nodes[2].node.get_our_node_id()).unwrap();
2248-
check_added_monitors!(nodes[1], 1);
2249-
check_closed_broadcast!(nodes[1], true);
2250-
2251-
connect_blocks(&nodes[1], TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS + 1);
2248+
let timeout_blocks = TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS + 1;
2249+
connect_blocks(&nodes[1], timeout_blocks);
22522250
let node_1_txn = test_txn_broadcast(&nodes[1], &chan_2, None, HTLCType::TIMEOUT);
2253-
check_closed_event(&nodes[1], 1, ClosureReason::HolderForceClosed, false);
2251+
check_closed_event(&nodes[1], 1, ClosureReason::CommitmentTxConfirmed, false);
2252+
check_closed_broadcast!(nodes[1], true);
2253+
check_added_monitors!(nodes[1], 1);
22542254

22552255
// Nothing is confirmed for a while
2256-
connect_blocks(&nodes[1], MIN_CLTV_EXPIRY_DELTA as u32 - LATENCY_GRACE_PERIOD_BLOCKS - TIMEOUT_FAIL_BACK_BUFFER);
2256+
let upstream_timeout_blocks = MIN_CLTV_EXPIRY_DELTA as u32 - LATENCY_GRACE_PERIOD_BLOCKS - TIMEOUT_FAIL_BACK_BUFFER;
2257+
connect_blocks(&nodes[1], upstream_timeout_blocks);
2258+
2259+
// Connect blocks for nodes[0] to make sure they don't go on-chain
2260+
connect_blocks(&nodes[0], timeout_blocks + upstream_timeout_blocks);
22572261

22582262
// Check that nodes[1] fails the HTLC upstream
22592263
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 }]);
@@ -2282,6 +2286,7 @@ fn do_test_fail_back_before_backwards_timeout(post_fail_back_action: PostFailBac
22822286
// Confirm nodes[1]'s claim with timeout, make sure we don't fail upstream again
22832287
mine_transaction(&nodes[1], &node_1_txn[0]); // Commitment
22842288
mine_transaction(&nodes[1], &node_1_txn[1]); // HTLC timeout
2289+
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
22852290
},
22862291
PostFailBackAction::ClaimOnChain => {
22872292
nodes[2].node.claim_funds(payment_preimage);
@@ -2297,6 +2302,7 @@ fn do_test_fail_back_before_backwards_timeout(post_fail_back_action: PostFailBac
22972302

22982303
mine_transaction(&nodes[1], &node_2_txn[0]); // Commitment
22992304
mine_transaction(&nodes[1], &node_2_txn[1]); // HTLC success
2305+
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
23002306
},
23012307
PostFailBackAction::FailOffChain => {
23022308
nodes[2].node.fail_htlc_backwards(&payment_hash);
@@ -2308,6 +2314,7 @@ fn do_test_fail_back_before_backwards_timeout(post_fail_back_action: PostFailBac
23082314
nodes[1].node.handle_update_fail_htlc(&nodes[2].node.get_our_node_id(), &update_fail);
23092315
let err_msg = get_err_msg(&nodes[1], &nodes[2].node.get_our_node_id());
23102316
assert_eq!(err_msg.channel_id, chan_2.2);
2317+
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
23112318
},
23122319
PostFailBackAction::ClaimOffChain => {
23132320
nodes[2].node.claim_funds(payment_preimage);
@@ -2319,6 +2326,7 @@ fn do_test_fail_back_before_backwards_timeout(post_fail_back_action: PostFailBac
23192326
nodes[1].node.handle_update_fulfill_htlc(&nodes[2].node.get_our_node_id(), &update_fulfill);
23202327
let err_msg = get_err_msg(&nodes[1], &nodes[2].node.get_our_node_id());
23212328
assert_eq!(err_msg.channel_id, chan_2.2);
2329+
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
23222330
},
23232331
};
23242332
}

0 commit comments

Comments
 (0)