Skip to content

Commit

Permalink
Add para to registry (#1699)
Browse files Browse the repository at this point in the history
* Add mainnet-local-v decorator

* Fix nix hash

* fix decorator

Co-authored-by: Javier Viola <javier@parity.io>

* Update javascript/packages/orchestrator/src/chain-decorators/index.ts

* lint

---------

Co-authored-by: valentinfernandez1 <valentinfernandez1@users.noreply.github.com>
Co-authored-by: Javier Viola <javier@parity.io>
Co-authored-by: Javier Viola <363911+pepoviola@users.noreply.github.com>
  • Loading branch information
4 people authored Jan 24, 2024
1 parent 7563e5c commit 19a02a1
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 1 deletion.
2 changes: 1 addition & 1 deletion flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
...
}: let
# this change on each change of dependencies, unfortunately this hash not yet automatically updated from SRI of package.lock
npmDepsHash = "sha256-83mDJ4YCAg8AZjwqtyqx6BULa20ySxcO8xBvSAvB78c=";
npmDepsHash = "sha256-YupR/AnxHvBihLvdcWmUHRknW3ReQ01YDd/5uawRuSg=";
####

# there is officia polkadot on nixpkgs, but it has no local rococo wasm to run
Expand Down
12 changes: 12 additions & 0 deletions javascript/packages/orchestrator/src/chain-decorators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ enum CHAIN {
Mangata = "mangata",
Generic = "generic",
LocalV = "local_v",
MainnetLocalV = "mainnet_local_v",
}

interface Decorator {
Expand All @@ -24,6 +25,7 @@ import bifrost from "./bifrost";
import efinity from "./efinity";
import equilibrium from "./equilibrium";
import local_v from "./local-v";
import mainnet_local_v from "./mainnet-local-v";
import mangata from "./mangata";
import moonbeam from "./moonbeam";
import oak from "./oak";
Expand All @@ -40,6 +42,7 @@ function whichChain(chain: string): CHAIN {
if (/oak|turing|neumann/.test(chain)) return CHAIN.Oak;
if (/mangata/.test(chain)) return CHAIN.Mangata;
if (/local-v/.test(chain)) return CHAIN.LocalV;
if (/mainnet-local-v/.test(chain)) return CHAIN.MainnetLocalV;

return CHAIN.Generic;
}
Expand Down Expand Up @@ -99,6 +102,14 @@ const localVDecorators: Decorator = Object.keys(local_v).reduce((memo, fn) => {
return memo;
}, Object.create({}));

const MainnetLocalVDecorators: Decorator = Object.keys(mainnet_local_v).reduce(
(memo, fn) => {
memo[fn] = (local_v as Decorator)[fn];
return memo;
},
Object.create({}),
);

const decorators: { [para in CHAIN]: { [fn: string]: Function } } = {
moonbeam: moonbeamDecorators,
asset_hub_polkadot: assetHubPolkadotDecorators,
Expand All @@ -110,6 +121,7 @@ const decorators: { [para in CHAIN]: { [fn: string]: Function } } = {
oak: oakDecorators,
mangata: mangataDecorators,
local_v: localVDecorators,
mainnet_local_v: MainnetLocalVDecorators,
generic: {},
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { Keyring } from "@polkadot/api";
import { u8aToHex } from "@polkadot/util";
import { cryptoWaitReady } from "@polkadot/util-crypto";
import { CreateLogTable, decorators } from "@zombienet/utils";
import {
GenesisNodeKey,
getRuntimeConfig,
readAndParseChainSpec,
writeChainSpec,
} from "../chainSpec";
import { generateKeyForNode as _generateKeyForNode } from "../keys";
import { Node } from "../sharedTypes";

async function generateKeyForNode(nodeName?: string): Promise<any> {
const keys = await _generateKeyForNode(nodeName);

await cryptoWaitReady();

const eth_keyring = new Keyring({ type: "ethereum" });
const eth_account = eth_keyring.createFromUri(
`${keys.mnemonic}/m/44'/60'/0'/0/0`,
);

keys.eth_account = {
address: eth_account.address,
publicKey: u8aToHex(eth_account.publicKey),
};

return keys;
}

export function getNodeKey(node: Node): GenesisNodeKey {
try {
const { sr_account, eth_account } = node.accounts;

const key: GenesisNodeKey = [
eth_account.address,
eth_account.address,
{
aura: sr_account.address,
},
];

return key;
} catch (err) {
console.error(
`\n${decorators.red(`Fail to generate key for node: ${node}`)}`,
);
throw err;
}
}

export async function addCollatorSelection(specPath: string, node: Node) {
try {
const chainSpec = readAndParseChainSpec(specPath);
const runtimeConfig = getRuntimeConfig(chainSpec);
if (!runtimeConfig?.collatorSelection?.invulnerables) return;

const { eth_account } = node.accounts;

runtimeConfig.collatorSelection.invulnerables.push(eth_account.address);

new CreateLogTable({
colWidths: [30, 20, 70],
}).pushToPrint([
[
decorators.cyan("👤 Added CollatorSelection "),
decorators.green(node.name),
decorators.magenta(eth_account.address),
],
]);

writeChainSpec(specPath, chainSpec);
} catch (err) {
console.error(`\n${decorators.red(`Fail to add collator: ${node}`)}`);
throw err;
}
}

export default {
getNodeKey,
generateKeyForNode,
addCollatorSelection,
};

0 comments on commit 19a02a1

Please sign in to comment.