@@ -2269,9 +2269,15 @@ fn channel_monitor_network_test() {
2269
2269
nodes[1].node.force_close_broadcasting_latest_txn(&chan_1.2, &nodes[0].node.get_our_node_id()).unwrap();
2270
2270
check_added_monitors!(nodes[1], 1);
2271
2271
check_closed_broadcast!(nodes[1], true);
2272
+ check_closed_event!(nodes[1], 1, ClosureReason::HolderForceClosed, [nodes[0].node.get_our_node_id()], 100000);
2272
2273
{
2273
2274
let mut node_txn = test_txn_broadcast(&nodes[1], &chan_1, None, HTLCType::NONE);
2274
2275
assert_eq!(node_txn.len(), 1);
2276
+ mine_transaction(&nodes[1], &node_txn[0]);
2277
+ if nodes[1].connect_style.borrow().updates_best_block_first() {
2278
+ let _ = nodes[1].tx_broadcaster.txn_broadcast();
2279
+ }
2280
+
2275
2281
mine_transaction(&nodes[0], &node_txn[0]);
2276
2282
check_added_monitors!(nodes[0], 1);
2277
2283
test_txn_broadcast(&nodes[0], &chan_1, Some(node_txn[0].clone()), HTLCType::NONE);
@@ -2280,7 +2286,6 @@ fn channel_monitor_network_test() {
2280
2286
assert_eq!(nodes[0].node.list_channels().len(), 0);
2281
2287
assert_eq!(nodes[1].node.list_channels().len(), 1);
2282
2288
check_closed_event!(nodes[0], 1, ClosureReason::CommitmentTxConfirmed, [nodes[1].node.get_our_node_id()], 100000);
2283
- check_closed_event!(nodes[1], 1, ClosureReason::HolderForceClosed, [nodes[0].node.get_our_node_id()], 100000);
2284
2289
2285
2290
// One pending HTLC is discarded by the force-close:
2286
2291
let (payment_preimage_1, payment_hash_1, ..) = route_payment(&nodes[1], &[&nodes[2], &nodes[3]], 3_000_000);
@@ -3551,7 +3556,7 @@ fn test_htlc_ignore_latest_remote_commitment() {
3551
3556
// connect_style.
3552
3557
return;
3553
3558
}
3554
- create_announced_chan_between_nodes(&nodes, 0, 1);
3559
+ let funding_tx = create_announced_chan_between_nodes(&nodes, 0, 1).3 ;
3555
3560
3556
3561
route_payment(&nodes[0], &[&nodes[1]], 10000000);
3557
3562
nodes[0].node.force_close_broadcasting_latest_txn(&nodes[0].node.list_channels()[0].channel_id, &nodes[1].node.get_our_node_id()).unwrap();
@@ -3560,11 +3565,12 @@ fn test_htlc_ignore_latest_remote_commitment() {
3560
3565
check_added_monitors!(nodes[0], 1);
3561
3566
check_closed_event!(nodes[0], 1, ClosureReason::HolderForceClosed, [nodes[1].node.get_our_node_id()], 100000);
3562
3567
3563
- let node_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
3564
- assert_eq!(node_txn.len(), 3);
3565
- assert_eq!(node_txn[0].txid(), node_txn[1].txid());
3568
+ let node_txn = nodes[0].tx_broadcaster.unique_txn_broadcast();
3569
+ assert_eq!(node_txn.len(), 2);
3570
+ check_spends!(node_txn[0], funding_tx);
3571
+ check_spends!(node_txn[1], node_txn[0]);
3566
3572
3567
- let block = create_dummy_block(nodes[1].best_block_hash(), 42, vec![node_txn[0].clone(), node_txn[1].clone() ]);
3573
+ let block = create_dummy_block(nodes[1].best_block_hash(), 42, vec![node_txn[0].clone()]);
3568
3574
connect_block(&nodes[1], &block);
3569
3575
check_closed_broadcast!(nodes[1], true);
3570
3576
check_added_monitors!(nodes[1], 1);
@@ -3621,7 +3627,7 @@ fn test_force_close_fail_back() {
3621
3627
check_closed_broadcast!(nodes[2], true);
3622
3628
check_added_monitors!(nodes[2], 1);
3623
3629
check_closed_event!(nodes[2], 1, ClosureReason::HolderForceClosed, [nodes[1].node.get_our_node_id()], 100000);
3624
- let tx = {
3630
+ let commitment_tx = {
3625
3631
let mut node_txn = nodes[2].tx_broadcaster.txn_broadcasted.lock().unwrap();
3626
3632
// Note that we don't bother broadcasting the HTLC-Success transaction here as we don't
3627
3633
// have a use for it unless nodes[2] learns the preimage somehow, the funds will go
@@ -3630,7 +3636,7 @@ fn test_force_close_fail_back() {
3630
3636
node_txn.remove(0)
3631
3637
};
3632
3638
3633
- mine_transaction(&nodes[1], &tx );
3639
+ mine_transaction(&nodes[1], &commitment_tx );
3634
3640
3635
3641
// Note no UpdateHTLCs event here from nodes[1] to nodes[0]!
3636
3642
check_closed_broadcast!(nodes[1], true);
@@ -3642,15 +3648,16 @@ fn test_force_close_fail_back() {
3642
3648
get_monitor!(nodes[2], payment_event.commitment_msg.channel_id)
3643
3649
.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);
3644
3650
}
3645
- mine_transaction(&nodes[2], &tx);
3646
- let node_txn = nodes[2].tx_broadcaster.txn_broadcasted.lock().unwrap();
3647
- assert_eq!(node_txn.len(), 1);
3648
- assert_eq!(node_txn[0].input.len(), 1);
3649
- assert_eq!(node_txn[0].input[0].previous_output.txid, tx.txid());
3650
- assert_eq!(node_txn[0].lock_time.0, 0); // Must be an HTLC-Success
3651
- assert_eq!(node_txn[0].input[0].witness.len(), 5); // Must be an HTLC-Success
3651
+ mine_transaction(&nodes[2], &commitment_tx);
3652
+ let mut node_txn = nodes[2].tx_broadcaster.txn_broadcast();
3653
+ assert_eq!(node_txn.len(), if nodes[2].connect_style.borrow().updates_best_block_first() { 2 } else { 1 });
3654
+ let htlc_tx = node_txn.pop().unwrap();
3655
+ assert_eq!(htlc_tx.input.len(), 1);
3656
+ assert_eq!(htlc_tx.input[0].previous_output.txid, commitment_tx.txid());
3657
+ assert_eq!(htlc_tx.lock_time.0, 0); // Must be an HTLC-Success
3658
+ assert_eq!(htlc_tx.input[0].witness.len(), 5); // Must be an HTLC-Success
3652
3659
3653
- check_spends!(node_txn[0], tx );
3660
+ check_spends!(htlc_tx, commitment_tx );
3654
3661
}
3655
3662
3656
3663
#[test]
@@ -8851,7 +8858,12 @@ fn do_test_onchain_htlc_settlement_after_close(broadcast_alice: bool, go_onchain
8851
8858
assert_eq!(bob_txn.len(), 1);
8852
8859
check_spends!(bob_txn[0], txn_to_broadcast[0]);
8853
8860
} else {
8854
- assert_eq!(bob_txn.len(), 2);
8861
+ if nodes[1].connect_style.borrow().updates_best_block_first() {
8862
+ assert_eq!(bob_txn.len(), 3);
8863
+ assert_eq!(bob_txn[0].txid(), bob_txn[1].txid());
8864
+ } else {
8865
+ assert_eq!(bob_txn.len(), 2);
8866
+ }
8855
8867
check_spends!(bob_txn[0], chan_ab.3);
8856
8868
}
8857
8869
}
@@ -8867,15 +8879,16 @@ fn do_test_onchain_htlc_settlement_after_close(broadcast_alice: bool, go_onchain
8867
8879
// If Alice force-closed, Bob only broadcasts a HTLC-output-claiming transaction. Otherwise,
8868
8880
// Bob force-closed and broadcasts the commitment transaction along with a
8869
8881
// HTLC-output-claiming transaction.
8870
- let bob_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().clone();
8882
+ let mut bob_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().clone();
8871
8883
if broadcast_alice {
8872
8884
assert_eq!(bob_txn.len(), 1);
8873
8885
check_spends!(bob_txn[0], txn_to_broadcast[0]);
8874
8886
assert_eq!(bob_txn[0].input[0].witness.last().unwrap().len(), script_weight);
8875
8887
} else {
8876
- assert_eq!(bob_txn.len(), 2);
8877
- check_spends!(bob_txn[1], txn_to_broadcast[0]);
8878
- assert_eq!(bob_txn[1].input[0].witness.last().unwrap().len(), script_weight);
8888
+ assert_eq!(bob_txn.len(), if nodes[1].connect_style.borrow().updates_best_block_first() { 3 } else { 2 });
8889
+ let htlc_tx = bob_txn.pop().unwrap();
8890
+ check_spends!(htlc_tx, txn_to_broadcast[0]);
8891
+ assert_eq!(htlc_tx.input[0].witness.last().unwrap().len(), script_weight);
8879
8892
}
8880
8893
}
8881
8894
}
@@ -9351,8 +9364,12 @@ fn do_test_tx_confirmed_skipping_blocks_immediate_broadcast(test_height_before_t
9351
9364
// We should broadcast an HTLC transaction spending our funding transaction first
9352
9365
let spending_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
9353
9366
assert_eq!(spending_txn.len(), 2);
9354
- assert_eq!(spending_txn[0].txid(), node_txn[0].txid());
9355
- check_spends!(spending_txn[1], node_txn[0]);
9367
+ let htlc_tx = if spending_txn[0].txid() == node_txn[0].txid() {
9368
+ &spending_txn[1]
9369
+ } else {
9370
+ &spending_txn[0]
9371
+ };
9372
+ check_spends!(htlc_tx, node_txn[0]);
9356
9373
// We should also generate a SpendableOutputs event with the to_self output (as its
9357
9374
// timelock is up).
9358
9375
let descriptor_spend_txn = check_spendable_outputs!(nodes[1], node_cfgs[1].keys_manager);
@@ -9362,7 +9379,7 @@ fn do_test_tx_confirmed_skipping_blocks_immediate_broadcast(test_height_before_t
9362
9379
// should immediately fail-backwards the HTLC to the previous hop, without waiting for an
9363
9380
// additional block built on top of the current chain.
9364
9381
nodes[1].chain_monitor.chain_monitor.transactions_confirmed(
9365
- &nodes[1].get_block_header(conf_height + 1), &[(0, &spending_txn[1] )], conf_height + 1);
9382
+ &nodes[1].get_block_header(conf_height + 1), &[(0, htlc_tx )], conf_height + 1);
9366
9383
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 }]);
9367
9384
check_added_monitors!(nodes[1], 1);
9368
9385
0 commit comments