@@ -2212,8 +2212,10 @@ mod tests {
2212
2212
2213
2213
use rand:: { thread_rng, Rng } ;
2214
2214
2215
+ use std:: cell:: RefCell ;
2215
2216
use std:: collections:: HashMap ;
2216
2217
use std:: default:: Default ;
2218
+ use std:: rc:: Rc ;
2217
2219
use std:: sync:: { Arc , Mutex } ;
2218
2220
use std:: time:: Instant ;
2219
2221
use std:: mem;
@@ -2384,9 +2386,10 @@ mod tests {
2384
2386
chan_monitor : Arc < test_utils:: TestChannelMonitor > ,
2385
2387
node : Arc < ChannelManager > ,
2386
2388
router : Router ,
2389
+ network_payment_count : Rc < RefCell < u8 > > ,
2390
+ network_chan_count : Rc < RefCell < u32 > > ,
2387
2391
}
2388
2392
2389
- static mut CHAN_COUNT : u32 = 0 ;
2390
2393
fn create_chan_between_nodes ( node_a : & Node , node_b : & Node ) -> ( msgs:: ChannelAnnouncement , msgs:: ChannelUpdate , msgs:: ChannelUpdate , [ u8 ; 32 ] , Transaction ) {
2391
2394
node_a. node . create_channel ( node_b. node . get_our_node_id ( ) , 100000 , 10001 , 42 ) . unwrap ( ) ;
2392
2395
@@ -2402,7 +2405,7 @@ mod tests {
2402
2405
2403
2406
node_a. node . handle_accept_channel ( & node_b. node . get_our_node_id ( ) , & accept_chan) . unwrap ( ) ;
2404
2407
2405
- let chan_id = unsafe { CHAN_COUNT } ;
2408
+ let chan_id = * node_a . network_chan_count . borrow ( ) ;
2406
2409
let tx;
2407
2410
let funding_output;
2408
2411
@@ -2508,9 +2511,7 @@ mod tests {
2508
2511
_ => panic ! ( "Unexpected event" ) ,
2509
2512
} ;
2510
2513
2511
- unsafe {
2512
- CHAN_COUNT += 1 ;
2513
- }
2514
+ * node_a. network_chan_count . borrow_mut ( ) += 1 ;
2514
2515
2515
2516
( ( * announcement) . clone ( ) , ( * as_update) . clone ( ) , ( * bs_update) . clone ( ) , channel_id, tx)
2516
2517
}
@@ -2612,10 +2613,9 @@ mod tests {
2612
2613
}
2613
2614
}
2614
2615
2615
- static mut PAYMENT_COUNT : u8 = 0 ;
2616
2616
fn send_along_route ( origin_node : & Node , route : Route , expected_route : & [ & Node ] , recv_value : u64 ) -> ( [ u8 ; 32 ] , [ u8 ; 32 ] ) {
2617
- let our_payment_preimage = unsafe { [ PAYMENT_COUNT ; 32 ] } ;
2618
- unsafe { PAYMENT_COUNT += 1 } ;
2617
+ let our_payment_preimage = [ * origin_node . network_payment_count . borrow ( ) ; 32 ] ;
2618
+ * origin_node . network_payment_count . borrow_mut ( ) += 1 ;
2619
2619
let our_payment_hash = {
2620
2620
let mut sha = Sha256 :: new ( ) ;
2621
2621
sha. input ( & our_payment_preimage[ ..] ) ;
@@ -2807,8 +2807,8 @@ mod tests {
2807
2807
assert_eq ! ( hop. pubkey, node. node. get_our_node_id( ) ) ;
2808
2808
}
2809
2809
2810
- let our_payment_preimage = unsafe { [ PAYMENT_COUNT ; 32 ] } ;
2811
- unsafe { PAYMENT_COUNT += 1 } ;
2810
+ let our_payment_preimage = [ * origin_node . network_payment_count . borrow ( ) ; 32 ] ;
2811
+ * origin_node . network_payment_count . borrow_mut ( ) += 1 ;
2812
2812
let our_payment_hash = {
2813
2813
let mut sha = Sha256 :: new ( ) ;
2814
2814
sha. input ( & our_payment_preimage[ ..] ) ;
@@ -2919,6 +2919,9 @@ mod tests {
2919
2919
let secp_ctx = Secp256k1 :: new ( ) ;
2920
2920
let logger: Arc < Logger > = Arc :: new ( test_utils:: TestLogger :: new ( ) ) ;
2921
2921
2922
+ let chan_count = Rc :: new ( RefCell :: new ( 0 ) ) ;
2923
+ let payment_count = Rc :: new ( RefCell :: new ( 0 ) ) ;
2924
+
2922
2925
for _ in 0 ..node_count {
2923
2926
let feeest = Arc :: new ( test_utils:: TestFeeEstimator { sat_per_kw : 253 } ) ;
2924
2927
let chain_monitor = Arc :: new ( chaininterface:: ChainWatchInterfaceUtil :: new ( Network :: Testnet , Arc :: clone ( & logger) ) ) ;
@@ -2931,7 +2934,10 @@ mod tests {
2931
2934
} ;
2932
2935
let node = ChannelManager :: new ( node_id. clone ( ) , 0 , true , Network :: Testnet , feeest. clone ( ) , chan_monitor. clone ( ) , chain_monitor. clone ( ) , tx_broadcaster. clone ( ) , Arc :: clone ( & logger) ) . unwrap ( ) ;
2933
2936
let router = Router :: new ( PublicKey :: from_secret_key ( & secp_ctx, & node_id) , chain_monitor. clone ( ) , Arc :: clone ( & logger) ) ;
2934
- nodes. push ( Node { chain_monitor, tx_broadcaster, chan_monitor, node, router } ) ;
2937
+ nodes. push ( Node { chain_monitor, tx_broadcaster, chan_monitor, node, router,
2938
+ network_payment_count : payment_count. clone ( ) ,
2939
+ network_chan_count : chan_count. clone ( ) ,
2940
+ } ) ;
2935
2941
}
2936
2942
2937
2943
nodes
0 commit comments