@@ -335,11 +335,29 @@ impl SignerProvider for OnlyReadsKeysInterface {
335335 fn get_shutdown_scriptpubkey ( & self ) -> Result < ShutdownScript , ( ) > { Err ( ( ) ) }
336336}
337337
338+ #[ cfg( feature = "std" ) ]
339+ pub trait SyncBroadcaster : chaininterface:: BroadcasterInterface + Sync { }
340+ #[ cfg( feature = "std" ) ]
341+ pub trait SyncPersist : chainmonitor:: Persist < TestChannelSigner > + Sync { }
342+ #[ cfg( feature = "std" ) ]
343+ impl < T : chaininterface:: BroadcasterInterface + Sync > SyncBroadcaster for T { }
344+ #[ cfg( feature = "std" ) ]
345+ impl < T : chainmonitor:: Persist < TestChannelSigner > + Sync > SyncPersist for T { }
346+
347+ #[ cfg( not( feature = "std" ) ) ]
348+ pub trait SyncBroadcaster : chaininterface:: BroadcasterInterface { }
349+ #[ cfg( not( feature = "std" ) ) ]
350+ pub trait SyncPersist : chainmonitor:: Persist < TestChannelSigner > { }
351+ #[ cfg( not( feature = "std" ) ) ]
352+ impl < T : chaininterface:: BroadcasterInterface > SyncBroadcaster for T { }
353+ #[ cfg( not( feature = "std" ) ) ]
354+ impl < T : chainmonitor:: Persist < TestChannelSigner > > SyncPersist for T { }
355+
338356pub struct TestChainMonitor < ' a > {
339357 pub added_monitors : Mutex < Vec < ( OutPoint , channelmonitor:: ChannelMonitor < TestChannelSigner > ) > > ,
340358 pub monitor_updates : Mutex < HashMap < ChannelId , Vec < channelmonitor:: ChannelMonitorUpdate > > > ,
341359 pub latest_monitor_update_id : Mutex < HashMap < ChannelId , ( OutPoint , u64 , u64 ) > > ,
342- pub chain_monitor : chainmonitor:: ChainMonitor < TestChannelSigner , & ' a TestChainSource , & ' a dyn chaininterface :: BroadcasterInterface , & ' a TestFeeEstimator , & ' a TestLogger , & ' a dyn chainmonitor :: Persist < TestChannelSigner > > ,
360+ pub chain_monitor : chainmonitor:: ChainMonitor < TestChannelSigner , & ' a TestChainSource , & ' a dyn SyncBroadcaster , & ' a TestFeeEstimator , & ' a TestLogger , & ' a dyn SyncPersist > ,
343361 pub keys_manager : & ' a TestKeysInterface ,
344362 /// If this is set to Some(), the next update_channel call (not watch_channel) must be a
345363 /// ChannelForceClosed event for the given channel_id with should_broadcast set to the given
@@ -350,7 +368,7 @@ pub struct TestChainMonitor<'a> {
350368 pub expect_monitor_round_trip_fail : Mutex < Option < ChannelId > > ,
351369}
352370impl < ' a > TestChainMonitor < ' a > {
353- pub fn new ( chain_source : Option < & ' a TestChainSource > , broadcaster : & ' a dyn chaininterface :: BroadcasterInterface , logger : & ' a TestLogger , fee_estimator : & ' a TestFeeEstimator , persister : & ' a dyn chainmonitor :: Persist < TestChannelSigner > , keys_manager : & ' a TestKeysInterface ) -> Self {
371+ pub fn new ( chain_source : Option < & ' a TestChainSource > , broadcaster : & ' a dyn SyncBroadcaster , logger : & ' a TestLogger , fee_estimator : & ' a TestFeeEstimator , persister : & ' a dyn SyncPersist , keys_manager : & ' a TestKeysInterface ) -> Self {
354372 Self {
355373 added_monitors : Mutex :: new ( Vec :: new ( ) ) ,
356374 monitor_updates : Mutex :: new ( new_hash_map ( ) ) ,
@@ -1448,18 +1466,19 @@ impl Drop for TestChainSource {
14481466
14491467pub struct TestScorer {
14501468 /// Stores a tuple of (scid, ChannelUsage)
1451- scorer_expectations : RefCell < Option < VecDeque < ( u64 , ChannelUsage ) > > > ,
1469+ scorer_expectations : Mutex < Option < VecDeque < ( u64 , ChannelUsage ) > > > ,
14521470}
14531471
14541472impl TestScorer {
14551473 pub fn new ( ) -> Self {
14561474 Self {
1457- scorer_expectations : RefCell :: new ( None ) ,
1475+ scorer_expectations : Mutex :: new ( None ) ,
14581476 }
14591477 }
14601478
14611479 pub fn expect_usage ( & self , scid : u64 , expectation : ChannelUsage ) {
1462- self . scorer_expectations . borrow_mut ( ) . get_or_insert_with ( || VecDeque :: new ( ) ) . push_back ( ( scid, expectation) ) ;
1480+ let mut expectations = self . scorer_expectations . lock ( ) . unwrap ( ) ;
1481+ expectations. get_or_insert_with ( || VecDeque :: new ( ) ) . push_back ( ( scid, expectation) ) ;
14631482 }
14641483}
14651484
@@ -1477,7 +1496,7 @@ impl ScoreLookUp for TestScorer {
14771496 Some ( scid) => scid,
14781497 None => return 0 ,
14791498 } ;
1480- if let Some ( scorer_expectations) = self . scorer_expectations . borrow_mut ( ) . as_mut ( ) {
1499+ if let Some ( scorer_expectations) = self . scorer_expectations . lock ( ) . unwrap ( ) . as_mut ( ) {
14811500 match scorer_expectations. pop_front ( ) {
14821501 Some ( ( scid, expectation) ) => {
14831502 assert_eq ! ( expectation, usage) ;
@@ -1511,7 +1530,7 @@ impl Drop for TestScorer {
15111530 return ;
15121531 }
15131532
1514- if let Some ( scorer_expectations) = self . scorer_expectations . borrow ( ) . as_ref ( ) {
1533+ if let Some ( scorer_expectations) = self . scorer_expectations . lock ( ) . unwrap ( ) . as_ref ( ) {
15151534 if !scorer_expectations. is_empty ( ) {
15161535 panic ! ( "Unsatisfied scorer expectations: {:?}" , scorer_expectations)
15171536 }
0 commit comments