@@ -2273,9 +2273,15 @@ fn channel_monitor_network_test() {
2273
2273
nodes[1].node.force_close_broadcasting_latest_txn(&chan_1.2, &nodes[0].node.get_our_node_id()).unwrap();
2274
2274
check_added_monitors!(nodes[1], 1);
2275
2275
check_closed_broadcast!(nodes[1], true);
2276
+ check_closed_event!(nodes[1], 1, ClosureReason::HolderForceClosed, [nodes[0].node.get_our_node_id()], 100000);
2276
2277
{
2277
2278
let mut node_txn = test_txn_broadcast(&nodes[1], &chan_1, None, HTLCType::NONE);
2278
2279
assert_eq!(node_txn.len(), 1);
2280
+ mine_transaction(&nodes[1], &node_txn[0]);
2281
+ if nodes[1].connect_style.borrow().updates_best_block_first() {
2282
+ let _ = nodes[1].tx_broadcaster.txn_broadcast();
2283
+ }
2284
+
2279
2285
mine_transaction(&nodes[0], &node_txn[0]);
2280
2286
check_added_monitors!(nodes[0], 1);
2281
2287
test_txn_broadcast(&nodes[0], &chan_1, Some(node_txn[0].clone()), HTLCType::NONE);
@@ -2284,7 +2290,6 @@ fn channel_monitor_network_test() {
2284
2290
assert_eq!(nodes[0].node.list_channels().len(), 0);
2285
2291
assert_eq!(nodes[1].node.list_channels().len(), 1);
2286
2292
check_closed_event!(nodes[0], 1, ClosureReason::CommitmentTxConfirmed, [nodes[1].node.get_our_node_id()], 100000);
2287
- check_closed_event!(nodes[1], 1, ClosureReason::HolderForceClosed, [nodes[0].node.get_our_node_id()], 100000);
2288
2293
2289
2294
// One pending HTLC is discarded by the force-close:
2290
2295
let (payment_preimage_1, payment_hash_1, ..) = route_payment(&nodes[1], &[&nodes[2], &nodes[3]], 3_000_000);
@@ -3556,7 +3561,7 @@ fn test_htlc_ignore_latest_remote_commitment() {
3556
3561
// connect_style.
3557
3562
return;
3558
3563
}
3559
- create_announced_chan_between_nodes(&nodes, 0, 1);
3564
+ let funding_tx = create_announced_chan_between_nodes(&nodes, 0, 1).3 ;
3560
3565
3561
3566
route_payment(&nodes[0], &[&nodes[1]], 10000000);
3562
3567
nodes[0].node.force_close_broadcasting_latest_txn(&nodes[0].node.list_channels()[0].channel_id, &nodes[1].node.get_our_node_id()).unwrap();
@@ -3565,11 +3570,12 @@ fn test_htlc_ignore_latest_remote_commitment() {
3565
3570
check_added_monitors!(nodes[0], 1);
3566
3571
check_closed_event!(nodes[0], 1, ClosureReason::HolderForceClosed, [nodes[1].node.get_our_node_id()], 100000);
3567
3572
3568
- let node_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
3569
- assert_eq!(node_txn.len(), 3);
3570
- assert_eq!(node_txn[0].txid(), node_txn[1].txid());
3573
+ let node_txn = nodes[0].tx_broadcaster.unique_txn_broadcast();
3574
+ assert_eq!(node_txn.len(), 2);
3575
+ check_spends!(node_txn[0], funding_tx);
3576
+ check_spends!(node_txn[1], node_txn[0]);
3571
3577
3572
- let block = create_dummy_block(nodes[1].best_block_hash(), 42, vec![node_txn[0].clone(), node_txn[1].clone() ]);
3578
+ let block = create_dummy_block(nodes[1].best_block_hash(), 42, vec![node_txn[0].clone()]);
3573
3579
connect_block(&nodes[1], &block);
3574
3580
check_closed_broadcast!(nodes[1], true);
3575
3581
check_added_monitors!(nodes[1], 1);
@@ -3626,7 +3632,7 @@ fn test_force_close_fail_back() {
3626
3632
check_closed_broadcast!(nodes[2], true);
3627
3633
check_added_monitors!(nodes[2], 1);
3628
3634
check_closed_event!(nodes[2], 1, ClosureReason::HolderForceClosed, [nodes[1].node.get_our_node_id()], 100000);
3629
- let tx = {
3635
+ let commitment_tx = {
3630
3636
let mut node_txn = nodes[2].tx_broadcaster.txn_broadcasted.lock().unwrap();
3631
3637
// Note that we don't bother broadcasting the HTLC-Success transaction here as we don't
3632
3638
// have a use for it unless nodes[2] learns the preimage somehow, the funds will go
@@ -3635,7 +3641,7 @@ fn test_force_close_fail_back() {
3635
3641
node_txn.remove(0)
3636
3642
};
3637
3643
3638
- mine_transaction(&nodes[1], &tx );
3644
+ mine_transaction(&nodes[1], &commitment_tx );
3639
3645
3640
3646
// Note no UpdateHTLCs event here from nodes[1] to nodes[0]!
3641
3647
check_closed_broadcast!(nodes[1], true);
@@ -3647,15 +3653,16 @@ fn test_force_close_fail_back() {
3647
3653
get_monitor!(nodes[2], payment_event.commitment_msg.channel_id)
3648
3654
.provide_payment_preimage(&our_payment_hash, &our_payment_preimage, &node_cfgs[2].tx_broadcaster, &LowerBoundedFeeEstimator::new(node_cfgs[2].fee_estimator), &node_cfgs[2].logger);
3649
3655
}
3650
- mine_transaction(&nodes[2], &tx);
3651
- let node_txn = nodes[2].tx_broadcaster.txn_broadcasted.lock().unwrap();
3652
- assert_eq!(node_txn.len(), 1);
3653
- assert_eq!(node_txn[0].input.len(), 1);
3654
- assert_eq!(node_txn[0].input[0].previous_output.txid, tx.txid());
3655
- assert_eq!(node_txn[0].lock_time, LockTime::ZERO); // Must be an HTLC-Success
3656
- assert_eq!(node_txn[0].input[0].witness.len(), 5); // Must be an HTLC-Success
3656
+ mine_transaction(&nodes[2], &commitment_tx);
3657
+ let mut node_txn = nodes[2].tx_broadcaster.txn_broadcast();
3658
+ assert_eq!(node_txn.len(), if nodes[2].connect_style.borrow().updates_best_block_first() { 2 } else { 1 });
3659
+ let htlc_tx = node_txn.pop().unwrap();
3660
+ assert_eq!(htlc_tx.input.len(), 1);
3661
+ assert_eq!(htlc_tx.input[0].previous_output.txid, commitment_tx.txid());
3662
+ assert_eq!(htlc_tx.lock_time, LockTime::ZERO); // Must be an HTLC-Success
3663
+ assert_eq!(htlc_tx.input[0].witness.len(), 5); // Must be an HTLC-Success
3657
3664
3658
- check_spends!(node_txn[0], tx );
3665
+ check_spends!(htlc_tx, commitment_tx );
3659
3666
}
3660
3667
3661
3668
#[test]
@@ -8881,7 +8888,12 @@ fn do_test_onchain_htlc_settlement_after_close(broadcast_alice: bool, go_onchain
8881
8888
assert_eq!(bob_txn.len(), 1);
8882
8889
check_spends!(bob_txn[0], txn_to_broadcast[0]);
8883
8890
} else {
8884
- assert_eq!(bob_txn.len(), 2);
8891
+ if nodes[1].connect_style.borrow().updates_best_block_first() {
8892
+ assert_eq!(bob_txn.len(), 3);
8893
+ assert_eq!(bob_txn[0].txid(), bob_txn[1].txid());
8894
+ } else {
8895
+ assert_eq!(bob_txn.len(), 2);
8896
+ }
8885
8897
check_spends!(bob_txn[0], chan_ab.3);
8886
8898
}
8887
8899
}
@@ -8897,15 +8909,16 @@ fn do_test_onchain_htlc_settlement_after_close(broadcast_alice: bool, go_onchain
8897
8909
// If Alice force-closed, Bob only broadcasts a HTLC-output-claiming transaction. Otherwise,
8898
8910
// Bob force-closed and broadcasts the commitment transaction along with a
8899
8911
// HTLC-output-claiming transaction.
8900
- let bob_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().clone();
8912
+ let mut bob_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().clone();
8901
8913
if broadcast_alice {
8902
8914
assert_eq!(bob_txn.len(), 1);
8903
8915
check_spends!(bob_txn[0], txn_to_broadcast[0]);
8904
8916
assert_eq!(bob_txn[0].input[0].witness.last().unwrap().len(), script_weight);
8905
8917
} else {
8906
- assert_eq!(bob_txn.len(), 2);
8907
- check_spends!(bob_txn[1], txn_to_broadcast[0]);
8908
- assert_eq!(bob_txn[1].input[0].witness.last().unwrap().len(), script_weight);
8918
+ assert_eq!(bob_txn.len(), if nodes[1].connect_style.borrow().updates_best_block_first() { 3 } else { 2 });
8919
+ let htlc_tx = bob_txn.pop().unwrap();
8920
+ check_spends!(htlc_tx, txn_to_broadcast[0]);
8921
+ assert_eq!(htlc_tx.input[0].witness.last().unwrap().len(), script_weight);
8909
8922
}
8910
8923
}
8911
8924
}
@@ -9381,8 +9394,12 @@ fn do_test_tx_confirmed_skipping_blocks_immediate_broadcast(test_height_before_t
9381
9394
// We should broadcast an HTLC transaction spending our funding transaction first
9382
9395
let spending_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
9383
9396
assert_eq!(spending_txn.len(), 2);
9384
- assert_eq!(spending_txn[0].txid(), node_txn[0].txid());
9385
- check_spends!(spending_txn[1], node_txn[0]);
9397
+ let htlc_tx = if spending_txn[0].txid() == node_txn[0].txid() {
9398
+ &spending_txn[1]
9399
+ } else {
9400
+ &spending_txn[0]
9401
+ };
9402
+ check_spends!(htlc_tx, node_txn[0]);
9386
9403
// We should also generate a SpendableOutputs event with the to_self output (as its
9387
9404
// timelock is up).
9388
9405
let descriptor_spend_txn = check_spendable_outputs!(nodes[1], node_cfgs[1].keys_manager);
@@ -9392,7 +9409,7 @@ fn do_test_tx_confirmed_skipping_blocks_immediate_broadcast(test_height_before_t
9392
9409
// should immediately fail-backwards the HTLC to the previous hop, without waiting for an
9393
9410
// additional block built on top of the current chain.
9394
9411
nodes[1].chain_monitor.chain_monitor.transactions_confirmed(
9395
- &nodes[1].get_block_header(conf_height + 1), &[(0, &spending_txn[1] )], conf_height + 1);
9412
+ &nodes[1].get_block_header(conf_height + 1), &[(0, htlc_tx )], conf_height + 1);
9396
9413
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: channel_id }]);
9397
9414
check_added_monitors!(nodes[1], 1);
9398
9415
0 commit comments