@@ -632,37 +632,45 @@ impl RelayerThread {
632
632
return None ;
633
633
} ;
634
634
635
- if self . need_block_found ( & canonical_stacks_snapshot, & last_winning_snapshot) {
636
- info ! (
637
- "Relayer: will submit late BlockFound for {}" ,
635
+ let won_last_winning_snapshot =
636
+ mining_pkh_opt. is_some ( ) && last_winning_snapshot. miner_pk_hash == mining_pkh_opt;
637
+
638
+ if won_last_winning_snapshot {
639
+ debug ! (
640
+ "Relayer: we won the last winning sortition {}" ,
638
641
& last_winning_snapshot. consensus_hash
639
642
) ;
640
- // prepare to immediately extend after our BlockFound gets mined.
641
- self . tenure_extend_time = Some ( TenureExtendTime :: immediate ( ) ) ;
642
- return Some ( MinerDirective :: BeginTenure {
643
- parent_tenure_start : StacksBlockId (
644
- last_winning_snapshot. winning_stacks_block_hash . clone ( ) . 0 ,
645
- ) ,
646
- burnchain_tip : sn,
647
- election_block : last_winning_snapshot,
648
- late : true ,
649
- } ) ;
650
- }
651
643
652
- let won_last_winning_snapshot =
653
- mining_pkh_opt. is_some ( ) && last_winning_snapshot. miner_pk_hash == mining_pkh_opt;
654
- let tip_is_last_winning_snapshot = mining_pkh_opt. is_some ( )
655
- && canonical_stacks_snapshot. block_height == last_winning_snapshot. block_height
656
- && canonical_stacks_snapshot. consensus_hash == last_winning_snapshot. consensus_hash ;
657
-
658
- if won_last_winning_snapshot && tip_is_last_winning_snapshot {
659
- // this is the ongoing tenure snapshot. A BlockFound has already been issued. We
660
- // can instead opt to Extend immediately
661
- info ! ( "Relayer: BlockFound already issued for the last winning sortition. Will extend tenure." ) ;
662
- return Some ( MinerDirective :: ContinueTenure {
663
- new_burn_view : sn. consensus_hash ,
664
- } ) ;
644
+ if self . need_block_found ( & canonical_stacks_snapshot, & last_winning_snapshot) {
645
+ info ! (
646
+ "Relayer: will submit late BlockFound for {}" ,
647
+ & last_winning_snapshot. consensus_hash
648
+ ) ;
649
+ // prepare to immediately extend after our BlockFound gets mined.
650
+ self . tenure_extend_time = Some ( TenureExtendTime :: immediate ( ) ) ;
651
+ return Some ( MinerDirective :: BeginTenure {
652
+ parent_tenure_start : StacksBlockId (
653
+ last_winning_snapshot. winning_stacks_block_hash . clone ( ) . 0 ,
654
+ ) ,
655
+ burnchain_tip : sn,
656
+ election_block : last_winning_snapshot,
657
+ late : true ,
658
+ } ) ;
659
+ }
660
+ let tip_is_last_winning_snapshot = mining_pkh_opt. is_some ( )
661
+ && canonical_stacks_snapshot. block_height == last_winning_snapshot. block_height
662
+ && canonical_stacks_snapshot. consensus_hash == last_winning_snapshot. consensus_hash ;
663
+
664
+ if tip_is_last_winning_snapshot {
665
+ // this is the ongoing tenure snapshot. A BlockFound has already been issued. We
666
+ // can instead opt to Extend immediately
667
+ info ! ( "Relayer: BlockFound already issued for the last winning sortition. Will extend tenure." ) ;
668
+ return Some ( MinerDirective :: ContinueTenure {
669
+ new_burn_view : sn. consensus_hash ,
670
+ } ) ;
671
+ }
665
672
}
673
+
666
674
if won_ongoing_tenure_sortition {
667
675
info ! ( "Relayer: No sortition, but we produced the canonical Stacks tip. Will extend tenure." ) ;
668
676
if !won_last_winning_snapshot {
@@ -684,27 +692,16 @@ impl RelayerThread {
684
692
return None ;
685
693
}
686
694
687
- /// Determine if we need to issue a BlockFound.
695
+ /// Determine if we the current tenure winner needs to issue a BlockFound.
696
+ /// Assumes the caller has already checked that the last-winning snapshot was won by us.
688
697
///
689
- /// Returns true if we won the last non-empty sortition, and the stacks tip's snapshot is an ancestor of the last-won sortition
698
+ /// Returns true if the stacks tip's snapshot is an ancestor of the last-won sortition
690
699
/// Returns false otherwise.
691
700
fn need_block_found (
692
701
& mut self ,
693
702
canonical_stacks_snapshot : & BlockSnapshot ,
694
703
last_winning_snapshot : & BlockSnapshot ,
695
704
) -> bool {
696
- if last_winning_snapshot. miner_pk_hash != self . get_mining_key_pkh ( ) {
697
- debug ! (
698
- "Relayer: we did not win the last winning sortition {}" ,
699
- & last_winning_snapshot. consensus_hash
700
- ) ;
701
- // We did not win the last winning snapshot, we do not need to issue a block found.
702
- return false ;
703
- }
704
- debug ! (
705
- "Relayer: we won the last winning sortition {}" ,
706
- & last_winning_snapshot. consensus_hash
707
- ) ;
708
705
// we won the last non-empty sortition. Has there been a BlockFound issued for it?
709
706
// This would be true if the stacks tip's tenure is at or descends from this snapshot.
710
707
// If there has _not_ been a BlockFound, then we should issue one.
@@ -1854,11 +1851,15 @@ impl RelayerThread {
1854
1851
return ;
1855
1852
} ;
1856
1853
1857
- if self . need_block_found ( & canonical_stacks_snapshot, & last_winning_snapshot) {
1854
+ let won_last_winning_snapshot = last_winning_snapshot. miner_pk_hash == Some ( mining_pk) ;
1855
+ if won_last_winning_snapshot
1856
+ && self . need_block_found ( & canonical_stacks_snapshot, & last_winning_snapshot)
1857
+ {
1858
1858
info ! ( "Will not extend tenure -- need to issue a BlockFound first" ) ;
1859
1859
return ;
1860
1860
}
1861
-
1861
+ // If we reach this code, we have either won the last winning snapshot and have already issued a block found for it and should extend.
1862
+ // OR we did not win the last snapshot, but the person who did has failed to produce a block and we should extend our old tenure.
1862
1863
if let Err ( e) = self . stop_tenure ( ) {
1863
1864
error ! ( "Relayer: Failed to stop tenure: {e:?}" ) ;
1864
1865
return ;
0 commit comments