@@ -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,26 +434,26 @@ 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_locked ( & self ) -> Result < ( ) , ( ) > {
454- let mut sweeper_state = self . sweeper_state . lock ( ) . unwrap ( ) ;
455- self . regenerate_and_broadcast_spend_if_necessary ( & mut * sweeper_state)
455+ let sweeper_state = & mut self . sweeper_state . lock ( ) . unwrap ( ) . persistent ;
456+ self . regenerate_and_broadcast_spend_if_necessary ( sweeper_state)
456457 }
457458
458459 fn regenerate_and_broadcast_spend_if_necessary (
@@ -628,22 +629,22 @@ where
628629 fn filtered_block_connected (
629630 & self , header : & Header , txdata : & chain:: transaction:: TransactionData , height : u32 ,
630631 ) {
631- let mut state_lock = self . sweeper_state . lock ( ) . unwrap ( ) ;
632+ let state_lock = & mut self . sweeper_state . lock ( ) . unwrap ( ) . persistent ;
632633 assert_eq ! ( state_lock. best_block. block_hash, header. prev_blockhash,
633634 "Blocks must be connected in chain-order - the connected header must build on the last connected header" ) ;
634635 assert_eq ! ( state_lock. best_block. height, height - 1 ,
635636 "Blocks must be connected in chain-order - the connected block height must be one greater than the previous height" ) ;
636637
637- self . transactions_confirmed_internal ( & mut * state_lock, header, txdata, height) ;
638- self . best_block_updated_internal ( & mut * state_lock, header, height) ;
638+ self . transactions_confirmed_internal ( state_lock, header, txdata, height) ;
639+ self . best_block_updated_internal ( state_lock, header, height) ;
639640
640- let _ = self . persist_state ( & * state_lock) . map_err ( |e| {
641+ let _ = self . persist_state ( & state_lock) . map_err ( |e| {
641642 log_error ! ( self . logger, "Error persisting OutputSweeper: {:?}" , e) ;
642643 } ) ;
643644 }
644645
645646 fn block_disconnected ( & self , header : & Header , height : u32 ) {
646- let mut state_lock = self . sweeper_state . lock ( ) . unwrap ( ) ;
647+ let state_lock = & mut self . sweeper_state . lock ( ) . unwrap ( ) . persistent ;
647648
648649 let new_height = height - 1 ;
649650 let block_hash = header. block_hash ( ) ;
@@ -681,15 +682,15 @@ where
681682 fn transactions_confirmed (
682683 & self , header : & Header , txdata : & chain:: transaction:: TransactionData , height : u32 ,
683684 ) {
684- let mut state_lock = self . sweeper_state . lock ( ) . unwrap ( ) ;
685- self . transactions_confirmed_internal ( & mut * state_lock, header, txdata, height) ;
686- self . persist_state ( & * state_lock) . unwrap_or_else ( |e| {
685+ let state_lock = & mut self . sweeper_state . lock ( ) . unwrap ( ) . persistent ;
686+ self . transactions_confirmed_internal ( state_lock, header, txdata, height) ;
687+ self . persist_state ( state_lock) . unwrap_or_else ( |e| {
687688 log_error ! ( self . logger, "Error persisting OutputSweeper: {:?}" , e) ;
688689 } ) ;
689690 }
690691
691692 fn transaction_unconfirmed ( & self , txid : & Txid ) {
692- let mut state_lock = self . sweeper_state . lock ( ) . unwrap ( ) ;
693+ let state_lock = & mut self . sweeper_state . lock ( ) . unwrap ( ) . persistent ;
693694
694695 // Get what height was unconfirmed.
695696 let unconf_height = state_lock
@@ -706,22 +707,22 @@ where
706707 . filter ( |o| o. status . confirmation_height ( ) >= Some ( unconf_height) )
707708 . for_each ( |o| o. status . unconfirmed ( ) ) ;
708709
709- self . persist_state ( & * state_lock) . unwrap_or_else ( |e| {
710+ self . persist_state ( state_lock) . unwrap_or_else ( |e| {
710711 log_error ! ( self . logger, "Error persisting OutputSweeper: {:?}" , e) ;
711712 } ) ;
712713 }
713714 }
714715
715716 fn best_block_updated ( & self , header : & Header , height : u32 ) {
716- let mut state_lock = self . sweeper_state . lock ( ) . unwrap ( ) ;
717- self . best_block_updated_internal ( & mut * state_lock, header, height) ;
718- let _ = self . persist_state ( & * state_lock) . map_err ( |e| {
717+ let state_lock = & mut self . sweeper_state . lock ( ) . unwrap ( ) . persistent ;
718+ self . best_block_updated_internal ( state_lock, header, height) ;
719+ let _ = self . persist_state ( state_lock) . map_err ( |e| {
719720 log_error ! ( self . logger, "Error persisting OutputSweeper: {:?}" , e) ;
720721 } ) ;
721722 }
722723
723724 fn get_relevant_txids ( & self ) -> Vec < ( Txid , u32 , Option < BlockHash > ) > {
724- let state_lock = self . sweeper_state . lock ( ) . unwrap ( ) ;
725+ let state_lock = & self . sweeper_state . lock ( ) . unwrap ( ) . persistent ;
725726 state_lock
726727 . outputs
727728 . iter ( )
@@ -742,6 +743,11 @@ where
742743 }
743744}
744745
746+ #[ derive( Debug , Clone ) ]
747+ struct RuntimeSweeperState {
748+ persistent : SweeperState ,
749+ }
750+
745751#[ derive( Debug , Clone ) ]
746752struct SweeperState {
747753 outputs : Vec < TrackedSpendableOutput > ,
@@ -804,7 +810,7 @@ where
804810 }
805811 }
806812
807- let sweeper_state = Mutex :: new ( state) ;
813+ let sweeper_state = Mutex :: new ( RuntimeSweeperState { persistent : state } ) ;
808814 Ok ( Self {
809815 sweeper_state,
810816 broadcaster,
@@ -852,7 +858,7 @@ where
852858 }
853859 }
854860
855- let sweeper_state = Mutex :: new ( state) ;
861+ let sweeper_state = Mutex :: new ( RuntimeSweeperState { persistent : state } ) ;
856862 Ok ( (
857863 best_block,
858864 OutputSweeper {
0 commit comments