@@ -378,17 +378,35 @@ impl SignerProvider for OnlyReadsKeysInterface {
378
378
}
379
379
}
380
380
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
+
381
399
pub struct TestChainMonitor < ' a > {
382
400
pub added_monitors : Mutex < Vec < ( ChannelId , ChannelMonitor < TestChannelSigner > ) > > ,
383
401
pub monitor_updates : Mutex < HashMap < ChannelId , Vec < ChannelMonitorUpdate > > > ,
384
402
pub latest_monitor_update_id : Mutex < HashMap < ChannelId , ( u64 , u64 ) > > ,
385
403
pub chain_monitor : ChainMonitor <
386
404
TestChannelSigner ,
387
405
& ' a TestChainSource ,
388
- & ' a dyn chaininterface :: BroadcasterInterface ,
406
+ & ' a dyn SyncBroadcaster ,
389
407
& ' a TestFeeEstimator ,
390
408
& ' a TestLogger ,
391
- & ' a dyn Persist < TestChannelSigner > ,
409
+ & ' a dyn SyncPersist ,
392
410
> ,
393
411
pub keys_manager : & ' a TestKeysInterface ,
394
412
/// 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> {
401
419
}
402
420
impl < ' a > TestChainMonitor < ' a > {
403
421
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 ,
408
425
) -> Self {
409
426
Self {
410
427
added_monitors : Mutex :: new ( Vec :: new ( ) ) ,
@@ -1739,19 +1756,17 @@ impl Drop for TestChainSource {
1739
1756
1740
1757
pub struct TestScorer {
1741
1758
/// Stores a tuple of (scid, ChannelUsage)
1742
- scorer_expectations : RefCell < Option < VecDeque < ( u64 , ChannelUsage ) > > > ,
1759
+ scorer_expectations : Mutex < Option < VecDeque < ( u64 , ChannelUsage ) > > > ,
1743
1760
}
1744
1761
1745
1762
impl TestScorer {
1746
1763
pub fn new ( ) -> Self {
1747
- Self { scorer_expectations : RefCell :: new ( None ) }
1764
+ Self { scorer_expectations : Mutex :: new ( None ) }
1748
1765
}
1749
1766
1750
1767
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) ) ;
1755
1770
}
1756
1771
}
1757
1772
@@ -1772,7 +1787,7 @@ impl ScoreLookUp for TestScorer {
1772
1787
Some ( scid) => scid,
1773
1788
None => return 0 ,
1774
1789
} ;
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 ( ) {
1776
1791
match scorer_expectations. pop_front ( ) {
1777
1792
Some ( ( scid, expectation) ) => {
1778
1793
assert_eq ! ( expectation, usage) ;
@@ -1810,7 +1825,7 @@ impl Drop for TestScorer {
1810
1825
return ;
1811
1826
}
1812
1827
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 ( ) {
1814
1829
if !scorer_expectations. is_empty ( ) {
1815
1830
panic ! ( "Unsatisfied scorer expectations: {:?}" , scorer_expectations)
1816
1831
}
0 commit comments