Skip to main content

get_next_work_required_corrected

Function get_next_work_required_corrected 

Source
pub fn get_next_work_required_corrected(
    _current_header: &BlockHeader,
    prev_headers: &[BlockHeader],
) -> Result<u64, ConsensusError>
Expand description

GetNextWorkRequired (Corrected): ℋ × ℋ* → ℕ

Calculate the next work required with corrected off-by-one error fix.

This version fixes the known off-by-one error in Bitcoin’s difficulty adjustment:

  • When measuring time for n blocks (indices 0 to n-1), we measure (n-1) intervals
  • The corrected version adjusts expected_time to account for this
  • Use this for regtest or new protocol variants that don’t need Bitcoin compatibility

Compatibility Warning: Do NOT use this for Bitcoin mainnet/testnet as it will cause consensus divergence. This is only safe for isolated networks like regtest.