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

[DNM] wip, support windows #1206

Closed
wants to merge 1 commit into from
Closed
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
1 change: 0 additions & 1 deletion javascript/packages/orchestrator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
"libp2p-crypto": "^0.21.2",
"minimatch": "^9.0.3",
"mocha": "^10.2.0",
"napi-maybe-compressed-blob": "^0.0.11",
"peer-id": "^0.16.0",
"tmp-promise": "^3.0.3",
"typescript": "^5.1.6",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ApiPromise, Keyring } from "@polkadot/api";
import { blake2AsHex, cryptoWaitReady } from "@polkadot/util-crypto";
import { promises as fsPromises } from "fs";
import { compress, decompress } from "napi-maybe-compressed-blob";
//import { compress, decompress } from "napi-maybe-compressed-blob";
import { DEFAULT_INDIVIDUAL_TEST_TIMEOUT } from "../constants";
const debug = require("debug")("zombie::js-helpers::chain-upgrade");

Check warning on line 6 in javascript/packages/orchestrator/src/jsapi-helpers/chainUpgrade.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'debug' is assigned a value but never used

Check warning on line 6 in javascript/packages/orchestrator/src/jsapi-helpers/chainUpgrade.ts

View workflow job for this annotation

GitHub Actions / build (19.x)

'debug' is assigned a value but never used

Check warning on line 6 in javascript/packages/orchestrator/src/jsapi-helpers/chainUpgrade.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'debug' is assigned a value but never used

export async function chainUpgradeFromUrl(
api: ApiPromise,
Expand Down Expand Up @@ -45,29 +45,30 @@
// and can be ignored in the general case.
// The wasm format consists of bunch of sections. Here we just slap a custom section to the end.
export async function chainCustomSectionUpgrade(
api: ApiPromise,

Check warning on line 48 in javascript/packages/orchestrator/src/jsapi-helpers/chainUpgrade.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'api' is defined but never used

Check warning on line 48 in javascript/packages/orchestrator/src/jsapi-helpers/chainUpgrade.ts

View workflow job for this annotation

GitHub Actions / build (19.x)

'api' is defined but never used

Check warning on line 48 in javascript/packages/orchestrator/src/jsapi-helpers/chainUpgrade.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'api' is defined but never used
): Promise<string> {
const code: any = await api.rpc.state.getStorage(":code");
const codeHex = code.toString().slice(2);
const codeBuf = Buffer.from(hexToBytes(codeHex));
const decompressed = decompress(codeBuf);

// add a custom section
// Same as echo -n -e "\x00\x07\x05\x64\x75\x6D\x6D\x79\x0A" >> file.wasm
const customSection = [0x00, 0x07, 0x05, 0x64, 0x75, 0x6d, 0x6d, 0x79, 0x0a];
const withCustomSectionCode = Buffer.concat([
decompressed,
Buffer.from(customSection),
]);

// compress again
const compressed = compress(withCustomSectionCode);
const hash = blake2AsHex(compressed);
debug(`New compressed hash : ${hash}`);

await performChainUpgrade(api, compressed.toString("hex"));

return hash;
// const code: any = await api.rpc.state.getStorage(":code");
// const codeHex = code.toString().slice(2);
// const codeBuf = Buffer.from(hexToBytes(codeHex));
// const decompressed = decompress(codeBuf);

// // add a custom section
// // Same as echo -n -e "\x00\x07\x05\x64\x75\x6D\x6D\x79\x0A" >> file.wasm
// const customSection = [0x00, 0x07, 0x05, 0x64, 0x75, 0x6d, 0x6d, 0x79, 0x0a];
// const withCustomSectionCode = Buffer.concat([
// decompressed,
// Buffer.from(customSection),
// ]);

// // compress again
// const compressed = compress(withCustomSectionCode);
// const hash = blake2AsHex(compressed);
// debug(`New compressed hash : ${hash}`);

// await performChainUpgrade(api, compressed.toString("hex"));

// return hash;
return "NOT supported for windows version"

Check failure on line 71 in javascript/packages/orchestrator/src/jsapi-helpers/chainUpgrade.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Insert `;`

Check failure on line 71 in javascript/packages/orchestrator/src/jsapi-helpers/chainUpgrade.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Missing semicolon

Check failure on line 71 in javascript/packages/orchestrator/src/jsapi-helpers/chainUpgrade.ts

View workflow job for this annotation

GitHub Actions / build (19.x)

Insert `;`

Check failure on line 71 in javascript/packages/orchestrator/src/jsapi-helpers/chainUpgrade.ts

View workflow job for this annotation

GitHub Actions / build (19.x)

Missing semicolon

Check failure on line 71 in javascript/packages/orchestrator/src/jsapi-helpers/chainUpgrade.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Insert `;`

Check failure on line 71 in javascript/packages/orchestrator/src/jsapi-helpers/chainUpgrade.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Missing semicolon
}

export async function validateRuntimeCode(
Expand All @@ -80,7 +81,7 @@
let done;
while (!done) {
const currentHash = await api.query.paras.currentCodeHash(paraId);
console.log(`parachain ${paraId} current code hash : ${currentHash}`);
console.log(`parachain ${paraId} current code hash : ${currentHash}, desired hash: ${hash}`);

Check failure on line 84 in javascript/packages/orchestrator/src/jsapi-helpers/chainUpgrade.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Replace ``parachain·${paraId}·current·code·hash·:·${currentHash},·desired·hash:·${hash}`` with `⏎········`parachain·${paraId}·current·code·hash·:·${currentHash},·desired·hash:·${hash}`,⏎······`

Check failure on line 84 in javascript/packages/orchestrator/src/jsapi-helpers/chainUpgrade.ts

View workflow job for this annotation

GitHub Actions / build (19.x)

Replace ``parachain·${paraId}·current·code·hash·:·${currentHash},·desired·hash:·${hash}`` with `⏎········`parachain·${paraId}·current·code·hash·:·${currentHash},·desired·hash:·${hash}`,⏎······`

Check failure on line 84 in javascript/packages/orchestrator/src/jsapi-helpers/chainUpgrade.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Replace ``parachain·${paraId}·current·code·hash·:·${currentHash},·desired·hash:·${hash}`` with `⏎········`parachain·${paraId}·current·code·hash·:·${currentHash},·desired·hash:·${hash}`,⏎······`
if (hash === currentHash.toString()) break;
// wait 2 secs between checks
await new Promise((resolve) => setTimeout(resolve, 2000));
Expand Down Expand Up @@ -137,7 +138,7 @@
}

/// Internal
function hexToBytes(hex: any) {

Check warning on line 141 in javascript/packages/orchestrator/src/jsapi-helpers/chainUpgrade.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'hexToBytes' is defined but never used

Check warning on line 141 in javascript/packages/orchestrator/src/jsapi-helpers/chainUpgrade.ts

View workflow job for this annotation

GitHub Actions / build (19.x)

'hexToBytes' is defined but never used

Check warning on line 141 in javascript/packages/orchestrator/src/jsapi-helpers/chainUpgrade.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'hexToBytes' is defined but never used
const bytes = [];
for (let c = 0; c < hex.length; c += 2)
bytes.push(parseInt(hex.substr(c, 2), 16));
Expand Down
25 changes: 13 additions & 12 deletions javascript/packages/orchestrator/src/orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import { Client } from "./providers/client";
import { KubeClient } from "./providers/k8s/kubeClient";
import { spawnNode } from "./spawner";
import { setSubstrateCliArgsVersion } from "./substrateCliArgsHelper";
import path from "path";

const debug = require("debug")("zombie");

Expand Down Expand Up @@ -144,14 +145,14 @@ export async function start(
}
}

const localMagicFilepath = `${tmpDir.path}/finished.txt`;
const localMagicFilepath = `${tmpDir.path}${path.sep}finished.txt`;
// Create MAGIC file to stop temp/init containers
fs.openSync(localMagicFilepath, "w");

// Define chain name and file name to use.
const chainSpecFileName = `${networkSpec.relaychain.chain}.json`;
const chainName = networkSpec.relaychain.chain;
const chainSpecFullPath = `${tmpDir.path}/${chainSpecFileName}`;
const chainSpecFullPath = `${tmpDir.path}${path.sep}${chainSpecFileName}`;
const chainSpecFullPathPlain = chainSpecFullPath.replace(
".json",
"-plain.json",
Expand Down Expand Up @@ -201,7 +202,7 @@ export async function start(
process.exit(1);
}

const zombieWrapperLocalPath = `${tmpDir.path}/${ZOMBIE_WRAPPER}`;
const zombieWrapperLocalPath = `${tmpDir.path}${path.sep}${ZOMBIE_WRAPPER}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

windows work well with /. i doubt there is any code which does not.

const zombieWrapperContent = await fs.promises.readFile(zombieWrapperPath);
await fs.promises.writeFile(
zombieWrapperLocalPath,
Expand Down Expand Up @@ -251,7 +252,7 @@ export async function start(
network.chainId = chainSpecContent.id;

const parachainFilesPromiseGenerator = async (parachain: Parachain) => {
const parachainFilesPath = `${tmpDir.path}/${parachain.name}`;
const parachainFilesPath = `${tmpDir.path}${path.sep}${parachain.name}`;
await makeDir(parachainFilesPath);
await generateParachainFiles(
namespace,
Expand All @@ -272,9 +273,9 @@ export async function start(
await series(parachainPromiseGenerators, opts.spawnConcurrency);

for (const parachain of networkSpec.parachains) {
const parachainFilesPath = `${tmpDir.path}/${parachain.name}`;
const stateLocalFilePath = `${parachainFilesPath}/${GENESIS_STATE_FILENAME}`;
const wasmLocalFilePath = `${parachainFilesPath}/${GENESIS_WASM_FILENAME}`;
const parachainFilesPath = `${tmpDir.path}${path.sep}${parachain.name}`;
const stateLocalFilePath = `${parachainFilesPath}${path.sep}${GENESIS_STATE_FILENAME}`;
const wasmLocalFilePath = `${parachainFilesPath}${path.sep}${GENESIS_WASM_FILENAME}`;
if (parachain.addToGenesis && !relayChainSpecIsRaw)
await addParachainToGenesis(
chainSpecFullPathPlain,
Expand Down Expand Up @@ -395,7 +396,7 @@ export async function start(
// cache the chainSpec with bootnodes
const fileBuffer = await fs.promises.readFile(chainSpecFullPath);
const fileHash = getSha256(fileBuffer.toString());
const parts = chainSpecFullPath.split("/");
const parts = chainSpecFullPath.split(path.sep);
const fileName = parts[parts.length - 1];
await (client as KubeClient).uploadToFileserver(
chainSpecFullPath,
Expand Down Expand Up @@ -436,13 +437,13 @@ export async function start(
for (const parachain of networkSpec.parachains) {
if (!parachain.addToGenesis && parachain.registerPara) {
// register parachain on a running network
const basePath = `${tmpDir.path}/${parachain.name}`;
const basePath = `${tmpDir.path}${path.sep}${parachain.name}`;
// ensure node is up.
await nodeChecker(network.relay[0]);
await registerParachain({
id: parachain.id,
wasmPath: `${basePath}/${GENESIS_WASM_FILENAME}`,
statePath: `${basePath}/${GENESIS_STATE_FILENAME}`,
wasmPath: `${basePath}${path.sep}${GENESIS_WASM_FILENAME}`,
statePath: `${basePath}${path.sep}${GENESIS_STATE_FILENAME}`,
apiUrl: network.relay[0].wsUri,
onboardAsParachain: parachain.onboardAsParachain,
});
Expand Down Expand Up @@ -517,7 +518,7 @@ export async function start(
// clean cache before dump the info.
network.cleanMetricsCache();
await fs.promises.writeFile(
`${tmpDir.path}/zombie.json`,
`${tmpDir.path}${path.sep}zombie.json`,
JSON.stringify(network),
);

Expand Down
13 changes: 7 additions & 6 deletions javascript/packages/orchestrator/src/paras.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { decorate } from "./paras-decorators";
import { Providers } from "./providers";
import { getClient } from "./providers/client";
import { Node, Parachain, ZombieRole, fileMap } from "./types";
import path from "path";

const debug = require("debug")("zombie::paras");

Expand Down Expand Up @@ -50,8 +51,8 @@ export async function generateParachainFiles(
const GENESIS_STATE_FILENAME_WITH_ID = `${GENESIS_STATE_FILENAME}-${parachain.id}`;
const GENESIS_WASM_FILENAME_WITH_ID = `${GENESIS_WASM_FILENAME}-${parachain.id}`;

const stateLocalFilePath = `${parachainFilesPath}/${GENESIS_STATE_FILENAME}`;
const wasmLocalFilePath = `${parachainFilesPath}/${GENESIS_WASM_FILENAME}`;
const stateLocalFilePath = `${parachainFilesPath}${path.sep}${GENESIS_STATE_FILENAME}`;
const wasmLocalFilePath = `${parachainFilesPath}${path.sep}${GENESIS_WASM_FILENAME}`;
const client = getClient();

const { setupChainSpec, getChainSpecRaw } = Providers.get(
Expand All @@ -64,12 +65,12 @@ export async function generateParachainFiles(
}-${relayChainName}`;
const chainSpecFileName = `${chainName}.json`;

const chainSpecFullPathPlain = `${tmpDir}/${chainName}-plain.json`;
const chainSpecFullPathPlain = `${tmpDir}${path.sep}${chainName}-plain.json`;

if (parachain.cumulusBased) {
// need to create the parachain spec
// file name template is [para chain-]<para name>-<relay chain>
const relayChainSpecFullPathPlain = `${tmpDir}/${relayChainName}-plain.json`;
const relayChainSpecFullPathPlain = `${tmpDir}${path.sep}${relayChainName}-plain.json`;

// Check if the chain-spec file is provided.
if (parachain.chainSpecPath) {
Expand All @@ -95,7 +96,7 @@ export async function generateParachainFiles(
);
}

chainSpecFullPath = `${tmpDir}/${chainSpecFileName}`;
chainSpecFullPath = `${tmpDir}${path.sep}${chainSpecFileName}`;
if (!(await isRawSpec(chainSpecFullPathPlain))) {
// fields
const plainData = readAndParseChainSpec(chainSpecFullPathPlain);
Expand Down Expand Up @@ -146,7 +147,7 @@ export async function generateParachainFiles(
if (parachain.chain)
fs.copyFileSync(
chainSpecFullPathPlain,
`${tmpDir}/${parachain.chain}-${parachain.name}-plain.json`,
`${tmpDir}${path.sep}${parachain.chain}-${parachain.name}-plain.json`,
);
// generate the raw chain spec
await getChainSpecRaw(
Expand Down
2 changes: 2 additions & 0 deletions javascript/packages/orchestrator/src/test-runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Providers } from "../providers";
import { LaunchConfig, TestDefinition } from "../types";
import assertions from "./assertions";
import commands from "./commands";
import os from "os";

const DEFAULT_GLOBAL_TIMEOUT = 1200; // 20 mins

Expand Down Expand Up @@ -64,6 +65,7 @@ export async function run(
const possiblePaths = [
".",
"..",
`${os.homedir()}/.kube`,
`${process.env.HOME}/.kube`,
"/etc/zombie-net",
];
Expand Down
3 changes: 2 additions & 1 deletion javascript/packages/utils/src/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import yaml from "yaml";
import { decorators } from "./colors";
import { RelativeLoader } from "./nunjucksRelativeLoader";
import { LaunchConfig } from "./types";
import os from "os";

export interface LocalJsonFileContentIF {
apiVersion: string;
Expand Down Expand Up @@ -71,7 +72,7 @@ export async function makeDir(dir: string, recursive = false) {
export function getCredsFilePath(credsFile: string): string | undefined {
if (fs.existsSync(credsFile)) return credsFile;

const possiblePaths = [".", "..", `${process.env.HOME}/.kube`];
const possiblePaths = [".", "..", `${os.homedir()}/.kube`];
const credsFileExistInPath: string | undefined = possiblePaths.find(
(path) => {
const t = `${path}/${credsFile}`;
Expand Down
Loading