@@ -270,7 +270,7 @@ impl<S: BlockchainStorage, V: TransactionVerificationStrategy> Chainstate<S, V>
270270
271271 fn broadcast_new_tip_event (
272272 & mut self ,
273- best_block_index : & BlockIndex ,
273+ best_block_index : GenBlockIndexRef < ' _ > ,
274274 is_initial_block_download : bool ,
275275 ) {
276276 let event = ChainstateEvent :: NewTip {
@@ -623,7 +623,10 @@ impl<S: BlockchainStorage, V: TransactionVerificationStrategy> Chainstate<S, V>
623623
624624 if let Some ( best_block_index) = & best_block_index_opt {
625625 self . update_initial_block_download_flag ( GenBlockIndexRef :: Block ( best_block_index) ) ;
626- self . broadcast_new_tip_event ( best_block_index, self . is_initial_block_download ( ) ) ;
626+ self . broadcast_new_tip_event (
627+ GenBlockIndexRef :: Block ( best_block_index) ,
628+ self . is_initial_block_download ( ) ,
629+ ) ;
627630
628631 let compact_target = match best_block_index. block_header ( ) . consensus_data ( ) {
629632 ConsensusData :: None => Compact :: from ( Uint256 :: ZERO ) ,
@@ -707,15 +710,60 @@ impl<S: BlockchainStorage, V: TransactionVerificationStrategy> Chainstate<S, V>
707710
708711 #[ log_error]
709712 pub fn invalidate_block ( & mut self , block_id : & Id < Block > ) -> Result < ( ) , BlockInvalidatorError > {
713+ let prev_best_block_id = self
714+ . make_db_tx_ro ( ) ?
715+ . get_best_block_id ( )
716+ . map_err ( BlockInvalidatorError :: BestBlockIdQueryError ) ?;
717+
710718 let result = BlockInvalidator :: new ( self )
711719 . invalidate_block ( block_id, block_invalidation:: IsExplicit :: Yes ) ;
712720 // Note: we don't ignore the result of check_consistency even though we may already have
713721 // an error to return (if the checks are enabled but couldn't be done for some reason,
714722 // we don't want to miss this).
715723 self . check_consistency ( ) ?;
724+
725+ let new_best_block_index = self
726+ . make_db_tx_ro ( ) ?
727+ . get_best_block_index ( )
728+ . map_err ( BlockInvalidatorError :: BestBlockIndexQueryError ) ?;
729+
730+ if new_best_block_index. block_id ( ) != prev_best_block_id {
731+ self . broadcast_new_tip_event (
732+ new_best_block_index. as_ref ( ) ,
733+ self . is_initial_block_download ( ) ,
734+ ) ;
735+ }
736+
716737 result
717738 }
718739
740+ #[ log_error]
741+ pub fn reset_block_failure_flags (
742+ & mut self ,
743+ block_id : & Id < Block > ,
744+ ) -> Result < ( ) , BlockInvalidatorError > {
745+ let prev_best_block_id = self
746+ . make_db_tx_ro ( ) ?
747+ . get_best_block_id ( )
748+ . map_err ( BlockInvalidatorError :: BestBlockIdQueryError ) ?;
749+
750+ BlockInvalidator :: new ( self ) . reset_block_failure_flags ( block_id) ?;
751+
752+ let new_best_block_index = self
753+ . make_db_tx_ro ( ) ?
754+ . get_best_block_index ( )
755+ . map_err ( BlockInvalidatorError :: BestBlockIndexQueryError ) ?;
756+
757+ if new_best_block_index. block_id ( ) != prev_best_block_id {
758+ self . broadcast_new_tip_event (
759+ new_best_block_index. as_ref ( ) ,
760+ self . is_initial_block_download ( ) ,
761+ ) ;
762+ }
763+
764+ Ok ( ( ) )
765+ }
766+
719767 #[ log_error]
720768 fn create_pool_in_storage (
721769 & self ,
0 commit comments