Skip to content

Commit 8e9ad55

Browse files
committed
Import types we use in test_utils
`test_utils` is ancient and didn't import common types like `ChannelMonitor` for some reason. Here we do that, cleaning up some code.
1 parent 86308e1 commit 8e9ad55

File tree

1 file changed

+27
-36
lines changed

1 file changed

+27
-36
lines changed

lightning/src/util/test_utils.rs

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ use crate::chain::chaininterface;
1515
use crate::chain::chaininterface::ConfirmationTarget;
1616
#[cfg(test)]
1717
use crate::chain::chaininterface::FEERATE_FLOOR_SATS_PER_KW;
18-
use crate::chain::chainmonitor;
19-
use crate::chain::channelmonitor;
20-
use crate::chain::channelmonitor::MonitorEvent;
18+
use crate::chain::chainmonitor::{ChainMonitor, Persist};
19+
use crate::chain::channelmonitor::{
20+
ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateStep, MonitorEvent,
21+
};
2122
use crate::chain::transaction::OutPoint;
2223
use crate::chain::WatchedOutput;
2324
use crate::events;
@@ -386,16 +387,16 @@ impl SignerProvider for OnlyReadsKeysInterface {
386387
}
387388

388389
pub struct TestChainMonitor<'a> {
389-
pub added_monitors: Mutex<Vec<(OutPoint, channelmonitor::ChannelMonitor<TestChannelSigner>)>>,
390-
pub monitor_updates: Mutex<HashMap<ChannelId, Vec<channelmonitor::ChannelMonitorUpdate>>>,
390+
pub added_monitors: Mutex<Vec<(OutPoint, ChannelMonitor<TestChannelSigner>)>>,
391+
pub monitor_updates: Mutex<HashMap<ChannelId, Vec<ChannelMonitorUpdate>>>,
391392
pub latest_monitor_update_id: Mutex<HashMap<ChannelId, (OutPoint, u64, u64)>>,
392-
pub chain_monitor: chainmonitor::ChainMonitor<
393+
pub chain_monitor: ChainMonitor<
393394
TestChannelSigner,
394395
&'a TestChainSource,
395396
&'a dyn chaininterface::BroadcasterInterface,
396397
&'a TestFeeEstimator,
397398
&'a TestLogger,
398-
&'a dyn chainmonitor::Persist<TestChannelSigner>,
399+
&'a dyn Persist<TestChannelSigner>,
399400
>,
400401
pub keys_manager: &'a TestKeysInterface,
401402
/// If this is set to Some(), the next update_channel call (not watch_channel) must be a
@@ -410,8 +411,7 @@ impl<'a> TestChainMonitor<'a> {
410411
pub fn new(
411412
chain_source: Option<&'a TestChainSource>,
412413
broadcaster: &'a dyn chaininterface::BroadcasterInterface, logger: &'a TestLogger,
413-
fee_estimator: &'a TestFeeEstimator,
414-
persister: &'a dyn chainmonitor::Persist<TestChannelSigner>,
414+
fee_estimator: &'a TestFeeEstimator, persister: &'a dyn Persist<TestChannelSigner>,
415415
keys_manager: &'a TestKeysInterface,
416416
) -> Self {
417417
let added_monitors = Mutex::new(Vec::new());
@@ -423,7 +423,7 @@ impl<'a> TestChainMonitor<'a> {
423423
added_monitors,
424424
monitor_updates,
425425
latest_monitor_update_id,
426-
chain_monitor: chainmonitor::ChainMonitor::new(
426+
chain_monitor: ChainMonitor::new(
427427
chain_source,
428428
broadcaster,
429429
logger,
@@ -444,13 +444,13 @@ impl<'a> TestChainMonitor<'a> {
444444
}
445445
impl<'a> chain::Watch<TestChannelSigner> for TestChainMonitor<'a> {
446446
fn watch_channel(
447-
&self, funding_txo: OutPoint, monitor: channelmonitor::ChannelMonitor<TestChannelSigner>,
447+
&self, funding_txo: OutPoint, monitor: ChannelMonitor<TestChannelSigner>,
448448
) -> Result<chain::ChannelMonitorUpdateStatus, ()> {
449449
// At every point where we get a monitor update, we should be able to send a useful monitor
450450
// to a watchtower and disk...
451451
let mut w = TestVecWriter(Vec::new());
452452
monitor.write(&mut w).unwrap();
453-
let new_monitor = <(BlockHash, channelmonitor::ChannelMonitor<TestChannelSigner>)>::read(
453+
let new_monitor = <(BlockHash, ChannelMonitor<TestChannelSigner>)>::read(
454454
&mut io::Cursor::new(&w.0),
455455
(self.keys_manager, self.keys_manager),
456456
)
@@ -466,15 +466,12 @@ impl<'a> chain::Watch<TestChannelSigner> for TestChainMonitor<'a> {
466466
}
467467

468468
fn update_channel(
469-
&self, funding_txo: OutPoint, update: &channelmonitor::ChannelMonitorUpdate,
469+
&self, funding_txo: OutPoint, update: &ChannelMonitorUpdate,
470470
) -> chain::ChannelMonitorUpdateStatus {
471471
// Every monitor update should survive roundtrip
472472
let mut w = TestVecWriter(Vec::new());
473473
update.write(&mut w).unwrap();
474-
assert!(
475-
channelmonitor::ChannelMonitorUpdate::read(&mut io::Cursor::new(&w.0)).unwrap()
476-
== *update
477-
);
474+
assert_eq!(ChannelMonitorUpdate::read(&mut &w.0[..]).unwrap(), *update);
478475
let channel_id =
479476
update.channel_id.unwrap_or(ChannelId::v1_from_funding_outpoint(funding_txo));
480477

@@ -488,11 +485,9 @@ impl<'a> chain::Watch<TestChannelSigner> for TestChainMonitor<'a> {
488485
if let Some(exp) = self.expect_channel_force_closed.lock().unwrap().take() {
489486
assert_eq!(channel_id, exp.0);
490487
assert_eq!(update.updates.len(), 1);
491-
if let channelmonitor::ChannelMonitorUpdateStep::ChannelForceClosed {
492-
should_broadcast,
493-
} = update.updates[0]
494-
{
495-
assert_eq!(should_broadcast, exp.1);
488+
let update = &update.updates[0];
489+
if let ChannelMonitorUpdateStep::ChannelForceClosed { should_broadcast } = update {
490+
assert_eq!(*should_broadcast, exp.1);
496491
} else {
497492
panic!();
498493
}
@@ -508,7 +503,7 @@ impl<'a> chain::Watch<TestChannelSigner> for TestChainMonitor<'a> {
508503
let monitor = self.chain_monitor.get_monitor(funding_txo).unwrap();
509504
w.0.clear();
510505
monitor.write(&mut w).unwrap();
511-
let new_monitor = <(BlockHash, channelmonitor::ChannelMonitor<TestChannelSigner>)>::read(
506+
let new_monitor = <(BlockHash, ChannelMonitor<TestChannelSigner>)>::read(
512507
&mut io::Cursor::new(&w.0),
513508
(self.keys_manager, self.keys_manager),
514509
)
@@ -598,11 +593,9 @@ impl WatchtowerPersister {
598593
}
599594

600595
#[cfg(test)]
601-
impl<Signer: sign::ecdsa::EcdsaChannelSigner> chainmonitor::Persist<Signer>
602-
for WatchtowerPersister
603-
{
596+
impl<Signer: sign::ecdsa::EcdsaChannelSigner> Persist<Signer> for WatchtowerPersister {
604597
fn persist_new_channel(
605-
&self, funding_txo: OutPoint, data: &channelmonitor::ChannelMonitor<Signer>,
598+
&self, funding_txo: OutPoint, data: &ChannelMonitor<Signer>,
606599
) -> chain::ChannelMonitorUpdateStatus {
607600
let res = self.persister.persist_new_channel(funding_txo, data);
608601

@@ -635,8 +628,8 @@ impl<Signer: sign::ecdsa::EcdsaChannelSigner> chainmonitor::Persist<Signer>
635628
}
636629

637630
fn update_persisted_channel(
638-
&self, funding_txo: OutPoint, update: Option<&channelmonitor::ChannelMonitorUpdate>,
639-
data: &channelmonitor::ChannelMonitor<Signer>,
631+
&self, funding_txo: OutPoint, update: Option<&ChannelMonitorUpdate>,
632+
data: &ChannelMonitor<Signer>,
640633
) -> chain::ChannelMonitorUpdateStatus {
641634
let res = self.persister.update_persisted_channel(funding_txo, update, data);
642635

@@ -679,7 +672,7 @@ impl<Signer: sign::ecdsa::EcdsaChannelSigner> chainmonitor::Persist<Signer>
679672
}
680673

681674
fn archive_persisted_channel(&self, funding_txo: OutPoint) {
682-
<TestPersister as chainmonitor::Persist<TestChannelSigner>>::archive_persisted_channel(
675+
<TestPersister as Persist<TestChannelSigner>>::archive_persisted_channel(
683676
&self.persister,
684677
funding_txo,
685678
);
@@ -692,8 +685,6 @@ pub struct TestPersister {
692685
pub update_rets: Mutex<VecDeque<chain::ChannelMonitorUpdateStatus>>,
693686
/// When we get an update_persisted_channel call *with* a ChannelMonitorUpdate, we insert the
694687
/// [`ChannelMonitor::get_latest_update_id`] here.
695-
///
696-
/// [`ChannelMonitor`]: channelmonitor::ChannelMonitor
697688
pub offchain_monitor_updates: Mutex<HashMap<OutPoint, HashSet<u64>>>,
698689
/// When we get an update_persisted_channel call with no ChannelMonitorUpdate, we insert the
699690
/// monitor's funding outpoint here.
@@ -712,9 +703,9 @@ impl TestPersister {
712703
self.update_rets.lock().unwrap().push_back(next_ret);
713704
}
714705
}
715-
impl<Signer: sign::ecdsa::EcdsaChannelSigner> chainmonitor::Persist<Signer> for TestPersister {
706+
impl<Signer: sign::ecdsa::EcdsaChannelSigner> Persist<Signer> for TestPersister {
716707
fn persist_new_channel(
717-
&self, _funding_txo: OutPoint, _data: &channelmonitor::ChannelMonitor<Signer>,
708+
&self, _funding_txo: OutPoint, _data: &ChannelMonitor<Signer>,
718709
) -> chain::ChannelMonitorUpdateStatus {
719710
if let Some(update_ret) = self.update_rets.lock().unwrap().pop_front() {
720711
return update_ret;
@@ -723,8 +714,8 @@ impl<Signer: sign::ecdsa::EcdsaChannelSigner> chainmonitor::Persist<Signer> for
723714
}
724715

725716
fn update_persisted_channel(
726-
&self, funding_txo: OutPoint, update: Option<&channelmonitor::ChannelMonitorUpdate>,
727-
_data: &channelmonitor::ChannelMonitor<Signer>,
717+
&self, funding_txo: OutPoint, update: Option<&ChannelMonitorUpdate>,
718+
_data: &ChannelMonitor<Signer>,
728719
) -> chain::ChannelMonitorUpdateStatus {
729720
let mut ret = chain::ChannelMonitorUpdateStatus::Completed;
730721
if let Some(update_ret) = self.update_rets.lock().unwrap().pop_front() {

0 commit comments

Comments
 (0)