@@ -574,6 +574,29 @@ where
574
574
& Secp256k1 :: new ( ) ,
575
575
)
576
576
}
577
+
578
+ fn transactions_confirmed_internal (
579
+ & self , sweeper_state : & mut SweeperState , header : & Header ,
580
+ txdata : & chain:: transaction:: TransactionData , height : u32 ,
581
+ ) {
582
+ let confirmation_hash = header. block_hash ( ) ;
583
+ for ( _, tx) in txdata {
584
+ for output_info in sweeper_state. outputs . iter_mut ( ) {
585
+ if output_info. is_spent_in ( * tx) {
586
+ output_info. status . confirmed ( confirmation_hash, height, ( * tx) . clone ( ) )
587
+ }
588
+ }
589
+ }
590
+ }
591
+
592
+ fn best_block_updated_internal (
593
+ & self , sweeper_state : & mut SweeperState , header : & Header , height : u32 ,
594
+ ) -> Option < Transaction > {
595
+ sweeper_state. best_block = BestBlock :: new ( header. block_hash ( ) , height) ;
596
+ self . prune_confirmed_outputs ( sweeper_state) ;
597
+ let spending_tx_opt = self . regenerate_spend_if_necessary ( sweeper_state) ;
598
+ spending_tx_opt
599
+ }
577
600
}
578
601
579
602
impl < B : Deref , D : Deref , E : Deref , F : Deref , K : Deref , L : Deref , O : Deref > Listen
@@ -590,16 +613,25 @@ where
590
613
fn filtered_block_connected (
591
614
& self , header : & Header , txdata : & chain:: transaction:: TransactionData , height : u32 ,
592
615
) {
616
+ let spending_tx_opt;
593
617
{
594
- let state_lock = self . sweeper_state . lock ( ) . unwrap ( ) ;
618
+ let mut state_lock = self . sweeper_state . lock ( ) . unwrap ( ) ;
595
619
assert_eq ! ( state_lock. best_block. block_hash, header. prev_blockhash,
596
- "Blocks must be connected in chain-order - the connected header must build on the last connected header" ) ;
620
+ "Blocks must be connected in chain-order - the connected header must build on the last connected header" ) ;
597
621
assert_eq ! ( state_lock. best_block. height, height - 1 ,
598
- "Blocks must be connected in chain-order - the connected block height must be one greater than the previous height" ) ;
622
+ "Blocks must be connected in chain-order - the connected block height must be one greater than the previous height" ) ;
623
+
624
+ self . transactions_confirmed_internal ( & mut * state_lock, header, txdata, height) ;
625
+ spending_tx_opt = self . best_block_updated_internal ( & mut * state_lock, header, height) ;
626
+
627
+ self . persist_state ( & * state_lock) . unwrap_or_else ( |e| {
628
+ log_error ! ( self . logger, "Error persisting OutputSweeper: {:?}" , e) ;
629
+ } ) ;
599
630
}
600
631
601
- self . transactions_confirmed ( header, txdata, height) ;
602
- self . best_block_updated ( header, height) ;
632
+ if let Some ( spending_tx) = spending_tx_opt {
633
+ self . broadcaster . broadcast_transactions ( & [ & spending_tx] ) ;
634
+ }
603
635
}
604
636
605
637
fn block_disconnected ( & self , header : & Header , height : u32 ) {
@@ -642,15 +674,7 @@ where
642
674
& self , header : & Header , txdata : & chain:: transaction:: TransactionData , height : u32 ,
643
675
) {
644
676
let mut state_lock = self . sweeper_state . lock ( ) . unwrap ( ) ;
645
- let confirmation_hash = header. block_hash ( ) ;
646
- for ( _, tx) in txdata {
647
- for output_info in state_lock. outputs . iter_mut ( ) {
648
- if output_info. is_spent_in ( * tx) {
649
- output_info. status . confirmed ( confirmation_hash, height, ( * tx) . clone ( ) )
650
- }
651
- }
652
- }
653
-
677
+ self . transactions_confirmed_internal ( & mut * state_lock, header, txdata, height) ;
654
678
self . persist_state ( & * state_lock) . unwrap_or_else ( |e| {
655
679
log_error ! ( self . logger, "Error persisting OutputSweeper: {:?}" , e) ;
656
680
} ) ;
@@ -688,10 +712,7 @@ where
688
712
let spending_tx_opt;
689
713
{
690
714
let mut state_lock = self . sweeper_state . lock ( ) . unwrap ( ) ;
691
- state_lock. best_block = BestBlock :: new ( header. block_hash ( ) , height) ;
692
- self . prune_confirmed_outputs ( & mut * state_lock) ;
693
- spending_tx_opt = self . regenerate_spend_if_necessary ( & mut * state_lock) ;
694
-
715
+ spending_tx_opt = self . best_block_updated_internal ( & mut * state_lock, header, height) ;
695
716
self . persist_state ( & * state_lock) . unwrap_or_else ( |e| {
696
717
log_error ! ( self . logger, "Error persisting OutputSweeper: {:?}" , e) ;
697
718
} ) ;
0 commit comments