Skip to content

feat: load chain spec from file via --chain-spec CLI flag#794

Merged
anshalshukla merged 13 commits into
blockblaz:mainfrom
markolazic01:feat/load-spec-from-config
May 7, 2026
Merged

feat: load chain spec from file via --chain-spec CLI flag#794
anshalshukla merged 13 commits into
blockblaz:mainfrom
markolazic01:feat/load-spec-from-config

Conversation

@markolazic01
Copy link
Copy Markdown
Contributor

feat: load chain spec from file via --chain-spec CLI flag

Closes #677

Problem

The chain spec was hardcoded as an inline JSON string in NodeRunner.init, meaning the chain name and preset couldn't be changed without recompiling.

Solution

Added a --chain-spec <path> CLI flag that loads the chain specification from a JSON file at startup. If the flag is not provided, the existing hardcoded default is used as a fallback.

Changes

  • Added chain-spec option to NodeCommand in main.zig with help text
  • Added chain_spec field to NodeOptions in node.zig
  • Wired the flag through buildStartOptions
  • In Node.init, reads the file via readFileAlloc when the flag is set, with error logging on failure

The issue also mentions loading from config YAML (# 2) and bundled preset names (# 3) as possible approaches — those could be follow-ups if desired.

@markolazic01 markolazic01 changed the title feat: load chain spec from file via --chain-spec CLI flag feat: load chain spec from file via --chain-spec CLI flag Apr 28, 2026
Comment thread pkgs/cli/src/node.zig
Comment on lines +189 to +194
const chain_spec = if (self.options.chain_spec) |path|
std.fs.cwd().readFileAlloc(allocator, path, 1024 * 1024) catch |err| {
self.logger.err("failed to load chain spec at '{s}': {any}", .{ path, err });
return err;
}
else
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think after reading from the file we should do some validation checks to confirm that all the fields are present and are of valid types or it might fall back to default values and might cause issues later.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback, will make sure to add those.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added the checks.

@ch4r10t33r ch4r10t33r marked this pull request as draft April 30, 2026 16:03
@markolazic01 markolazic01 marked this pull request as ready for review April 30, 2026 18:52
@markolazic01
Copy link
Copy Markdown
Contributor Author

Adapted to the std.Io change and formatting.

@ch4r10t33r
Copy link
Copy Markdown
Contributor

@markolazic01 can you pls resolve conflicts. We can merge this PR later today.

@markolazic01
Copy link
Copy Markdown
Contributor Author

@ch4r10t33r Resolved now

@anshalshukla anshalshukla merged commit 7b50ae7 into blockblaz:main May 7, 2026
9 checks passed
@zclawz zclawz mentioned this pull request May 7, 2026
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.

feat: load chain spec from config file/CLI arg instead of hardcoded inline JSON

3 participants