From 0230d053c42d209b8f582f0eddd2efb1a51b8f10 Mon Sep 17 00:00:00 2001 From: Valentin Fernandez Date: Wed, 24 Jan 2024 12:15:46 -0300 Subject: [PATCH 1/5] Add mainnet-local-v decorator --- .../src/chain-decorators/index.ts | 10 +++ .../src/chain-decorators/mainnet-local-v.ts | 84 +++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 javascript/packages/orchestrator/src/chain-decorators/mainnet-local-v.ts diff --git a/javascript/packages/orchestrator/src/chain-decorators/index.ts b/javascript/packages/orchestrator/src/chain-decorators/index.ts index 9f92e4341..9cc28a3f4 100644 --- a/javascript/packages/orchestrator/src/chain-decorators/index.ts +++ b/javascript/packages/orchestrator/src/chain-decorators/index.ts @@ -10,6 +10,7 @@ enum CHAIN { Mangata = "mangata", Generic = "generic", LocalV = "local_v", + MainnetLocalV = "mainnet_local_v", } interface Decorator { @@ -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"; @@ -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; } @@ -99,6 +102,12 @@ const localVDecorators: Decorator = Object.keys(local_v).reduce((memo, fn) => { return memo; }, Object.create({})); +const MainnetLocalVDecorators: Decorator = Object.keys(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, @@ -110,6 +119,7 @@ const decorators: { [para in CHAIN]: { [fn: string]: Function } } = { oak: oakDecorators, mangata: mangataDecorators, local_v: localVDecorators, + mainnet_local_v: localVDecorators, generic: {}, }; diff --git a/javascript/packages/orchestrator/src/chain-decorators/mainnet-local-v.ts b/javascript/packages/orchestrator/src/chain-decorators/mainnet-local-v.ts new file mode 100644 index 000000000..b5668f4b4 --- /dev/null +++ b/javascript/packages/orchestrator/src/chain-decorators/mainnet-local-v.ts @@ -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 { + 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, +}; From 22d33d16581c4068b06f1504e323e4bcf873945c Mon Sep 17 00:00:00 2001 From: valentinfernandez1 Date: Wed, 24 Jan 2024 15:22:03 +0000 Subject: [PATCH 2/5] Fix nix hash --- flake-module.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake-module.nix b/flake-module.nix index 4b51889c0..a77b06b9b 100644 --- a/flake-module.nix +++ b/flake-module.nix @@ -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 From 7cdd3ecb3fed3c2f62c2a6a3201bb7aa1a6a7579 Mon Sep 17 00:00:00 2001 From: Valentin Fernandez <33705477+valentinfernandez1@users.noreply.github.com> Date: Wed, 24 Jan 2024 12:29:49 -0300 Subject: [PATCH 3/5] fix decorator Co-authored-by: Javier Viola --- javascript/packages/orchestrator/src/chain-decorators/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javascript/packages/orchestrator/src/chain-decorators/index.ts b/javascript/packages/orchestrator/src/chain-decorators/index.ts index 9cc28a3f4..2be155bde 100644 --- a/javascript/packages/orchestrator/src/chain-decorators/index.ts +++ b/javascript/packages/orchestrator/src/chain-decorators/index.ts @@ -102,7 +102,7 @@ const localVDecorators: Decorator = Object.keys(local_v).reduce((memo, fn) => { return memo; }, Object.create({})); -const MainnetLocalVDecorators: Decorator = Object.keys(local_v).reduce((memo, fn) => { +const MainnetLocalVDecorators: Decorator = Object.keys(mainnet_local_v).reduce((memo, fn) => { memo[fn] = (local_v as Decorator)[fn]; return memo; }, Object.create({})); From f261dd0bb2955729adf55081f5fe6191f6ca1ca9 Mon Sep 17 00:00:00 2001 From: Javier Viola Date: Wed, 24 Jan 2024 12:30:16 -0300 Subject: [PATCH 4/5] Update javascript/packages/orchestrator/src/chain-decorators/index.ts --- javascript/packages/orchestrator/src/chain-decorators/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/javascript/packages/orchestrator/src/chain-decorators/index.ts b/javascript/packages/orchestrator/src/chain-decorators/index.ts index 2be155bde..e3d9f4d41 100644 --- a/javascript/packages/orchestrator/src/chain-decorators/index.ts +++ b/javascript/packages/orchestrator/src/chain-decorators/index.ts @@ -106,7 +106,6 @@ const MainnetLocalVDecorators: Decorator = Object.keys(mainnet_local_v).reduce(( memo[fn] = (local_v as Decorator)[fn]; return memo; }, Object.create({})); -); const decorators: { [para in CHAIN]: { [fn: string]: Function } } = { moonbeam: moonbeamDecorators, From 54323af838dd44b4871bcb2e19bfbc6ad43fc41a Mon Sep 17 00:00:00 2001 From: Javier Viola <363911+pepoviola@users.noreply.github.com> Date: Wed, 24 Jan 2024 12:38:14 -0300 Subject: [PATCH 5/5] lint --- .../orchestrator/src/chain-decorators/index.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/javascript/packages/orchestrator/src/chain-decorators/index.ts b/javascript/packages/orchestrator/src/chain-decorators/index.ts index e3d9f4d41..1cd6978b1 100644 --- a/javascript/packages/orchestrator/src/chain-decorators/index.ts +++ b/javascript/packages/orchestrator/src/chain-decorators/index.ts @@ -102,10 +102,13 @@ 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 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, @@ -118,7 +121,7 @@ const decorators: { [para in CHAIN]: { [fn: string]: Function } } = { oak: oakDecorators, mangata: mangataDecorators, local_v: localVDecorators, - mainnet_local_v: localVDecorators, + mainnet_local_v: MainnetLocalVDecorators, generic: {}, };