Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customize Entire genesis Object in Chain Specification #93

Merged
merged 4 commits into from
Jun 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ You can see an example [here](config.json).
- `name`: Must be one of `alice`, `bob`, `charlie`, or `dave`.
- `wsPort`: The websocket port for this node.
- `port`: The TCP port for this node.
- `runtime_genesis_config`: A JSON object of the properties you want to modify from the genesis
- `genesis`: A JSON object of the properties you want to modify from the genesis
configuration. Non-specified properties will be unchanged from the original genesis configuration.

These variable are fed directly into the Polkadot binary and used to spawn a node:
Expand All @@ -71,23 +71,28 @@ These variable are fed directly into the Polkadot binary and used to spawn a nod
--<name> \
```

An example of `runtime_genesis_config` is:
An example of `genesis` is:

```json
"runtime_genesis_config": {
"parachainsConfiguration": {
"config": {
"validation_upgrade_frequency": 1,
"validation_upgrade_delay": 1
}
},
"palletCollective": {
"members": ["5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", "5DbKjhNLpqX3zqZdNBc9BGb4fHU1cRBaDhJUskrvkwfraDi6"]
"genesis": {
"runtime": {
"runtime_genesis_config": {
"parachainsConfiguration": {
"config": {
"validation_upgrade_frequency": 1,
"validation_upgrade_delay": 1
}
},
"palletCollective": {
"members": ["5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", "5DbKjhNLpqX3zqZdNBc9BGb4fHU1cRBaDhJUskrvkwfraDi6"]
}
},
"session_length_in_blocks": 10
}
}
```

All `runtime_genesis_config` properties can be found in the chainspec output:
All `genesis` properties can be found in the chainspec output:

```bash
./polkadot build-spec --chain=rococo-local --disable-default-bootnode
Expand Down
14 changes: 9 additions & 5 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@
"port": 30777
}
],
"runtime_genesis_config": {
"parachainsConfiguration": {
"config": {
"validation_upgrade_frequency": 1,
"validation_upgrade_delay": 1
"genesis": {
"runtime": {
"runtime_genesis_config": {
"parachainsConfiguration": {
"config": {
"validation_upgrade_frequency": 1,
"validation_upgrade_delay": 1
}
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ export async function run(config_dir: string, config: LaunchConfig) {
for (const node of config.relaychain.nodes) {
await addAuthority(`${chain}.json`, node.name);
}
if (config.relaychain.runtime_genesis_config) {
if (config.relaychain.genesis) {
await changeGenesisConfig(
`${chain}.json`,
config.relaychain.runtime_genesis_config
config.relaychain.genesis
);
}
await addParachainsToGenesis(config_dir, `${chain}.json`, config.parachains);
Expand Down
11 changes: 6 additions & 5 deletions src/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export async function addGenesisParachain(
}
}

// Update the `genesis` object in the chain specification.
export async function addGenesisHrmpChannel(
spec: string,
hrmpChannel: HrmpChannelsConfig
Expand Down Expand Up @@ -152,10 +153,10 @@ export async function changeGenesisConfig(spec: string, updates: any) {
let rawdata = fs.readFileSync(spec);
let chainSpec = JSON.parse(rawdata);

console.log(`\n⚙ Updating Parachains Genesis Configuration`);
console.log(`\n⚙ Updating Relay Chain Genesis Configuration`);

if (chainSpec.genesis.runtime.runtime_genesis_config) {
let config = chainSpec.genesis.runtime.runtime_genesis_config;
if (chainSpec.genesis) {
let config = chainSpec.genesis;
findAndReplaceConfig(updates, config);

let data = JSON.stringify(chainSpec, null, 2);
Expand All @@ -175,12 +176,12 @@ function findAndReplaceConfig(obj1: any, obj2: any) {
} else {
obj2[key] = obj1[key];
console.log(
` ✓ Updated Parachains Configuration [ ${key}: ${obj2[key]} ]`
` ✓ Updated Genesis Configuration [ ${key}: ${obj2[key]} ]`
);
}
} else {
console.error(
` ⚠ Bad Parachains Configuration [ ${key}: ${obj1[key]} ]`
` ⚠ Bad Genesis Configuration [ ${key}: ${obj1[key]} ]`
);
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export interface RelayChainConfig {
port: number;
flags?: string[];
}[];
runtime_genesis_config?: JSON;
genesis?: JSON;
}

export interface ChainSpec {
Expand Down