Skip to content

pipe num-validators through local-env cli - #2008

Open
justinfrevert wants to merge 6 commits into
mainfrom
local-env-cli-num-validators
Open

pipe num-validators through local-env cli#2008
justinfrevert wants to merge 6 commits into
mainfrom
local-env-cli-num-validators

Conversation

@justinfrevert

@justinfrevert justinfrevert commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Overview

--num-validators <count> lets a well-known network fork come up with fewer mock
validators than the network's Compose topology defines, instead of always
materializing the full set. Smaller forks start faster and fit on a laptop, which
is what most fork testing actually needs.

The flag is threaded through every local-env command that brings up or rolls a
forked network: run, image-upgrade, full-upgrade, and the runtime-upgrade
path, plus the fork-network CI workflow.

  1. When forking from a snapshot the count drives mock-authorities convert (how
    many validator keysets get synthesized) and a generated Compose override that
    starts only the selected node* services, parking the rest behind a profile
    this tooling never activates.
  2. The active selection is persisted in the generated override
    (x-midnight-mock), so later restarts can omit the flag and reuse it, and
    verify-finality probes the validators that are actually running rather than
    the full configured topology.
  3. The count must be a positive integer no larger than mock.validatorServices.
    Changing it requires --from-snapshot so the authority set and seeds can be
    regenerated; it is rejected on reuse runs, in --from-genesis mode, and for
    the standalone local-env stack, whose topology and keys are fixed.

Also fixes a GRANDPA finality stall found while testing this: the fork tooling
defaulted to mock-authorities images that predate the client-side aux-storage
rewrite, which deadlocks the GRANDPA voter on a >=2.0.0 runtime. Details in
changes/node/changed/local-env-fork-grandpa-finality-fix.md. That stall was not
caused by the reduced validator set.

🗹 TODO before merging

  • Ready

📌 Submission Checklist

  • All commits are signed off (git commit -s) for the DCO
  • Changes are backward-compatible (or flagged if breaking)
  • Pull request description explains why the change is needed
  • Self-reviewed the diff
  • I have included a change file, or skipped for this reason:
  • If the changes introduce a new feature, I have bumped the node minor version
  • Update documentation (if relevant)
  • Updated AGENTS.md if build commands, architecture, or workflows changed
  • No new todos introduced

🧪 Testing Evidence

Unit tests cover the selection resolver, the persisted-selection round trip, the
disabled-service profile, and the stale-override cleanup
(local-environment/src/lib/mockValidatorSelection.test.ts).

Manually verified by forking devnet (2.0.0-rc.3) from a snapshot with
--num-validators 3: all three validators author and finalize, and the client
and runtime GRANDPA set-ids match.

  • Additional tests are provided (if possible)

🔱 Fork Strategy

  • N/A

Links

Consumer of this tooling: midnightntwrk/midnight-indexer#1364

Signed-off-by: Justin Frevert <justinfrevert@gmail.com>
@justinfrevert
justinfrevert marked this pull request as ready for review August 13, 2026 22:23
@justinfrevert
justinfrevert requested a review from a team as a code owner August 13, 2026 22:23
…idators

Signed-off-by: Justin Frevert <justinfrevert@gmail.com>

# Conflicts:
#	local-environment/README.md
#	local-environment/package.json
#	local-environment/src/index.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a0aa824fe8

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +60 to +62
const selection = readMockValidatorSelection(
mockOverridePath(path.dirname(composeFile), network),
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Ignore stale mock overrides for finality checks

When a network was previously forked with a reduced validator count, this now reads the persisted <network>.mock.override.yaml and filters the probe list whenever that file exists. If the same checkout is later started with run <network> --from-genesis, that path only layers the generated genesis override and leaves the old mock override unused on disk, so verify-finality <network> can report success after checking only the stale subset while the other genesis validators are stalled. Gate this on the currently used fork-mode compose override, or ignore/remove stale mock metadata for from-genesis/base-compose runs.

Useful? React with 👍 / 👎.

Signed-off-by: Justin Frevert <justinfrevert@gmail.com>
Signed-off-by: Justin Frevert <justinfrevert@gmail.com>
Assisted-by: Claude:claude-opus-4.8
Signed-off-by: Justin Frevert <justinfrevert@gmail.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ba8a5ea247

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +172 to +178
if (persistedSelection?.disabledValidatorServices.length) {
await removeDockerComposeServices(
{
composeFile,
env,
profiles: runOptions.profiles,
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Stop active validators before replacing their data

When --num-validators is used to change an existing running fork, this only stops the newly disabled services, and it does so after restoreSnapshot has deleted and replaced every bind-mounted data directory and after mock-authorities has rewritten them. Validators retained in the new selection therefore remain alive with handles to the old database; because their service configuration is otherwise unchanged, the subsequent compose up need not recreate them, leaving retained nodes on the old state while newly enabled nodes use the regenerated snapshot. Stop or force-recreate all validator containers before restoring and converting the snapshot.

Useful? React with 👍 / 👎.

@justinfrevert justinfrevert added the bot:ai-assisted Authored or substantially edited by an AI agent label Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:ai-assisted Authored or substantially edited by an AI agent skip-changes-check-issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants