Skip to content

Commit

Permalink
fix(stacks-indexer): prevent subtract with overflow (#449)
Browse files Browse the repository at this point in the history
I was attempting to update Clarinet to the latest version of
chainhook-sdk/types, and I ran into this issue when testing the devnet.

The devnet mines 100 bitcoin blocks, and the default
`pox_info.first_burnchain_block_height` is also 100, so devnet startup
would always fail.
  • Loading branch information
vabanaerytk authored Oct 15, 2023
1 parent 82a4afc commit 767cd8e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions components/chainhook-sdk/src/indexer/stacks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,10 @@ pub fn standardize_stacks_block(
let pox_cycle_length: u64 = (chain_ctx.pox_info.prepare_phase_block_length
+ chain_ctx.pox_info.reward_phase_block_length)
.into();
let current_len =
block.burn_block_height - (1 + chain_ctx.pox_info.first_burnchain_block_height);
let current_len = u64::saturating_sub(
block.burn_block_height,
1 + chain_ctx.pox_info.first_burnchain_block_height,
);
let pox_cycle_id: u32 = (current_len / pox_cycle_length).try_into().unwrap_or(0);
let mut events: HashMap<&String, Vec<&NewEvent>> = HashMap::new();
for event in block.events.iter() {
Expand Down

0 comments on commit 767cd8e

Please sign in to comment.