@@ -790,11 +790,44 @@ impl Relayer {
790
790
}
791
791
Ok ( res)
792
792
}
793
+
794
+ /// Wrapper around inner_process_new_nakamoto_block
795
+ pub fn process_new_nakamoto_block (
796
+ burnchain : & Burnchain ,
797
+ sortdb : & SortitionDB ,
798
+ sort_handle : & mut SortitionHandleConn ,
799
+ chainstate : & mut StacksChainState ,
800
+ stacks_tip : & StacksBlockId ,
801
+ block : & NakamotoBlock ,
802
+ coord_comms : Option < & CoordinatorChannels > ,
803
+ obtained_method : NakamotoBlockObtainMethod ,
804
+ ) -> Result < bool , chainstate_error > {
805
+ Self :: process_new_nakamoto_block_ext (
806
+ burnchain,
807
+ sortdb,
808
+ sort_handle,
809
+ chainstate,
810
+ stacks_tip,
811
+ block,
812
+ coord_comms,
813
+ obtained_method,
814
+ false
815
+ )
816
+ }
793
817
794
818
/// Insert a staging Nakamoto block that got relayed to us somehow -- e.g. uploaded via http,
795
819
/// downloaded by us, or pushed via p2p.
796
- /// Return Ok(true) if we stored it, Ok(false) if we didn't
797
- pub fn process_new_nakamoto_block (
820
+ /// Return Ok(true) if we should broadcast the block. If force_broadcast is true, then this
821
+ /// function will return Ok(true) even if we already have the block.
822
+ /// Return Ok(false) if we should not broadcast it (e.g. we already have it, it was invalid,
823
+ /// etc.)
824
+ /// Return Err(..) in the following cases, beyond DB errors:
825
+ /// * If the block is from a tenure we don't recognize
826
+ /// * If we're not in the Nakamoto epoch
827
+ /// * If the reward cycle info could not be determined
828
+ /// * If there was an unrecognized signer
829
+ /// * If the coordinator is closed, and `coord_comms` is Some(..)
830
+ pub fn process_new_nakamoto_block_ext (
798
831
burnchain : & Burnchain ,
799
832
sortdb : & SortitionDB ,
800
833
sort_handle : & mut SortitionHandleConn ,
@@ -803,6 +836,7 @@ impl Relayer {
803
836
block : & NakamotoBlock ,
804
837
coord_comms : Option < & CoordinatorChannels > ,
805
838
obtained_method : NakamotoBlockObtainMethod ,
839
+ force_broadcast : bool
806
840
) -> Result < bool , chainstate_error > {
807
841
debug ! (
808
842
"Handle incoming Nakamoto block {}/{} obtained via {}" ,
@@ -825,8 +859,16 @@ impl Relayer {
825
859
e
826
860
} ) ?
827
861
{
828
- debug ! ( "Already have Nakamoto block {}" , & block. header. block_id( ) ) ;
829
- return Ok ( false ) ;
862
+ if force_broadcast {
863
+ // it's possible that the signer sent this block to us, in which case, we should
864
+ // broadcast it
865
+ debug ! ( "Already have Nakamoto block {}, but broadcasting anyway" , & block. header. block_id( ) ) ;
866
+ return Ok ( true ) ;
867
+ }
868
+ else {
869
+ debug ! ( "Already have Nakamoto block {}" , & block. header. block_id( ) ) ;
870
+ return Ok ( false ) ;
871
+ }
830
872
}
831
873
832
874
let block_sn =
@@ -2541,6 +2583,7 @@ impl Relayer {
2541
2583
accepted_blocks : Vec < AcceptedNakamotoBlocks > ,
2542
2584
force_send : bool ,
2543
2585
) {
2586
+ // TODO: we don't relay HTTP-uploaded blocks :(
2544
2587
debug ! (
2545
2588
"{:?}: relay {} sets of Nakamoto blocks" ,
2546
2589
_local_peer,
0 commit comments