Skip to content

fix: don't reject a mining interval of 0, which disables interval mining - #8486

Open
Kropiunig wants to merge 1 commit into
NomicFoundation:mainfrom
Kropiunig:fix/edr-mining-interval-zero
Open

fix: don't reject a mining interval of 0, which disables interval mining#8486
Kropiunig wants to merge 1 commit into
NomicFoundation:mainfrom
Kropiunig:fix/edr-mining-interval-zero

Conversation

@Kropiunig

Copy link
Copy Markdown
Contributor

Problem

The EDR network config validation rejects any mining.interval below 1000 ms
unless allowBlocksWithSameTimestamp: true is also set. That check exists to
stop block timestamps from running ahead of clock time (#6012).

A scalar interval: 0 does not schedule blocks at all, so it can't cause that
divergence. It is how interval mining is turned off — and it is the value the
config resolution already defaults to. Writing it explicitly makes Hardhat
refuse to load the config:

// hardhat.config.ts
export default {
  networks: {
    dev: {
      type: "edr-simulated",
      mining: {
        auto: false,
        interval: 0, // turn off automatic mining, mine manually with evm_mine
      },
    },
  },
};
$ npx hardhat test
Error in networks.dev.mining.interval: mining.interval is set to less than
1000 ms. To avoid the block timestamp diverging from clock time, please set
allowBlocksWithSameTimestamp: true on the network config

The suggested workaround (allowBlocksWithSameTimestamp: true) changes
unrelated behaviour, and the message describes a risk that cannot occur when no
blocks are mined on a timer.

Root cause

refineEdrNetworkUserConfig in
packages/hardhat/src/internal/builtin-plugins/network-manager/type-validation.ts
runs the minimum-interval check for every numeric interval, including 0:

const interval = network.mining?.interval;
if (typeof interval === "number" || Array.isArray(interval)) {
  const minInterval =
    typeof interval === "number" ? interval : Math.min(...interval);
  if (minInterval < 1000 && network.allowBlocksWithSameTimestamp !== true) {

But 0 is the "interval mining disabled" sentinel elsewhere in the same
plugin:

  • hardhatMiningIntervalToEdrMiningInterval
    (edr/utils/convert-to-edr.ts) maps a scalar 0 to undefined with the
    comment // Is interval mining disabled?.
  • resolveMiningConfig (config-resolution.ts) resolves the default to
    interval: 0, and the existing default-config test asserts
    mining === { auto: true, interval: 0, mempool: { order: "priority" } }.

So the validation rejects a value the resolver produces by default.

Fix

Skip the check only for a scalar 0. An interval range always enables
interval mining, so [0, 5000] is still an error.

Tests

Added to
packages/hardhat/test/internal/builtin-plugins/network-manager/hook-handlers/config.ts:

  • interval: 0 with allowBlocksWithSameTimestamp: false → no validation errors.
  • mining: { auto: false, interval: 0 } → no validation errors.
  • interval: [0, 5000] → still errors (ranges are unaffected).

Both new assertions fail on main (1 validation error where 0 is expected) and
pass with this change.

Copilot AI review requested due to automatic review settings August 3, 2026 21:59
@changeset-bot

changeset-bot Bot commented Aug 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2ccd059

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
hardhat Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes EDR simulated-network config validation so that mining.interval: 0 (the sentinel that disables interval mining and is also the resolved default) no longer triggers the “< 1000 ms” timestamp-divergence validation error.

Changes:

  • Updated EDR network config refinement to skip the minimum-interval check for scalar interval === 0 while keeping interval-range validation unchanged.
  • Added regression tests covering interval: 0 (accepted) and [0, 5000] (still rejected when allowBlocksWithSameTimestamp is false).
  • Added a changeset to release the fix as a patch.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
packages/hardhat/src/internal/builtin-plugins/network-manager/type-validation.ts Adjusts interval validation to treat scalar 0 as “interval mining disabled,” skipping the < 1000 ms guard.
packages/hardhat/test/internal/builtin-plugins/network-manager/hook-handlers/config.ts Adds test coverage for interval: 0 acceptance and preserves errors for interval ranges with a minimum below 1000.
.changeset/edr-mining-interval-zero.md Documents the patch release for the validation behavior change.

Comment on lines 619 to 622
// // Interval range with min >= 1000, allowBlocksWithSameTimestamp = false, no error
validationErrors = await validateNetworkUserConfig(
makeConfig([1000, 1000], true),
);
@kanej
kanej self-requested a review August 4, 2026 09:10
@kanej kanej added no docs needed This PR doesn't require links to documentation no peer bump needed labels Aug 4, 2026
The EDR network config validation rejects any `mining.interval` below
1000 ms unless `allowBlocksWithSameTimestamp` is set, to keep block
timestamps from diverging from clock time (NomicFoundation#6012).

A scalar `interval: 0` doesn't schedule any blocks at all though: it's
how interval mining is turned off (see
`hardhatMiningIntervalToEdrMiningInterval`), and it's the value the
config resolution defaults to. Writing it explicitly, as in
`mining: { auto: false, interval: 0 }`, made Hardhat fail to load the
config with a message about timestamps that can't apply.

An interval range still enables interval mining, so `[0, 5000]` remains
an error.
@Kropiunig
Kropiunig force-pushed the fix/edr-mining-interval-zero branch from fb88891 to 2ccd059 Compare August 7, 2026 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no docs needed This PR doesn't require links to documentation no peer bump needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants