fix: respect CFG_PRESET and CHAIN env vars in wizards generate-keys command#365
Merged
Merged
Conversation
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)
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? |
gilescope
approved these changes
Dec 15, 2025
Contributor
Author
|
@justinfrevert @gilescope please merge this PR. It is very simple and we need the fix in order to have working docs. |
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The initial fix PR: #187 introduced a regression where running
wizards generate-keyswithout any configuration would always panic withcalled Option::unwrap()on aNonevalue.The
wizards generate-keyscommand was panicking withcalled Option::unwrap() on a None valuewhen run without explicitly setting configuration files. This occurred becausecreate_chain_spec()was callingload_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:chainvalue fromSubstrateCfg(configurable viaCHAINenv var or config preset)"dev"when no chain is specifiedNote: 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.