@@ -362,15 +362,28 @@ pub fn load_nakamoto_reward_set<U: RewardSetProvider>(
362362 sort_db : & SortitionDB ,
363363 provider : & U ,
364364) -> Result < Option < ( RewardCycleInfo , StacksHeaderInfo ) > , Error > {
365- // If the prepare phase started in pre-Nakamoto, it should be using Epoch 2.5 reward
366- // set calculation rules.
367365 let cycle_start_height = burnchain. nakamoto_first_block_of_cycle ( reward_cycle) ;
368- // This is safe to cast because a u32 always fits in a u64
369- let prepare_phase_start =
370- cycle_start_height. saturating_sub ( u64:: from ( burnchain. pox_constants . prepare_length ) ) ;
371- let epoch_at_height = SortitionDB :: get_stacks_epoch ( sort_db. conn ( ) , prepare_phase_start) ?
372- . unwrap_or_else ( || panic ! ( "FATAL: no epoch defined for burn height {prepare_phase_start}" ) ) ;
373- if epoch_at_height. epoch_id < StacksEpochId :: Epoch30 {
366+ let epoch_at_height = SortitionDB :: get_stacks_epoch ( sort_db. conn ( ) , cycle_start_height) ?
367+ . unwrap_or_else ( || panic ! ( "FATAL: no epoch defined for burn height {cycle_start_height}" ) ) ;
368+ let is_pre_naka_epoch = if epoch_at_height. epoch_id < StacksEpochId :: Epoch30 {
369+ true
370+ } else {
371+ let epoch_30 =
372+ SortitionDB :: get_stacks_epoch_by_epoch_id ( sort_db. conn ( ) , & StacksEpochId :: Epoch30 ) ?
373+ . unwrap_or_else ( || panic ! ( "FATAL: no Nakamoto epoch defined" ) ) ;
374+ // Find the first Stacks block in this reward cycle's preceding prepare phase.
375+ // This block will have invoked `.signers.stackerdb-set-signer-slots()` with the reward set.
376+ // Note that we may not have processed it yet. But, if we do find it, then it's
377+ // unique (and since Nakamoto Stacks blocks are processed in order, the anchor block
378+ // cannot change later).
379+ let first_epoch30_reward_cycle = burnchain
380+ . block_height_to_reward_cycle ( epoch_30. start_height )
381+ . expect ( "FATAL: no reward cycle for epoch 3.0 start height" ) ;
382+ !epoch_at_height
383+ . epoch_id
384+ . uses_nakamoto_reward_set ( reward_cycle, first_epoch30_reward_cycle)
385+ } ;
386+ if is_pre_naka_epoch {
374387 // in epoch 2.5, and in the first reward cycle of epoch 3.0, the reward set can *only* be found in the sortition DB.
375388 // The nakamoto chain-processing rules aren't active yet, so we can't look for the reward
376389 // cycle info in the nakamoto chain state.
0 commit comments