Skip to content

Commit ee7acca

Browse files
committed
Make TestChannelManager Sync
In a coming commit we'll need to hold references to `TestChannelManager` in threads, requiring that it be `Sync`.
1 parent 1fc2726 commit ee7acca

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

lightning-persister/src/test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ pub(crate) fn do_test_data_migration<S: MigratableKVStore, T: MigratableKVStore>
113113

114114
// Integration-test the given KVStore implementation. Test relaying a few payments and check that
115115
// the persisted data is updated the appropriate number of times.
116-
pub(crate) fn do_test_store<K: KVStore>(store_0: &K, store_1: &K) {
116+
pub(crate) fn do_test_store<K: KVStore + Sync>(store_0: &K, store_1: &K) {
117117
let chanmon_cfgs = create_chanmon_cfgs(2);
118118
let mut node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
119119
let chain_mon_0 = test_utils::TestChainMonitor::new(

lightning/src/ln/functional_test_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ pub struct NodeCfg<'a> {
398398
pub override_init_features: Rc<RefCell<Option<InitFeatures>>>,
399399
}
400400

401-
type TestChannelManager<'node_cfg, 'chan_mon_cfg> = ChannelManager<
401+
pub(crate) type TestChannelManager<'node_cfg, 'chan_mon_cfg> = ChannelManager<
402402
&'node_cfg TestChainMonitor<'chan_mon_cfg>,
403403
&'chan_mon_cfg test_utils::TestBroadcaster,
404404
&'node_cfg test_utils::TestKeysInterface,
@@ -3286,7 +3286,7 @@ pub fn create_node_cfgs<'a>(node_count: usize, chanmon_cfgs: &'a Vec<TestChanMon
32863286
create_node_cfgs_with_persisters(node_count, chanmon_cfgs, chanmon_cfgs.iter().map(|c| &c.persister).collect())
32873287
}
32883288

3289-
pub fn create_node_cfgs_with_persisters<'a>(node_count: usize, chanmon_cfgs: &'a Vec<TestChanMonCfg>, persisters: Vec<&'a impl Persist<TestChannelSigner>>) -> Vec<NodeCfg<'a>> {
3289+
pub fn create_node_cfgs_with_persisters<'a>(node_count: usize, chanmon_cfgs: &'a Vec<TestChanMonCfg>, persisters: Vec<&'a (impl Persist<TestChannelSigner> + Sync)>) -> Vec<NodeCfg<'a>> {
32903290
let mut nodes = Vec::new();
32913291

32923292
for i in 0..node_count {

lightning/src/util/test_utils.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,10 @@ pub struct TestChainMonitor<'a> {
385385
pub chain_monitor: ChainMonitor<
386386
TestChannelSigner,
387387
&'a TestChainSource,
388-
&'a dyn chaininterface::BroadcasterInterface,
388+
&'a (dyn chaininterface::BroadcasterInterface + Sync),
389389
&'a TestFeeEstimator,
390390
&'a TestLogger,
391-
&'a dyn Persist<TestChannelSigner>,
391+
&'a (dyn Persist<TestChannelSigner> + Sync),
392392
>,
393393
pub keys_manager: &'a TestKeysInterface,
394394
/// If this is set to Some(), the next update_channel call (not watch_channel) must be a
@@ -402,8 +402,8 @@ pub struct TestChainMonitor<'a> {
402402
impl<'a> TestChainMonitor<'a> {
403403
pub fn new(
404404
chain_source: Option<&'a TestChainSource>,
405-
broadcaster: &'a dyn chaininterface::BroadcasterInterface, logger: &'a TestLogger,
406-
fee_estimator: &'a TestFeeEstimator, persister: &'a dyn Persist<TestChannelSigner>,
405+
broadcaster: &'a (dyn chaininterface::BroadcasterInterface + Sync), logger: &'a TestLogger,
406+
fee_estimator: &'a TestFeeEstimator, persister: &'a (dyn Persist<TestChannelSigner> + Sync),
407407
keys_manager: &'a TestKeysInterface,
408408
) -> Self {
409409
Self {
@@ -1739,19 +1739,17 @@ impl Drop for TestChainSource {
17391739

17401740
pub struct TestScorer {
17411741
/// Stores a tuple of (scid, ChannelUsage)
1742-
scorer_expectations: RefCell<Option<VecDeque<(u64, ChannelUsage)>>>,
1742+
scorer_expectations: Mutex<Option<VecDeque<(u64, ChannelUsage)>>>,
17431743
}
17441744

17451745
impl TestScorer {
17461746
pub fn new() -> Self {
1747-
Self { scorer_expectations: RefCell::new(None) }
1747+
Self { scorer_expectations: Mutex::new(None) }
17481748
}
17491749

17501750
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));
1751+
let mut expectations = self.scorer_expectations.lock().unwrap();
1752+
expectations.get_or_insert_with(|| VecDeque::new()).push_back((scid, expectation));
17551753
}
17561754
}
17571755

@@ -1772,7 +1770,7 @@ impl ScoreLookUp for TestScorer {
17721770
Some(scid) => scid,
17731771
None => return 0,
17741772
};
1775-
if let Some(scorer_expectations) = self.scorer_expectations.borrow_mut().as_mut() {
1773+
if let Some(scorer_expectations) = self.scorer_expectations.lock().unwrap().as_mut() {
17761774
match scorer_expectations.pop_front() {
17771775
Some((scid, expectation)) => {
17781776
assert_eq!(expectation, usage);
@@ -1810,7 +1808,7 @@ impl Drop for TestScorer {
18101808
return;
18111809
}
18121810

1813-
if let Some(scorer_expectations) = self.scorer_expectations.borrow().as_ref() {
1811+
if let Some(scorer_expectations) = self.scorer_expectations.lock().unwrap().as_ref() {
18141812
if !scorer_expectations.is_empty() {
18151813
panic!("Unsatisfied scorer expectations: {:?}", scorer_expectations)
18161814
}

0 commit comments

Comments
 (0)