@@ -8434,7 +8434,7 @@ fn test_update_err_monitor_lockdown() {
8434
8434
let block = Block { header, txdata: vec![] };
8435
8435
// Make the tx_broadcaster aware of enough blocks that it doesn't think we're violating
8436
8436
// transaction lock time requirements here.
8437
- chanmon_cfgs[0].tx_broadcaster.blocks.lock().unwrap().resize(200, (block.clone(), 0 ));
8437
+ chanmon_cfgs[0].tx_broadcaster.blocks.lock().unwrap().resize(200, (block.clone(), 200 ));
8438
8438
watchtower.chain_monitor.block_connected(&block, 200);
8439
8439
8440
8440
// Try to update ChannelMonitor
@@ -8486,6 +8486,7 @@ fn test_concurrent_monitor_claim() {
8486
8486
let chain_source = test_utils::TestChainSource::new(Network::Testnet);
8487
8487
let logger = test_utils::TestLogger::with_id(format!("node {}", "Alice"));
8488
8488
let persister = test_utils::TestPersister::new();
8489
+ let alice_broadcaster = test_utils::TestBroadcaster::new(Arc::new(Mutex::new(nodes[0].blocks.lock().unwrap().clone())));
8489
8490
let watchtower_alice = {
8490
8491
let new_monitor = {
8491
8492
let monitor = nodes[0].chain_monitor.chain_monitor.get_monitor(outpoint).unwrap();
@@ -8494,20 +8495,21 @@ fn test_concurrent_monitor_claim() {
8494
8495
assert!(new_monitor == *monitor);
8495
8496
new_monitor
8496
8497
};
8497
- let watchtower = test_utils::TestChainMonitor::new(Some(&chain_source), &chanmon_cfgs[0].tx_broadcaster , &logger, &chanmon_cfgs[0].fee_estimator, &persister, &node_cfgs[0].keys_manager);
8498
+ let watchtower = test_utils::TestChainMonitor::new(Some(&chain_source), &alice_broadcaster , &logger, &chanmon_cfgs[0].fee_estimator, &persister, &node_cfgs[0].keys_manager);
8498
8499
assert_eq!(watchtower.watch_channel(outpoint, new_monitor), ChannelMonitorUpdateStatus::Completed);
8499
8500
watchtower
8500
8501
};
8501
8502
let header = BlockHeader { version: 0x20000000, prev_blockhash: BlockHash::all_zeros(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 };
8502
8503
let block = Block { header, txdata: vec![] };
8503
- // Make the tx_broadcaster aware of enough blocks that it doesn't think we're violating
8504
- // transaction lock time requirements here.
8505
- chanmon_cfgs[0].tx_broadcaster.blocks.lock().unwrap().resize((CHAN_CONFIRM_DEPTH + 1 + TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS) as usize, (block.clone(), 0));
8504
+ // Make Alice aware of enough blocks that it doesn't think we're violating transaction lock time
8505
+ // requirements here.
8506
+ const HTLC_TIMEOUT_BROADCAST: u32 = CHAN_CONFIRM_DEPTH + 1 + TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS;
8507
+ alice_broadcaster.blocks.lock().unwrap().resize((HTLC_TIMEOUT_BROADCAST) as usize, (block.clone(), HTLC_TIMEOUT_BROADCAST));
8506
8508
watchtower_alice.chain_monitor.block_connected(&block, CHAN_CONFIRM_DEPTH + 1 + TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS);
8507
8509
8508
8510
// Watchtower Alice should have broadcast a commitment/HTLC-timeout
8509
8511
let alice_state = {
8510
- let mut txn = chanmon_cfgs[0].tx_broadcaster .txn_broadcast();
8512
+ let mut txn = alice_broadcaster .txn_broadcast();
8511
8513
assert_eq!(txn.len(), 2);
8512
8514
txn.remove(0)
8513
8515
};
@@ -8516,6 +8518,7 @@ fn test_concurrent_monitor_claim() {
8516
8518
let chain_source = test_utils::TestChainSource::new(Network::Testnet);
8517
8519
let logger = test_utils::TestLogger::with_id(format!("node {}", "Bob"));
8518
8520
let persister = test_utils::TestPersister::new();
8521
+ let bob_broadcaster = test_utils::TestBroadcaster::new(Arc::clone(&alice_broadcaster.blocks));
8519
8522
let watchtower_bob = {
8520
8523
let new_monitor = {
8521
8524
let monitor = nodes[0].chain_monitor.chain_monitor.get_monitor(outpoint).unwrap();
@@ -8524,7 +8527,7 @@ fn test_concurrent_monitor_claim() {
8524
8527
assert!(new_monitor == *monitor);
8525
8528
new_monitor
8526
8529
};
8527
- let watchtower = test_utils::TestChainMonitor::new(Some(&chain_source), &chanmon_cfgs[0].tx_broadcaster , &logger, &chanmon_cfgs[0].fee_estimator, &persister, &node_cfgs[0].keys_manager);
8530
+ let watchtower = test_utils::TestChainMonitor::new(Some(&chain_source), &bob_broadcaster , &logger, &chanmon_cfgs[0].fee_estimator, &persister, &node_cfgs[0].keys_manager);
8528
8531
assert_eq!(watchtower.watch_channel(outpoint, new_monitor), ChannelMonitorUpdateStatus::Completed);
8529
8532
watchtower
8530
8533
};
@@ -8556,21 +8559,26 @@ fn test_concurrent_monitor_claim() {
8556
8559
8557
8560
//// Provide one more block to watchtower Bob, expect broadcast of commitment and HTLC-Timeout
8558
8561
let header = BlockHeader { version: 0x20000000, prev_blockhash: BlockHash::all_zeros(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 };
8559
- watchtower_bob.chain_monitor.block_connected(&Block { header, txdata: vec![] }, CHAN_CONFIRM_DEPTH + 1 + TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS );
8562
+ watchtower_bob.chain_monitor.block_connected(&Block { header, txdata: vec![] }, HTLC_TIMEOUT_BROADCAST );
8560
8563
8561
8564
// Watchtower Bob should have broadcast a commitment/HTLC-timeout
8562
8565
let bob_state_y;
8563
8566
{
8564
- let mut txn = chanmon_cfgs[0].tx_broadcaster .txn_broadcast();
8567
+ let mut txn = bob_broadcaster .txn_broadcast();
8565
8568
assert_eq!(txn.len(), 2);
8566
8569
bob_state_y = txn.remove(0);
8567
8570
};
8568
8571
8569
8572
// We confirm Bob's state Y on Alice, she should broadcast a HTLC-timeout
8570
8573
let header = BlockHeader { version: 0x20000000, prev_blockhash: BlockHash::all_zeros(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 };
8571
- watchtower_alice.chain_monitor.block_connected(&Block { header, txdata: vec![bob_state_y.clone()] }, CHAN_CONFIRM_DEPTH + 2 + TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS);
8574
+ let height = HTLC_TIMEOUT_BROADCAST + 1;
8575
+ connect_blocks(&nodes[0], height - nodes[0].best_block_info().1);
8576
+ check_closed_broadcast(&nodes[0], 1, true);
8577
+ check_closed_event(&nodes[0], 1, ClosureReason::CommitmentTxConfirmed, false);
8578
+ watchtower_alice.chain_monitor.block_connected(&Block { header, txdata: vec![bob_state_y.clone()] }, height);
8579
+ check_added_monitors(&nodes[0], 1);
8572
8580
{
8573
- let htlc_txn = chanmon_cfgs[0].tx_broadcaster .txn_broadcast();
8581
+ let htlc_txn = alice_broadcaster .txn_broadcast();
8574
8582
assert_eq!(htlc_txn.len(), 2);
8575
8583
check_spends!(htlc_txn[0], bob_state_y);
8576
8584
// Alice doesn't clean up the old HTLC claim since it hasn't seen a conflicting spend for
0 commit comments