Skip to content

Commit

Permalink
Merge pull request #4468 from stacks-network/feat/pox-info-reward-cycle
Browse files Browse the repository at this point in the history
Fix: manually calculate current reward cycle ID in /v2/pox_info
  • Loading branch information
saralab committed Mar 5, 2024
2 parents afe7e68 + d5af26e commit 11d7434
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions stackslib/src/net/api/getpoxinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,6 @@ impl RPCPoxInfoData {
.to_owned()
.expect_u128()? as u64;

let reward_cycle_id = res
.get("reward-cycle-id")
.unwrap_or_else(|_| panic!("FATAL: no 'reward-cycle-id'"))
.to_owned()
.expect_u128()? as u64;

let reward_cycle_length = res
.get("reward-cycle-length")
.unwrap_or_else(|_| panic!("FATAL: no 'reward-cycle-length'"))
Expand Down Expand Up @@ -292,7 +286,16 @@ impl RPCPoxInfoData {
return Err(NetError::DBError(DBError::Corruption));
}

// Manually calculate `reward_cycle_id` so that clients don't get an "off by one" view at
// reward cycle boundaries (because if the reward cycle is loaded from clarity, its
// evaluated in the last mined Stacks block, not the most recent burn block).
let reward_cycle_id = burnchain
.block_height_to_reward_cycle(burnchain_tip.block_height)
.ok_or_else(|| {
NetError::ChainstateError("Current burn block height is before stacks start".into())
})?;
let effective_height = burnchain_tip.block_height - first_burnchain_block_height;

let next_reward_cycle_in = reward_cycle_length - (effective_height % reward_cycle_length);

let next_rewards_start = burnchain_tip.block_height + next_reward_cycle_in;
Expand Down

0 comments on commit 11d7434

Please sign in to comment.