Why json for raw chainspec?

The Substrate documentation mentions the build-spec command to build raw chain specifications from custom format. Why was json chosen as the example output format? I do not feel like this file needs to be human-readable since it mainly contains key/value pairs in hexadecimal format and among them the embeded wasm runtime in hexadecimal as well.

But the raw chain spec still includes a few fields that will be useful for human inspection including chain id, para id etc.

1 Like

It makes it easy to interface with tooling. You can easily write script to inject funded genesis accounts or modify any other aspect of the genesis state.
Having it human readable definitely helps with that as well, for debugging and analysis.

1 Like

@xlc the fields you mention are some parts of the client spec for which json is relevant.

pub struct ChainSpec<G, E = NoExtension> {
	client_spec: ClientSpec<E>,
	genesis: GenesisSource<G>,
}

// ----

struct ClientSpec<E> {
	name: String,
	id: String,
	chain_type: ChainType,
	boot_nodes: Vec<MultiaddrWithPeerId>,
	telemetry_endpoints: Option<TelemetryEndpoints>,
	protocol_id: Option<String>,
	fork_id: Option<String>,
	properties: Option<Properties>,
	extensions: E,
	consensus_engine: (),
	genesis: serde::de::IgnoredAny,
	code_substitutes: BTreeMap<String, Bytes>,
}

What I was thinking about was more the genesis and code_substitutes parts and @OliverTY answer shows that it can be useful in his use cases.

You should be able to edit the bootnodes for example. This is useful when you publish a chainspec for others to use, and if the bootnodes change or are added to.

This Substrate stack exchange post can help to understand what you can change and what you can not.

1 Like

My question is not about json for chainspecs but json for raw chainspecs. I understand well the parts to edit (bootnodes from @chris and @ayush.mishra) and I do so, but not in the raw chainspecs. I generate these with the build-spec command that I customized with the load_spec() function for example.

2 Likes

You can still edit bootnodes etc in the raw chain spec. Maybe you are mixing there something up. The only thing that is β€œraw” is the genesis, aka that you see key value pairs in the chain spec that you can not easily read as a human. While this raw part could be some binary blob, it would not really make sense to have a binary blob in a json file?
And editing stuff like bootnodes, telemetry endpoints etc is still something that happens. If this all would be binary, you would then require some extra tool to do these changes etc, aka it would just complicate things.

If you are still confused, maybe you could give more details on what you are not getting.