Skip to content

Regtest difficulty retargets, but zcashd regtest expects fixed powLimit (sidecar rejects headers as bad-diffbits) #199

Description

@arya2

expected_difficulty_threshold has no Regtest case — only the testnet minimum-difficulty branch, else full retargeting:

pub fn expected_difficulty_threshold(&self) -> CompactDifficulty {
if NetworkUpgrade::is_testnet_min_difficulty_block(
&self.network,
self.candidate_height,
self.candidate_time,
*self.relevant_times.first(),
) {
assert!(
self.network.is_a_test_network(),
"invalid network: the minimum difficulty rule only applies on test networks"
);
self.network.target_difficulty_limit().to_compact()
} else {
self.threshold_bits()
}
}

zcashd regtest uses fixed powLimit with no retargeting (fPowNoRetargeting). Once the difficulty-averaging window fills (~17 blocks), the nBits of blocks mined on a zakura regtest chain diverge from powLimit, and a following zcashd rejects the headers as bad-diffbits — a permanent fork at that height. -regtestacceptunvalidatedpow does not help: it skips equihash/block-hash checks, not the contextual nBits check.

Regtest-only; no mainnet impact. It does prevent any regtest test that mines more than ~17 blocks (e.g. coinbase-maturity flows, which need 100+) from working with a zcashd sidecar.

Reproduce: mine ~20 regtest blocks on zakurad with a zcashd sidecar following; the sidecar rejects the first post-window header with bad-diffbits and stops following.

Fix reference: fixed upstream in Zebra (ZcashFoundation/zebra#10952, commit c7691893e): pin every Regtest block to the target difficulty limit, matching zcashd's fPowNoRetargeting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions