@@ -342,7 +342,7 @@ where
342342 L :: Target : Logger ,
343343 O :: Target : OutputSpender ,
344344{
345- sweeper_state : Mutex < SweeperState > ,
345+ sweeper_state : Mutex < RuntimeSweeperState > ,
346346 broadcaster : B ,
347347 fee_estimator : E ,
348348 chain_data_source : Option < F > ,
@@ -372,7 +372,8 @@ where
372372 output_spender : O , change_destination_source : D , kv_store : K , logger : L ,
373373 ) -> Self {
374374 let outputs = Vec :: new ( ) ;
375- let sweeper_state = Mutex :: new ( SweeperState { outputs, best_block } ) ;
375+ let sweeper_state =
376+ Mutex :: new ( RuntimeSweeperState { persistent : SweeperState { outputs, best_block } } ) ;
376377 Self {
377378 sweeper_state,
378379 broadcaster,
@@ -416,7 +417,7 @@ where
416417 return Ok ( ( ) ) ;
417418 }
418419
419- let mut state_lock = self . sweeper_state . lock ( ) . unwrap ( ) ;
420+ let state_lock = & mut self . sweeper_state . lock ( ) . unwrap ( ) . persistent ;
420421 for descriptor in relevant_descriptors {
421422 let output_info = TrackedSpendableOutput {
422423 descriptor,
@@ -433,25 +434,25 @@ where
433434
434435 state_lock. outputs . push ( output_info) ;
435436 }
436- self . persist_state ( & * state_lock) . map_err ( |e| {
437+ self . persist_state ( & state_lock) . map_err ( |e| {
437438 log_error ! ( self . logger, "Error persisting OutputSweeper: {:?}" , e) ;
438439 } )
439440 }
440441
441442 /// Returns a list of the currently tracked spendable outputs.
442443 pub fn tracked_spendable_outputs ( & self ) -> Vec < TrackedSpendableOutput > {
443- self . sweeper_state . lock ( ) . unwrap ( ) . outputs . clone ( )
444+ self . sweeper_state . lock ( ) . unwrap ( ) . persistent . outputs . clone ( )
444445 }
445446
446447 /// Gets the latest best block which was connected either via the [`Listen`] or
447448 /// [`Confirm`] interfaces.
448449 pub fn current_best_block ( & self ) -> BestBlock {
449- self . sweeper_state . lock ( ) . unwrap ( ) . best_block
450+ self . sweeper_state . lock ( ) . unwrap ( ) . persistent . best_block
450451 }
451452
452453 /// Regenerates and broadcasts the spending transaction for any outputs that are pending
453454 pub fn regenerate_and_broadcast_spend_if_necessary ( & self ) -> Result < ( ) , ( ) > {
454- let mut sweeper_state = self . sweeper_state . lock ( ) . unwrap ( ) ;
455+ let sweeper_state = & mut self . sweeper_state . lock ( ) . unwrap ( ) . persistent ;
455456
456457 let cur_height = sweeper_state. best_block . height ;
457458 let cur_hash = sweeper_state. best_block . block_hash ;
@@ -614,22 +615,22 @@ where
614615 fn filtered_block_connected (
615616 & self , header : & Header , txdata : & chain:: transaction:: TransactionData , height : u32 ,
616617 ) {
617- let mut state_lock = self . sweeper_state . lock ( ) . unwrap ( ) ;
618+ let state_lock = & mut self . sweeper_state . lock ( ) . unwrap ( ) . persistent ;
618619 assert_eq ! ( state_lock. best_block. block_hash, header. prev_blockhash,
619620 "Blocks must be connected in chain-order - the connected header must build on the last connected header" ) ;
620621 assert_eq ! ( state_lock. best_block. height, height - 1 ,
621622 "Blocks must be connected in chain-order - the connected block height must be one greater than the previous height" ) ;
622623
623- self . transactions_confirmed_internal ( & mut * state_lock, header, txdata, height) ;
624- self . best_block_updated_internal ( & mut * state_lock, header, height) ;
624+ self . transactions_confirmed_internal ( state_lock, header, txdata, height) ;
625+ self . best_block_updated_internal ( state_lock, header, height) ;
625626
626- let _ = self . persist_state ( & * state_lock) . map_err ( |e| {
627+ let _ = self . persist_state ( & state_lock) . map_err ( |e| {
627628 log_error ! ( self . logger, "Error persisting OutputSweeper: {:?}" , e) ;
628629 } ) ;
629630 }
630631
631632 fn block_disconnected ( & self , header : & Header , height : u32 ) {
632- let mut state_lock = self . sweeper_state . lock ( ) . unwrap ( ) ;
633+ let state_lock = & mut self . sweeper_state . lock ( ) . unwrap ( ) . persistent ;
633634
634635 let new_height = height - 1 ;
635636 let block_hash = header. block_hash ( ) ;
@@ -667,15 +668,15 @@ where
667668 fn transactions_confirmed (
668669 & self , header : & Header , txdata : & chain:: transaction:: TransactionData , height : u32 ,
669670 ) {
670- let mut state_lock = self . sweeper_state . lock ( ) . unwrap ( ) ;
671- self . transactions_confirmed_internal ( & mut * state_lock, header, txdata, height) ;
672- self . persist_state ( & * state_lock) . unwrap_or_else ( |e| {
671+ let state_lock = & mut self . sweeper_state . lock ( ) . unwrap ( ) . persistent ;
672+ self . transactions_confirmed_internal ( state_lock, header, txdata, height) ;
673+ self . persist_state ( state_lock) . unwrap_or_else ( |e| {
673674 log_error ! ( self . logger, "Error persisting OutputSweeper: {:?}" , e) ;
674675 } ) ;
675676 }
676677
677678 fn transaction_unconfirmed ( & self , txid : & Txid ) {
678- let mut state_lock = self . sweeper_state . lock ( ) . unwrap ( ) ;
679+ let state_lock = & mut self . sweeper_state . lock ( ) . unwrap ( ) . persistent ;
679680
680681 // Get what height was unconfirmed.
681682 let unconf_height = state_lock
@@ -692,22 +693,22 @@ where
692693 . filter ( |o| o. status . confirmation_height ( ) >= Some ( unconf_height) )
693694 . for_each ( |o| o. status . unconfirmed ( ) ) ;
694695
695- self . persist_state ( & * state_lock) . unwrap_or_else ( |e| {
696+ self . persist_state ( state_lock) . unwrap_or_else ( |e| {
696697 log_error ! ( self . logger, "Error persisting OutputSweeper: {:?}" , e) ;
697698 } ) ;
698699 }
699700 }
700701
701702 fn best_block_updated ( & self , header : & Header , height : u32 ) {
702- let mut state_lock = self . sweeper_state . lock ( ) . unwrap ( ) ;
703- self . best_block_updated_internal ( & mut * state_lock, header, height) ;
704- let _ = self . persist_state ( & * state_lock) . map_err ( |e| {
703+ let state_lock = & mut self . sweeper_state . lock ( ) . unwrap ( ) . persistent ;
704+ self . best_block_updated_internal ( state_lock, header, height) ;
705+ let _ = self . persist_state ( state_lock) . map_err ( |e| {
705706 log_error ! ( self . logger, "Error persisting OutputSweeper: {:?}" , e) ;
706707 } ) ;
707708 }
708709
709710 fn get_relevant_txids ( & self ) -> Vec < ( Txid , u32 , Option < BlockHash > ) > {
710- let state_lock = self . sweeper_state . lock ( ) . unwrap ( ) ;
711+ let state_lock = & self . sweeper_state . lock ( ) . unwrap ( ) . persistent ;
711712 state_lock
712713 . outputs
713714 . iter ( )
@@ -728,6 +729,10 @@ where
728729 }
729730}
730731
732+ struct RuntimeSweeperState {
733+ persistent : SweeperState ,
734+ }
735+
731736#[ derive( Debug , Clone ) ]
732737struct SweeperState {
733738 outputs : Vec < TrackedSpendableOutput > ,
@@ -790,7 +795,7 @@ where
790795 }
791796 }
792797
793- let sweeper_state = Mutex :: new ( state) ;
798+ let sweeper_state = Mutex :: new ( RuntimeSweeperState { persistent : state } ) ;
794799 Ok ( Self {
795800 sweeper_state,
796801 broadcaster,
@@ -838,7 +843,7 @@ where
838843 }
839844 }
840845
841- let sweeper_state = Mutex :: new ( state) ;
846+ let sweeper_state = Mutex :: new ( RuntimeSweeperState { persistent : state } ) ;
842847 Ok ( (
843848 best_block,
844849 OutputSweeper {
0 commit comments