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

Add support for chain spec modifier commands #909

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
96 changes: 44 additions & 52 deletions javascript/packages/orchestrator/src/chainSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -756,64 +756,56 @@ export async function customizePlainRelayChain(
specPath: string,
networkSpec: ComputedNetwork,
): Promise<void> {
try {
// Relay-chain spec customization logic
const plainRelayChainSpec = readAndParseChainSpec(specPath);
const keyType = specHaveSessionsKeys(plainRelayChainSpec)
? "session"
: "aura";

// Clear all defaults
clearAuthorities(specPath);

// add balances for nodes
await addBalances(specPath, networkSpec.relaychain.nodes);

// add authorities for nodes
const validatorKeys = [];
for (const node of networkSpec.relaychain.nodes) {
if (node.validator) {
validatorKeys.push(node.accounts.sr_stash.address);

if (keyType === "session") {
const key = getNodeKey(node);
await addAuthority(specPath, node, key);
} else {
await addAuraAuthority(specPath, node.name, node.accounts!);
await addGrandpaAuthority(specPath, node.name, node.accounts!);
}

await addStaking(specPath, node);
// Relay-chain spec customization logic
const plainRelayChainSpec = readAndParseChainSpec(specPath);
const keyType = specHaveSessionsKeys(plainRelayChainSpec)
? "session"
: "aura";

// Clear all defaults
clearAuthorities(specPath);

// add balances for nodes
await addBalances(specPath, networkSpec.relaychain.nodes);

// add authorities for nodes
const validatorKeys = [];
for (const node of networkSpec.relaychain.nodes) {
if (node.validator) {
validatorKeys.push(node.accounts.sr_stash.address);

if (keyType === "session") {
const key = getNodeKey(node);
await addAuthority(specPath, node, key);
} else {
await addAuraAuthority(specPath, node.name, node.accounts!);
await addGrandpaAuthority(specPath, node.name, node.accounts!);
}
}

if (networkSpec.relaychain.randomNominatorsCount) {
await generateNominators(
specPath,
networkSpec.relaychain.randomNominatorsCount,
networkSpec.relaychain.maxNominations,
validatorKeys,
);
await addStaking(specPath, node);
}
}

if (networkSpec.relaychain.genesis) {
await changeGenesisConfig(specPath, networkSpec.relaychain.genesis);
}
if (networkSpec.relaychain.randomNominatorsCount) {
await generateNominators(
specPath,
networkSpec.relaychain.randomNominatorsCount,
networkSpec.relaychain.maxNominations,
validatorKeys,
);
}

if (networkSpec.hrmp_channels) {
await addHrmpChannelsToGenesis(specPath, networkSpec.hrmp_channels);
}
if (networkSpec.relaychain.genesis) {
await changeGenesisConfig(specPath, networkSpec.relaychain.genesis);
}

// modify the plain chain spec with any custom commands
for (const cmd of networkSpec.relaychain.chainSpecModifierCommands) {
await runCommandWithChainSpec(specPath, cmd, networkSpec.configBasePath);
}
} catch (err) {
Copy link
Author

@Fahrrader Fahrrader Apr 20, 2023

Choose a reason for hiding this comment

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

Regarding the last commit, I believe we shouldn't let the process go on if a step in chain spec customization has failed. By removing the try-catch structure from customizePlainRelayChain, the error would go into the spawn's try-catch structure where it would print it out, dump the logs and exit the process. This was the way it was done prior to displacement of the relay's plain chain spec customization to chainSpec.ts, too.

console.log(
`\n ${decorators.red("Unexpected error: ")} \t ${decorators.bright(
err,
)}\n`,
);
if (networkSpec.hrmp_channels) {
await addHrmpChannelsToGenesis(specPath, networkSpec.hrmp_channels);
}

// modify the plain chain spec with any custom commands
for (const cmd of networkSpec.relaychain.chainSpecModifierCommands) {
await runCommandWithChainSpec(specPath, cmd, networkSpec.configBasePath);
}
}
export default {
Expand Down