const HALVING_INCREMENT: u32 = SUBSIDY_HALVING_INTERVAL % DIFFCHANGE_INTERVAL; // For valid degrees the relationship between epoch_offset and period_offset // will increment by 336 every halving. let relationship = period_offset + SUBSIDY_HALVING_INTERVAL * CYCLE_EPOCHS - epoch_offset; if relationship % HALVING_INCREMENT != 0 { bail!("relationship between epoch offset and period offset must be multiple of 336"); } let epochs_since_cycle_start = relationship % DIFFCHANGE_INTERVAL / HALVING_INCREMENT; let epoch = cycle_start_epoch + epochs_since_cycle_start; let height = Height(epoch * SUBSIDY_HALVING_INTERVAL + epoch_offset); let (block_offset, rest) = match rest.split_once('‴') { Some((block_offset, rest)) => (block_offset.parse::()?, rest), None => (0, rest), }; if !rest.is_empty() { bail!("trailing characters"); } if block_offset >= height.subsidy() { bail!("invalid block offset"); } Ok(height.starting_sat() + block_offset)