@@ -52,7 +52,7 @@ use regex;
52
52
53
53
use std:: collections:: { BTreeSet , HashMap , HashSet } ;
54
54
use core:: default:: Default ;
55
- use std:: sync:: Mutex ;
55
+ use std:: sync:: { Arc , Mutex } ;
56
56
57
57
use ln:: functional_test_utils:: * ;
58
58
use ln:: chan_utils:: CommitmentTransaction ;
@@ -2748,7 +2748,8 @@ fn test_htlc_on_chain_success() {
2748
2748
let chan_2 = create_announced_chan_between_nodes ( & nodes, 1 , 2 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
2749
2749
2750
2750
// Ensure all nodes are at the same height
2751
- let node_max_height = std:: cmp:: max ( nodes[ 0 ] . blocks . borrow ( ) . len ( ) , std:: cmp:: max ( nodes[ 1 ] . blocks . borrow ( ) . len ( ) , nodes[ 2 ] . blocks . borrow ( ) . len ( ) ) ) as u32 ;
2751
+ let node_max_height = std:: cmp:: max ( nodes[ 0 ] . blocks . lock ( ) . unwrap ( ) . len ( ) ,
2752
+ std:: cmp:: max ( nodes[ 1 ] . blocks . lock ( ) . unwrap ( ) . len ( ) , nodes[ 2 ] . blocks . lock ( ) . unwrap ( ) . len ( ) ) ) as u32 ;
2752
2753
connect_blocks ( & nodes[ 0 ] , node_max_height - nodes[ 0 ] . best_block_info ( ) . 1 ) ;
2753
2754
connect_blocks ( & nodes[ 1 ] , node_max_height - nodes[ 1 ] . best_block_info ( ) . 1 ) ;
2754
2755
connect_blocks ( & nodes[ 2 ] , node_max_height - nodes[ 2 ] . best_block_info ( ) . 1 ) ;
@@ -4521,7 +4522,7 @@ fn test_dup_htlc_onchain_fails_on_reload() {
4521
4522
// Note that if we re-connect the block which exposed nodes[0] to the payment preimage (but
4522
4523
// which the current ChannelMonitor has not seen), the ChannelManager's de-duplication of
4523
4524
// payment events should kick in, leaving us with no pending events here.
4524
- nodes[ 0 ] . chain_monitor . chain_monitor . block_connected ( & claim_block, nodes[ 0 ] . blocks . borrow ( ) . len ( ) as u32 - 1 ) ;
4525
+ nodes[ 0 ] . chain_monitor . chain_monitor . block_connected ( & claim_block, nodes[ 0 ] . blocks . lock ( ) . unwrap ( ) . len ( ) as u32 - 1 ) ;
4525
4526
assert ! ( nodes[ 0 ] . node. get_and_clear_pending_events( ) . is_empty( ) ) ;
4526
4527
}
4527
4528
@@ -5242,7 +5243,8 @@ fn test_onchain_to_onchain_claim() {
5242
5243
let chan_2 = create_announced_chan_between_nodes ( & nodes, 1 , 2 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
5243
5244
5244
5245
// Ensure all nodes are at the same height
5245
- let node_max_height = std:: cmp:: max ( nodes[ 0 ] . blocks . borrow ( ) . len ( ) , std:: cmp:: max ( nodes[ 1 ] . blocks . borrow ( ) . len ( ) , nodes[ 2 ] . blocks . borrow ( ) . len ( ) ) ) as u32 ;
5246
+ let node_max_height = std:: cmp:: max ( nodes[ 0 ] . blocks . lock ( ) . unwrap ( ) . len ( ) ,
5247
+ std:: cmp:: max ( nodes[ 1 ] . blocks . lock ( ) . unwrap ( ) . len ( ) , nodes[ 2 ] . blocks . lock ( ) . unwrap ( ) . len ( ) ) ) as u32 ;
5246
5248
connect_blocks ( & nodes[ 0 ] , node_max_height - nodes[ 0 ] . best_block_info ( ) . 1 ) ;
5247
5249
connect_blocks ( & nodes[ 1 ] , node_max_height - nodes[ 1 ] . best_block_info ( ) . 1 ) ;
5248
5250
connect_blocks ( & nodes[ 2 ] , node_max_height - nodes[ 2 ] . best_block_info ( ) . 1 ) ;
@@ -5355,7 +5357,9 @@ fn test_duplicate_payment_hash_one_failure_one_success() {
5355
5357
let chan_2 = create_announced_chan_between_nodes ( & nodes, 1 , 2 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
5356
5358
create_announced_chan_between_nodes ( & nodes, 2 , 3 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
5357
5359
5358
- let node_max_height = std:: cmp:: max ( std:: cmp:: max ( nodes[ 0 ] . blocks . borrow ( ) . len ( ) , nodes[ 1 ] . blocks . borrow ( ) . len ( ) ) , std:: cmp:: max ( nodes[ 2 ] . blocks . borrow ( ) . len ( ) , nodes[ 3 ] . blocks . borrow ( ) . len ( ) ) ) as u32 ;
5360
+ let node_max_height = std:: cmp:: max (
5361
+ std:: cmp:: max ( nodes[ 0 ] . blocks . lock ( ) . unwrap ( ) . len ( ) , nodes[ 1 ] . blocks . lock ( ) . unwrap ( ) . len ( ) ) ,
5362
+ std:: cmp:: max ( nodes[ 2 ] . blocks . lock ( ) . unwrap ( ) . len ( ) , nodes[ 3 ] . blocks . lock ( ) . unwrap ( ) . len ( ) ) ) as u32 ;
5359
5363
connect_blocks ( & nodes[ 0 ] , node_max_height - nodes[ 0 ] . best_block_info ( ) . 1 ) ;
5360
5364
connect_blocks ( & nodes[ 1 ] , node_max_height - nodes[ 1 ] . best_block_info ( ) . 1 ) ;
5361
5365
connect_blocks ( & nodes[ 2 ] , node_max_height - nodes[ 2 ] . best_block_info ( ) . 1 ) ;
@@ -7687,7 +7691,7 @@ fn test_data_loss_protect() {
7687
7691
logger = test_utils:: TestLogger :: with_id ( format ! ( "node {}" , 0 ) ) ;
7688
7692
let mut chain_monitor = <( BlockHash , ChannelMonitor < EnforcingSigner > ) >:: read ( & mut :: std:: io:: Cursor :: new ( previous_chain_monitor_state. 0 ) , keys_manager) . unwrap ( ) . 1 ;
7689
7693
chain_source = test_utils:: TestChainSource :: new ( Network :: Testnet ) ;
7690
- tx_broadcaster = test_utils:: TestBroadcaster { txn_broadcasted : Mutex :: new ( Vec :: new ( ) ) } ;
7694
+ tx_broadcaster = test_utils:: TestBroadcaster { txn_broadcasted : Mutex :: new ( Vec :: new ( ) ) , blocks : Arc :: new ( Mutex :: new ( Vec :: new ( ) ) ) } ;
7691
7695
fee_estimator = test_utils:: TestFeeEstimator { sat_per_kw : 253 } ;
7692
7696
persister = test_utils:: TestPersister :: new ( ) ;
7693
7697
monitor = test_utils:: TestChainMonitor :: new ( Some ( & chain_source) , & tx_broadcaster, & logger, & fee_estimator, & persister, keys_manager) ;
@@ -8472,14 +8476,18 @@ fn test_secret_timeout() {
8472
8476
if let Err ( APIError :: APIMisuseError { err } ) = nodes[ 1 ] . node . create_inbound_payment_for_hash ( payment_hash, Some ( 100_000 ) , 2 , 0 ) {
8473
8477
assert_eq ! ( err, "Duplicate payment hash" ) ;
8474
8478
} else { panic ! ( ) ; }
8475
- let mut block = Block {
8476
- header : BlockHeader {
8477
- version : 0x2000000 ,
8478
- prev_blockhash : nodes[ 1 ] . blocks . borrow ( ) . last ( ) . unwrap ( ) . 0 . block_hash ( ) ,
8479
- merkle_root : Default :: default ( ) ,
8480
- time : nodes[ 1 ] . blocks . borrow ( ) . len ( ) as u32 + 7200 , bits : 42 , nonce : 42 } ,
8481
- txdata : vec ! [ ] ,
8482
- } ;
8479
+ let mut block;
8480
+ {
8481
+ let node_1_blocks = nodes[ 1 ] . blocks . lock ( ) . unwrap ( ) ;
8482
+ block = Block {
8483
+ header : BlockHeader {
8484
+ version : 0x2000000 ,
8485
+ prev_blockhash : node_1_blocks. last ( ) . unwrap ( ) . 0 . block_hash ( ) ,
8486
+ merkle_root : Default :: default ( ) ,
8487
+ time : node_1_blocks. len ( ) as u32 + 7200 , bits : 42 , nonce : 42 } ,
8488
+ txdata : vec ! [ ] ,
8489
+ } ;
8490
+ }
8483
8491
connect_block ( & nodes[ 1 ] , & block) ;
8484
8492
if let Err ( APIError :: APIMisuseError { err } ) = nodes[ 1 ] . node . create_inbound_payment_for_hash ( payment_hash, Some ( 100_000 ) , 2 , 0 ) {
8485
8493
assert_eq ! ( err, "Duplicate payment hash" ) ;
@@ -8628,6 +8636,9 @@ fn test_update_err_monitor_lockdown() {
8628
8636
watchtower
8629
8637
} ;
8630
8638
let header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
8639
+ // Make the tx_broadcaster aware of enough blocks that it doesn't think we're violating
8640
+ // transaction lock time requirements here.
8641
+ chanmon_cfgs[ 0 ] . tx_broadcaster . blocks . lock ( ) . unwrap ( ) . resize ( 200 , ( header, 0 ) ) ;
8631
8642
watchtower. chain_monitor . block_connected ( & Block { header, txdata : vec ! [ ] } , 200 ) ;
8632
8643
8633
8644
// Try to update ChannelMonitor
@@ -8687,6 +8698,9 @@ fn test_concurrent_monitor_claim() {
8687
8698
watchtower
8688
8699
} ;
8689
8700
let header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
8701
+ // Make the tx_broadcaster aware of enough blocks that it doesn't think we're violating
8702
+ // transaction lock time requirements here.
8703
+ chanmon_cfgs[ 0 ] . tx_broadcaster . blocks . lock ( ) . unwrap ( ) . resize ( ( CHAN_CONFIRM_DEPTH + 1 + TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS ) as usize , ( header, 0 ) ) ;
8690
8704
watchtower_alice. chain_monitor . block_connected ( & Block { header, txdata : vec ! [ ] } , CHAN_CONFIRM_DEPTH + 1 + TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS ) ;
8691
8705
8692
8706
// Watchtower Alice should have broadcast a commitment/HTLC-timeout
0 commit comments