Skip to content

Commit 3fd4801

Browse files
committed
Catch up test nodes to latest block height
In a future commit, we plan to correctly enforce that the spending transaction has a valid locktime relative to the chain for the node broascasting it in `TestBroadcaster::broadcast_transaction` to. We catch up these test node instances to their expected height, such that we do not fail said enforcement.
1 parent 762f1c3 commit 3fd4801

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

lightning/src/ln/functional_tests.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8434,7 +8434,7 @@ fn test_update_err_monitor_lockdown() {
84348434
let block = Block { header, txdata: vec![] };
84358435
// Make the tx_broadcaster aware of enough blocks that it doesn't think we're violating
84368436
// 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));
84388438
watchtower.chain_monitor.block_connected(&block, 200);
84398439

84408440
// Try to update ChannelMonitor
@@ -8486,6 +8486,7 @@ fn test_concurrent_monitor_claim() {
84868486
let chain_source = test_utils::TestChainSource::new(Network::Testnet);
84878487
let logger = test_utils::TestLogger::with_id(format!("node {}", "Alice"));
84888488
let persister = test_utils::TestPersister::new();
8489+
let alice_broadcaster = test_utils::TestBroadcaster::new(Arc::new(Mutex::new(nodes[0].blocks.lock().unwrap().clone())));
84898490
let watchtower_alice = {
84908491
let new_monitor = {
84918492
let monitor = nodes[0].chain_monitor.chain_monitor.get_monitor(outpoint).unwrap();
@@ -8494,20 +8495,21 @@ fn test_concurrent_monitor_claim() {
84948495
assert!(new_monitor == *monitor);
84958496
new_monitor
84968497
};
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);
84988499
assert_eq!(watchtower.watch_channel(outpoint, new_monitor), ChannelMonitorUpdateStatus::Completed);
84998500
watchtower
85008501
};
85018502
let header = BlockHeader { version: 0x20000000, prev_blockhash: BlockHash::all_zeros(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 };
85028503
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));
85068508
watchtower_alice.chain_monitor.block_connected(&block, CHAN_CONFIRM_DEPTH + 1 + TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS);
85078509

85088510
// Watchtower Alice should have broadcast a commitment/HTLC-timeout
85098511
let alice_state = {
8510-
let mut txn = chanmon_cfgs[0].tx_broadcaster.txn_broadcast();
8512+
let mut txn = alice_broadcaster.txn_broadcast();
85118513
assert_eq!(txn.len(), 2);
85128514
txn.remove(0)
85138515
};
@@ -8516,6 +8518,7 @@ fn test_concurrent_monitor_claim() {
85168518
let chain_source = test_utils::TestChainSource::new(Network::Testnet);
85178519
let logger = test_utils::TestLogger::with_id(format!("node {}", "Bob"));
85188520
let persister = test_utils::TestPersister::new();
8521+
let bob_broadcaster = test_utils::TestBroadcaster::new(Arc::clone(&alice_broadcaster.blocks));
85198522
let watchtower_bob = {
85208523
let new_monitor = {
85218524
let monitor = nodes[0].chain_monitor.chain_monitor.get_monitor(outpoint).unwrap();
@@ -8524,7 +8527,7 @@ fn test_concurrent_monitor_claim() {
85248527
assert!(new_monitor == *monitor);
85258528
new_monitor
85268529
};
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);
85288531
assert_eq!(watchtower.watch_channel(outpoint, new_monitor), ChannelMonitorUpdateStatus::Completed);
85298532
watchtower
85308533
};
@@ -8556,21 +8559,26 @@ fn test_concurrent_monitor_claim() {
85568559

85578560
//// Provide one more block to watchtower Bob, expect broadcast of commitment and HTLC-Timeout
85588561
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);
85608563

85618564
// Watchtower Bob should have broadcast a commitment/HTLC-timeout
85628565
let bob_state_y;
85638566
{
8564-
let mut txn = chanmon_cfgs[0].tx_broadcaster.txn_broadcast();
8567+
let mut txn = bob_broadcaster.txn_broadcast();
85658568
assert_eq!(txn.len(), 2);
85668569
bob_state_y = txn.remove(0);
85678570
};
85688571

85698572
// We confirm Bob's state Y on Alice, she should broadcast a HTLC-timeout
85708573
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);
85728580
{
8573-
let htlc_txn = chanmon_cfgs[0].tx_broadcaster.txn_broadcast();
8581+
let htlc_txn = alice_broadcaster.txn_broadcast();
85748582
assert_eq!(htlc_txn.len(), 2);
85758583
check_spends!(htlc_txn[0], bob_state_y);
85768584
// Alice doesn't clean up the old HTLC claim since it hasn't seen a conflicting spend for

0 commit comments

Comments
 (0)