@@ -335,11 +335,29 @@ impl SignerProvider for OnlyReadsKeysInterface {
335
335
fn get_shutdown_scriptpubkey ( & self ) -> Result < ShutdownScript , ( ) > { Err ( ( ) ) }
336
336
}
337
337
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
+
338
356
pub struct TestChainMonitor < ' a > {
339
357
pub added_monitors : Mutex < Vec < ( OutPoint , channelmonitor:: ChannelMonitor < TestChannelSigner > ) > > ,
340
358
pub monitor_updates : Mutex < HashMap < ChannelId , Vec < channelmonitor:: ChannelMonitorUpdate > > > ,
341
359
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 > ,
343
361
pub keys_manager : & ' a TestKeysInterface ,
344
362
/// If this is set to Some(), the next update_channel call (not watch_channel) must be a
345
363
/// ChannelForceClosed event for the given channel_id with should_broadcast set to the given
@@ -350,7 +368,7 @@ pub struct TestChainMonitor<'a> {
350
368
pub expect_monitor_round_trip_fail : Mutex < Option < ChannelId > > ,
351
369
}
352
370
impl < ' 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 {
354
372
Self {
355
373
added_monitors : Mutex :: new ( Vec :: new ( ) ) ,
356
374
monitor_updates : Mutex :: new ( new_hash_map ( ) ) ,
@@ -1448,18 +1466,19 @@ impl Drop for TestChainSource {
1448
1466
1449
1467
pub struct TestScorer {
1450
1468
/// Stores a tuple of (scid, ChannelUsage)
1451
- scorer_expectations : RefCell < Option < VecDeque < ( u64 , ChannelUsage ) > > > ,
1469
+ scorer_expectations : Mutex < Option < VecDeque < ( u64 , ChannelUsage ) > > > ,
1452
1470
}
1453
1471
1454
1472
impl TestScorer {
1455
1473
pub fn new ( ) -> Self {
1456
1474
Self {
1457
- scorer_expectations : RefCell :: new ( None ) ,
1475
+ scorer_expectations : Mutex :: new ( None ) ,
1458
1476
}
1459
1477
}
1460
1478
1461
1479
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) ) ;
1463
1482
}
1464
1483
}
1465
1484
@@ -1477,7 +1496,7 @@ impl ScoreLookUp for TestScorer {
1477
1496
Some ( scid) => scid,
1478
1497
None => return 0 ,
1479
1498
} ;
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 ( ) {
1481
1500
match scorer_expectations. pop_front ( ) {
1482
1501
Some ( ( scid, expectation) ) => {
1483
1502
assert_eq ! ( expectation, usage) ;
@@ -1511,7 +1530,7 @@ impl Drop for TestScorer {
1511
1530
return ;
1512
1531
}
1513
1532
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 ( ) {
1515
1534
if !scorer_expectations. is_empty ( ) {
1516
1535
panic ! ( "Unsatisfied scorer expectations: {:?}" , scorer_expectations)
1517
1536
}
0 commit comments