@@ -15,9 +15,10 @@ use crate::chain::chaininterface;
15
15
use crate :: chain:: chaininterface:: ConfirmationTarget ;
16
16
#[ cfg( test) ]
17
17
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
+ } ;
21
22
use crate :: chain:: transaction:: OutPoint ;
22
23
use crate :: chain:: WatchedOutput ;
23
24
use crate :: events;
@@ -386,16 +387,16 @@ impl SignerProvider for OnlyReadsKeysInterface {
386
387
}
387
388
388
389
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 > > > ,
391
392
pub latest_monitor_update_id : Mutex < HashMap < ChannelId , ( OutPoint , u64 , u64 ) > > ,
392
- pub chain_monitor : chainmonitor :: ChainMonitor <
393
+ pub chain_monitor : ChainMonitor <
393
394
TestChannelSigner ,
394
395
& ' a TestChainSource ,
395
396
& ' a dyn chaininterface:: BroadcasterInterface ,
396
397
& ' a TestFeeEstimator ,
397
398
& ' a TestLogger ,
398
- & ' a dyn chainmonitor :: Persist < TestChannelSigner > ,
399
+ & ' a dyn Persist < TestChannelSigner > ,
399
400
> ,
400
401
pub keys_manager : & ' a TestKeysInterface ,
401
402
/// 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> {
410
411
pub fn new (
411
412
chain_source : Option < & ' a TestChainSource > ,
412
413
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 > ,
415
415
keys_manager : & ' a TestKeysInterface ,
416
416
) -> Self {
417
417
let added_monitors = Mutex :: new ( Vec :: new ( ) ) ;
@@ -423,7 +423,7 @@ impl<'a> TestChainMonitor<'a> {
423
423
added_monitors,
424
424
monitor_updates,
425
425
latest_monitor_update_id,
426
- chain_monitor : chainmonitor :: ChainMonitor :: new (
426
+ chain_monitor : ChainMonitor :: new (
427
427
chain_source,
428
428
broadcaster,
429
429
logger,
@@ -444,13 +444,13 @@ impl<'a> TestChainMonitor<'a> {
444
444
}
445
445
impl < ' a > chain:: Watch < TestChannelSigner > for TestChainMonitor < ' a > {
446
446
fn watch_channel (
447
- & self , funding_txo : OutPoint , monitor : channelmonitor :: ChannelMonitor < TestChannelSigner > ,
447
+ & self , funding_txo : OutPoint , monitor : ChannelMonitor < TestChannelSigner > ,
448
448
) -> Result < chain:: ChannelMonitorUpdateStatus , ( ) > {
449
449
// At every point where we get a monitor update, we should be able to send a useful monitor
450
450
// to a watchtower and disk...
451
451
let mut w = TestVecWriter ( Vec :: new ( ) ) ;
452
452
monitor. write ( & mut w) . unwrap ( ) ;
453
- let new_monitor = <( BlockHash , channelmonitor :: ChannelMonitor < TestChannelSigner > ) >:: read (
453
+ let new_monitor = <( BlockHash , ChannelMonitor < TestChannelSigner > ) >:: read (
454
454
& mut io:: Cursor :: new ( & w. 0 ) ,
455
455
( self . keys_manager , self . keys_manager ) ,
456
456
)
@@ -466,15 +466,12 @@ impl<'a> chain::Watch<TestChannelSigner> for TestChainMonitor<'a> {
466
466
}
467
467
468
468
fn update_channel (
469
- & self , funding_txo : OutPoint , update : & channelmonitor :: ChannelMonitorUpdate ,
469
+ & self , funding_txo : OutPoint , update : & ChannelMonitorUpdate ,
470
470
) -> chain:: ChannelMonitorUpdateStatus {
471
471
// Every monitor update should survive roundtrip
472
472
let mut w = TestVecWriter ( Vec :: new ( ) ) ;
473
473
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) ;
478
475
let channel_id =
479
476
update. channel_id . unwrap_or ( ChannelId :: v1_from_funding_outpoint ( funding_txo) ) ;
480
477
@@ -488,11 +485,9 @@ impl<'a> chain::Watch<TestChannelSigner> for TestChainMonitor<'a> {
488
485
if let Some ( exp) = self . expect_channel_force_closed . lock ( ) . unwrap ( ) . take ( ) {
489
486
assert_eq ! ( channel_id, exp. 0 ) ;
490
487
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 ) ;
496
491
} else {
497
492
panic ! ( ) ;
498
493
}
@@ -508,7 +503,7 @@ impl<'a> chain::Watch<TestChannelSigner> for TestChainMonitor<'a> {
508
503
let monitor = self . chain_monitor . get_monitor ( funding_txo) . unwrap ( ) ;
509
504
w. 0 . clear ( ) ;
510
505
monitor. write ( & mut w) . unwrap ( ) ;
511
- let new_monitor = <( BlockHash , channelmonitor :: ChannelMonitor < TestChannelSigner > ) >:: read (
506
+ let new_monitor = <( BlockHash , ChannelMonitor < TestChannelSigner > ) >:: read (
512
507
& mut io:: Cursor :: new ( & w. 0 ) ,
513
508
( self . keys_manager , self . keys_manager ) ,
514
509
)
@@ -598,11 +593,9 @@ impl WatchtowerPersister {
598
593
}
599
594
600
595
#[ 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 {
604
597
fn persist_new_channel (
605
- & self , funding_txo : OutPoint , data : & channelmonitor :: ChannelMonitor < Signer > ,
598
+ & self , funding_txo : OutPoint , data : & ChannelMonitor < Signer > ,
606
599
) -> chain:: ChannelMonitorUpdateStatus {
607
600
let res = self . persister . persist_new_channel ( funding_txo, data) ;
608
601
@@ -635,8 +628,8 @@ impl<Signer: sign::ecdsa::EcdsaChannelSigner> chainmonitor::Persist<Signer>
635
628
}
636
629
637
630
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 > ,
640
633
) -> chain:: ChannelMonitorUpdateStatus {
641
634
let res = self . persister . update_persisted_channel ( funding_txo, update, data) ;
642
635
@@ -679,7 +672,7 @@ impl<Signer: sign::ecdsa::EcdsaChannelSigner> chainmonitor::Persist<Signer>
679
672
}
680
673
681
674
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 (
683
676
& self . persister ,
684
677
funding_txo,
685
678
) ;
@@ -692,8 +685,6 @@ pub struct TestPersister {
692
685
pub update_rets : Mutex < VecDeque < chain:: ChannelMonitorUpdateStatus > > ,
693
686
/// When we get an update_persisted_channel call *with* a ChannelMonitorUpdate, we insert the
694
687
/// [`ChannelMonitor::get_latest_update_id`] here.
695
- ///
696
- /// [`ChannelMonitor`]: channelmonitor::ChannelMonitor
697
688
pub offchain_monitor_updates : Mutex < HashMap < OutPoint , HashSet < u64 > > > ,
698
689
/// When we get an update_persisted_channel call with no ChannelMonitorUpdate, we insert the
699
690
/// monitor's funding outpoint here.
@@ -712,9 +703,9 @@ impl TestPersister {
712
703
self . update_rets . lock ( ) . unwrap ( ) . push_back ( next_ret) ;
713
704
}
714
705
}
715
- impl < Signer : sign:: ecdsa:: EcdsaChannelSigner > chainmonitor :: Persist < Signer > for TestPersister {
706
+ impl < Signer : sign:: ecdsa:: EcdsaChannelSigner > Persist < Signer > for TestPersister {
716
707
fn persist_new_channel (
717
- & self , _funding_txo : OutPoint , _data : & channelmonitor :: ChannelMonitor < Signer > ,
708
+ & self , _funding_txo : OutPoint , _data : & ChannelMonitor < Signer > ,
718
709
) -> chain:: ChannelMonitorUpdateStatus {
719
710
if let Some ( update_ret) = self . update_rets . lock ( ) . unwrap ( ) . pop_front ( ) {
720
711
return update_ret;
@@ -723,8 +714,8 @@ impl<Signer: sign::ecdsa::EcdsaChannelSigner> chainmonitor::Persist<Signer> for
723
714
}
724
715
725
716
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 > ,
728
719
) -> chain:: ChannelMonitorUpdateStatus {
729
720
let mut ret = chain:: ChannelMonitorUpdateStatus :: Completed ;
730
721
if let Some ( update_ret) = self . update_rets . lock ( ) . unwrap ( ) . pop_front ( ) {
0 commit comments