@@ -362,36 +362,22 @@ 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.
365367 let cycle_start_height = burnchain. nakamoto_first_block_of_cycle ( reward_cycle) ;
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 {
368+ // This is safe to case because a u32 always fits in a u64
369+ let prepare_phase_start = cycle_start_height - u64:: from ( burnchain. pox_constants . prepare_length ) ;
370+ let epoch_at_height = SortitionDB :: get_stacks_epoch ( sort_db. conn ( ) , prepare_phase_start) ?
371+ . unwrap_or_else ( || panic ! ( "FATAL: no epoch defined for burn height {prepare_phase_start}" ) ) ;
372+ if epoch_at_height. epoch_id < StacksEpochId :: Epoch30 {
387373 // 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.
388374 // The nakamoto chain-processing rules aren't active yet, so we can't look for the reward
389375 // cycle info in the nakamoto chain state.
390376 let Some ( prepare_end_sortition_id) =
391377 get_ancestor_sort_id ( & sort_db. index_conn ( ) , cycle_start_height, sortition_tip) ?
392378 else {
393379 // reward cycle is too far in the future
394- warn ! ( "Requested reward cycle start ancestor sortition ID for cycle {} prepare-end height {}, but tip is {}" , reward_cycle , cycle_start_height , sortition_tip ) ;
380+ warn ! ( "Requested reward cycle start ancestor sortition ID for cycle {reward_cycle } prepare-end height {cycle_start_height }, but tip is {sortition_tip}" ) ;
395381 return Ok ( None ) ;
396382 } ;
397383
0 commit comments