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