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