@@ -2237,23 +2237,27 @@ fn do_test_fail_back_before_backwards_timeout(post_fail_back_action: PostFailBac
2237
2237
create_announced_chan_between_nodes(&nodes, 0, 1);
2238
2238
let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2);
2239
2239
2240
+ // Start every node on the same block height to make reasoning about timeouts easier
2240
2241
connect_blocks(&nodes[0], 2*CHAN_CONFIRM_DEPTH + 1 - nodes[0].best_block_info().1);
2241
2242
connect_blocks(&nodes[1], 2*CHAN_CONFIRM_DEPTH + 1 - nodes[1].best_block_info().1);
2242
2243
connect_blocks(&nodes[2], 2*CHAN_CONFIRM_DEPTH + 1 - nodes[2].best_block_info().1);
2243
2244
2244
2245
let (payment_preimage, payment_hash, _) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 3_000_000);
2245
2246
2246
2247
// 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);
2252
2250
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);
2254
2254
2255
2255
// 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);
2257
2261
2258
2262
// Check that nodes[1] fails the HTLC upstream
2259
2263
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
2282
2286
// Confirm nodes[1]'s claim with timeout, make sure we don't fail upstream again
2283
2287
mine_transaction(&nodes[1], &node_1_txn[0]); // Commitment
2284
2288
mine_transaction(&nodes[1], &node_1_txn[1]); // HTLC timeout
2289
+ assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
2285
2290
},
2286
2291
PostFailBackAction::ClaimOnChain => {
2287
2292
nodes[2].node.claim_funds(payment_preimage);
@@ -2297,6 +2302,7 @@ fn do_test_fail_back_before_backwards_timeout(post_fail_back_action: PostFailBac
2297
2302
2298
2303
mine_transaction(&nodes[1], &node_2_txn[0]); // Commitment
2299
2304
mine_transaction(&nodes[1], &node_2_txn[1]); // HTLC success
2305
+ assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
2300
2306
},
2301
2307
PostFailBackAction::FailOffChain => {
2302
2308
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
2308
2314
nodes[1].node.handle_update_fail_htlc(&nodes[2].node.get_our_node_id(), &update_fail);
2309
2315
let err_msg = get_err_msg(&nodes[1], &nodes[2].node.get_our_node_id());
2310
2316
assert_eq!(err_msg.channel_id, chan_2.2);
2317
+ assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
2311
2318
},
2312
2319
PostFailBackAction::ClaimOffChain => {
2313
2320
nodes[2].node.claim_funds(payment_preimage);
@@ -2319,6 +2326,7 @@ fn do_test_fail_back_before_backwards_timeout(post_fail_back_action: PostFailBac
2319
2326
nodes[1].node.handle_update_fulfill_htlc(&nodes[2].node.get_our_node_id(), &update_fulfill);
2320
2327
let err_msg = get_err_msg(&nodes[1], &nodes[2].node.get_our_node_id());
2321
2328
assert_eq!(err_msg.channel_id, chan_2.2);
2329
+ assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
2322
2330
},
2323
2331
};
2324
2332
}
0 commit comments