@@ -887,7 +887,7 @@ impl RelayerThread {
887
887
let mining_pkh = Hash160 :: from_node_public_key ( & StacksPublicKey :: from_private ( mining_key) ) ;
888
888
889
889
// If we won the last sortition, then we should start a new tenure off of it.
890
- let block_election_snapshot = {
890
+ let last_block_election_snapshot = {
891
891
let ih = self . sortdb . index_handle ( & burn_tip. sortition_id ) ;
892
892
ih. get_last_snapshot_with_sortition ( burn_tip. block_height )
893
893
. map_err ( |e| {
@@ -896,13 +896,13 @@ impl RelayerThread {
896
896
} ) ?
897
897
} ;
898
898
899
- let won_last_sortition = block_election_snapshot . miner_pk_hash == Some ( mining_pkh) ;
899
+ let won_last_sortition = last_block_election_snapshot . miner_pk_hash == Some ( mining_pkh) ;
900
900
debug ! (
901
901
"Relayer: Current burn block had no sortition. Checking for tenure continuation." ;
902
902
"won_last_sortition" => won_last_sortition,
903
903
"current_mining_pkh" => %mining_pkh,
904
- "block_election_snapshot .consensus_hash" => %block_election_snapshot . consensus_hash,
905
- "block_election_snapshot .miner_pk_hash" => ?block_election_snapshot . miner_pk_hash,
904
+ "last_block_election_snapshot .consensus_hash" => %last_block_election_snapshot . consensus_hash,
905
+ "last_block_election_snapshot .miner_pk_hash" => ?last_block_election_snapshot . miner_pk_hash,
906
906
"canonical_stacks_tip_id" => %canonical_stacks_tip,
907
907
"canonical_stacks_tip_ch" => %canonical_stacks_tip_ch,
908
908
"burn_view_ch" => %new_burn_view,
@@ -912,42 +912,40 @@ impl RelayerThread {
912
912
return Ok ( ( ) ) ;
913
913
}
914
914
915
- let tip_info =
916
- NakamotoChainState :: get_canonical_block_header ( self . chainstate . db ( ) , & self . sortdb )
917
- . map_err ( |e| {
918
- error ! ( "Relayer: failed to get canonical block header: {e:?}" ) ;
919
- NakamotoNodeError :: SnapshotNotFoundForChainTip
920
- } ) ?
921
- . ok_or_else ( || {
922
- error ! ( "Relayer: failed to get canonical block header" ) ;
923
- NakamotoNodeError :: SnapshotNotFoundForChainTip
924
- } ) ?;
925
-
926
915
let last_non_empty_sortition_snapshot =
927
- SortitionDB :: get_block_snapshot_consensus ( self . sortdb . conn ( ) , & tip_info . consensus_hash )
916
+ SortitionDB :: get_block_snapshot_consensus ( self . sortdb . conn ( ) , & canonical_stacks_tip_ch )
928
917
. map_err ( |e| {
929
- error ! ( "Relayer: failed to get last non-empty sortition snapshot : {e:?}" ) ;
918
+ error ! ( "Relayer: failed to get block snapshot for canonical tip : {e:?}" ) ;
930
919
NakamotoNodeError :: SnapshotNotFoundForChainTip
931
920
} ) ?
932
921
. ok_or_else ( || {
933
- error ! ( "Relayer: failed to get last non-empty sortition snapshot " ) ;
922
+ error ! ( "Relayer: failed to get block snapshot for canonical tip " ) ;
934
923
NakamotoNodeError :: SnapshotNotFoundForChainTip
935
924
} ) ?;
936
925
937
926
let won_last_non_empty_sortition_snapshot =
938
927
last_non_empty_sortition_snapshot. miner_pk_hash == Some ( mining_pkh) ;
939
928
940
- let reason = if !won_last_non_empty_sortition_snapshot {
941
- debug ! ( "Relayer: Failed to issue a tenure change payload in our last tenure. Issue a tenure change payload again." ) ;
942
- MinerReason :: EmptyTenure
943
- } else {
944
- debug ! ( "Relayer: Successfully issued a tenure change payload in our last tenure. Issue a continue extend." ) ;
945
- MinerReason :: Extended {
946
- burn_view_consensus_hash : new_burn_view,
947
- }
948
- } ;
929
+ let ( parent_tenure_start, block_election_snapshot, reason) =
930
+ if !won_last_non_empty_sortition_snapshot {
931
+ debug ! ( "Relayer: Failed to issue a tenure change payload in our last tenure. Issue a new tenure change payload." ) ;
932
+ (
933
+ canonical_stacks_tip, // TODO: what should this be? is this correct?
934
+ last_block_election_snapshot,
935
+ MinerReason :: EmptyTenure ,
936
+ )
937
+ } else {
938
+ debug ! ( "Relayer: Successfully issued a tenure change payload in its tenure. Issue a continue extend from the chain tip." ) ;
939
+ (
940
+ canonical_stacks_tip, //For tenure extend, we sould be extending off the canonical tip
941
+ last_non_empty_sortition_snapshot,
942
+ MinerReason :: Extended {
943
+ burn_view_consensus_hash : new_burn_view,
944
+ } ,
945
+ )
946
+ } ;
949
947
match self . start_new_tenure (
950
- canonical_stacks_tip , // For tenure extend, we should be extending off the canonical tip
948
+ parent_tenure_start ,
951
949
block_election_snapshot,
952
950
burn_tip,
953
951
reason,
0 commit comments