@@ -378,17 +378,35 @@ impl SignerProvider for OnlyReadsKeysInterface {
378378 }
379379}
380380
381+ #[ cfg( feature = "std" ) ]
382+ pub trait SyncBroadcaster : chaininterface:: BroadcasterInterface + Sync { }
383+ #[ cfg( feature = "std" ) ]
384+ pub trait SyncPersist : Persist < TestChannelSigner > + Sync { }
385+ #[ cfg( feature = "std" ) ]
386+ impl < T : chaininterface:: BroadcasterInterface + Sync > SyncBroadcaster for T { }
387+ #[ cfg( feature = "std" ) ]
388+ impl < T : Persist < TestChannelSigner > + Sync > SyncPersist for T { }
389+
390+ #[ cfg( not( feature = "std" ) ) ]
391+ pub trait SyncBroadcaster : chaininterface:: BroadcasterInterface { }
392+ #[ cfg( not( feature = "std" ) ) ]
393+ pub trait SyncPersist : Persist < TestChannelSigner > { }
394+ #[ cfg( not( feature = "std" ) ) ]
395+ impl < T : chaininterface:: BroadcasterInterface > SyncBroadcaster for T { }
396+ #[ cfg( not( feature = "std" ) ) ]
397+ impl < T : Persist < TestChannelSigner > > SyncPersist for T { }
398+
381399pub struct TestChainMonitor < ' a > {
382400 pub added_monitors : Mutex < Vec < ( ChannelId , ChannelMonitor < TestChannelSigner > ) > > ,
383401 pub monitor_updates : Mutex < HashMap < ChannelId , Vec < ChannelMonitorUpdate > > > ,
384402 pub latest_monitor_update_id : Mutex < HashMap < ChannelId , ( u64 , u64 ) > > ,
385403 pub chain_monitor : ChainMonitor <
386404 TestChannelSigner ,
387405 & ' a TestChainSource ,
388- & ' a dyn chaininterface :: BroadcasterInterface ,
406+ & ' a dyn SyncBroadcaster ,
389407 & ' a TestFeeEstimator ,
390408 & ' a TestLogger ,
391- & ' a dyn Persist < TestChannelSigner > ,
409+ & ' a dyn SyncPersist ,
392410 > ,
393411 pub keys_manager : & ' a TestKeysInterface ,
394412 /// If this is set to Some(), the next update_channel call (not watch_channel) must be a
@@ -401,10 +419,9 @@ pub struct TestChainMonitor<'a> {
401419}
402420impl < ' a > TestChainMonitor < ' a > {
403421 pub fn new (
404- chain_source : Option < & ' a TestChainSource > ,
405- broadcaster : & ' a dyn chaininterface:: BroadcasterInterface , logger : & ' a TestLogger ,
406- fee_estimator : & ' a TestFeeEstimator , persister : & ' a dyn Persist < TestChannelSigner > ,
407- keys_manager : & ' a TestKeysInterface ,
422+ chain_source : Option < & ' a TestChainSource > , broadcaster : & ' a dyn SyncBroadcaster ,
423+ logger : & ' a TestLogger , fee_estimator : & ' a TestFeeEstimator ,
424+ persister : & ' a dyn SyncPersist , keys_manager : & ' a TestKeysInterface ,
408425 ) -> Self {
409426 Self {
410427 added_monitors : Mutex :: new ( Vec :: new ( ) ) ,
@@ -1739,19 +1756,17 @@ impl Drop for TestChainSource {
17391756
17401757pub struct TestScorer {
17411758 /// Stores a tuple of (scid, ChannelUsage)
1742- scorer_expectations : RefCell < Option < VecDeque < ( u64 , ChannelUsage ) > > > ,
1759+ scorer_expectations : Mutex < Option < VecDeque < ( u64 , ChannelUsage ) > > > ,
17431760}
17441761
17451762impl TestScorer {
17461763 pub fn new ( ) -> Self {
1747- Self { scorer_expectations : RefCell :: new ( None ) }
1764+ Self { scorer_expectations : Mutex :: new ( None ) }
17481765 }
17491766
17501767 pub fn expect_usage ( & self , scid : u64 , expectation : ChannelUsage ) {
1751- self . scorer_expectations
1752- . borrow_mut ( )
1753- . get_or_insert_with ( || VecDeque :: new ( ) )
1754- . push_back ( ( scid, expectation) ) ;
1768+ let mut expectations = self . scorer_expectations . lock ( ) . unwrap ( ) ;
1769+ expectations. get_or_insert_with ( || VecDeque :: new ( ) ) . push_back ( ( scid, expectation) ) ;
17551770 }
17561771}
17571772
@@ -1772,7 +1787,7 @@ impl ScoreLookUp for TestScorer {
17721787 Some ( scid) => scid,
17731788 None => return 0 ,
17741789 } ;
1775- if let Some ( scorer_expectations) = self . scorer_expectations . borrow_mut ( ) . as_mut ( ) {
1790+ if let Some ( scorer_expectations) = self . scorer_expectations . lock ( ) . unwrap ( ) . as_mut ( ) {
17761791 match scorer_expectations. pop_front ( ) {
17771792 Some ( ( scid, expectation) ) => {
17781793 assert_eq ! ( expectation, usage) ;
@@ -1810,7 +1825,7 @@ impl Drop for TestScorer {
18101825 return ;
18111826 }
18121827
1813- if let Some ( scorer_expectations) = self . scorer_expectations . borrow ( ) . as_ref ( ) {
1828+ if let Some ( scorer_expectations) = self . scorer_expectations . lock ( ) . unwrap ( ) . as_ref ( ) {
18141829 if !scorer_expectations. is_empty ( ) {
18151830 panic ! ( "Unsatisfied scorer expectations: {:?}" , scorer_expectations)
18161831 }
0 commit comments