Skip to content

fix: respect CFG_PRESET and CHAIN env vars in wizards generate-keys command#365

Merged
chrisferry merged 7 commits into
midnightntwrk:mainfrom
riusricardo:fix-generate-keys
Jan 9, 2026
Merged

fix: respect CFG_PRESET and CHAIN env vars in wizards generate-keys command#365
chrisferry merged 7 commits into
midnightntwrk:mainfrom
riusricardo:fix-generate-keys

Conversation

@riusricardo

@riusricardo riusricardo commented Dec 11, 2025

Copy link
Copy Markdown
Contributor

Problem

The initial fix PR: #187 introduced a regression where running wizards generate-keys without any configuration would always panic with called Option::unwrap() on a None value.

The wizards generate-keys command was panicking with called Option::unwrap() on a None value when run without explicitly setting configuration files. This occurred because create_chain_spec() was calling load_spec("") with an empty string, which attempted to load custom chainspec configuration files that don't exist in a default setup.

Solution

Modified create_chain_spec() to respect the existing configuration system:

  • Use the chain value from SubstrateCfg (configurable via CHAIN env var or config preset)
  • Default to "dev" when no chain is specified
// Dev environment (default)
./midnight-node wizards generate-keys

// Or explicitly
CFG_PRESET=dev ./midnight-node wizards generate-keys

// QA network
CFG_PRESET=qanet ./midnight-node wizards generate-keys

// Preview network  
CFG_PRESET=preview ./midnight-node wizards generate-keys

// Using a named chain (dev, local)
CHAIN=local ./midnight-node wizards generate-keys

// Using a path to a chain-spec file
CHAIN=res/node-dev-01/chain-spec-raw.json ./midnight-node wizards generate-keys

Note: When deploying the midnight-node binary to a different location, the res directory must be copied alongside it. This directory contains required configuration files (cfg) and mock data (mock-bridge-data, genesis, dev) that the binary expects to find relative to its working directory.

Fixes regression introduced in PR midnightntwrk#187 where wizards generate-keys
command would panic when no custom chain specification was provided.

The original fix addressed the issue for explicit --chain-id usage
but introduced a new panic by calling load_spec("") when using
configuration presets (CFG_PRESET environment variable).

This change ensures the command respects the configuration system:
- Uses configured chain ID from SubstrateCfg
- Falls back to "dev" when no configuration is specified
- Maintains compatibility with all existing workflows:
  * CFG_PRESET=dev
  * CHAIN=local
  * CHAIN=path/to/custom/chainspec.json
  * Default behavior (no environment variables)
@riusricardo riusricardo requested a review from a team as a code owner December 11, 2025 23:23
Comment thread changes/changed/fix-wizard-generate-keys.md Outdated
@gilescope

Copy link
Copy Markdown
Contributor

@justinfrevert can you review and approve #337 if you're happy so that we don't have such a sea of red from forked PRs please?

@riusricardo

Copy link
Copy Markdown
Contributor Author

@justinfrevert @gilescope please merge this PR. It is very simple and we need the fix in order to have working docs.

@chrisferry chrisferry merged commit cf94ac2 into midnightntwrk:main Jan 9, 2026
29 of 35 checks passed
gilescope pushed a commit that referenced this pull request Apr 8, 2026
m2ux added a commit that referenced this pull request Apr 23, 2026
Signed-off-by: Mike Clay <mike.clay@shielded.io>
m2ux added a commit that referenced this pull request Apr 23, 2026
Signed-off-by: Mike Clay <mike.clay@shielded.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants