Skip to content

Commit

Permalink
Customize Entire genesis Object in Chain Specification (#93)
Browse files Browse the repository at this point in the history
* Go higher up in custom genesis config

* update name
  • Loading branch information
shawntabrizi authored Jun 7, 2021
1 parent 8222452 commit fb4c00c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 25 deletions.
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

0 comments on commit fb4c00c

Please sign in to comment.