Skip to content

Commit

Permalink
Merge pull request #2755 from blockstack/feat/pox-2-extend
Browse files Browse the repository at this point in the history
Stacks 2.1: PoX 2 `stack-extend`, `delegate-stack-extend`
  • Loading branch information
kantai authored Aug 27, 2021
2 parents 4c268bb + 0a6bf7a commit 7b7d652
Show file tree
Hide file tree
Showing 12 changed files with 3,011 additions and 16 deletions.
22 changes: 17 additions & 5 deletions src/burnchains/burnchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,13 +504,25 @@ impl Burnchain {
self.first_block_height + reward_cycle * (self.pox_constants.reward_cycle_length as u64) + 1
}

pub fn block_height_to_reward_cycle(&self, block_height: u64) -> Option<u64> {
if block_height < self.first_block_height {
/// Returns the active reward cycle at the given burn block height
/// * `first_block_ht` - the first burn block height that the Stacks network monitored
/// * `reward_cycle_len` - the length of each reward cycle in the network.
pub fn static_block_height_to_reward_cycle(
block_ht: u64,
first_block_ht: u64,
reward_cycle_len: u64,
) -> Option<u64> {
if block_ht < first_block_ht {
return None;
}
Some(
(block_height - self.first_block_height)
/ (self.pox_constants.reward_cycle_length as u64),
Some((block_ht - first_block_ht) / (reward_cycle_len))
}

pub fn block_height_to_reward_cycle(&self, block_height: u64) -> Option<u64> {
Self::static_block_height_to_reward_cycle(
block_height,
self.first_block_height,
self.pox_constants.reward_cycle_length as u64,
)
}

Expand Down
Loading

0 comments on commit 7b7d652

Please sign in to comment.