Skip to content

Commit

Permalink
fix, dedup chain-spec file (#52)
Browse files Browse the repository at this point in the history
* fix, dedup chain-spec file

* bump version

* fix package ci
  • Loading branch information
pepoviola authored Dec 26, 2021
1 parent 7e49448 commit b17b3e5
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ package:
- npm run clean
- npm run build
- npm run package
- cp zombienet-* artifacts/
- cp bins/zombienet-* artifacts/


# template task for building and pushing an image
Expand Down
16 changes: 10 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zombienet",
"version": "1.1.2",
"version": "1.1.3",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"author": "Javier Viola <[email protected]>",
Expand All @@ -11,7 +11,7 @@
"build": "tsc",
"start": "yarn build && node dist/cli.js",
"lint": "npx prettier --write .",
"package": "pkg ."
"package": "pkg . --out-path ./bins"
},
"dependencies": {
"@polkadot/api": "^6.1.2",
Expand All @@ -24,7 +24,8 @@
"execa": "^5.1.1",
"mocha": "^9.1.2",
"tmp-promise": "^3.0.2",
"toml": "^3.0.0"
"toml": "^3.0.0",
"yaml": "^2.0.0-9"
},
"files": [
"dist"
Expand All @@ -39,15 +40,18 @@
"static-configs/*",
"scripts/*"
],
"targets": [ "node14-macos-x64", "node14-linux-x64" ]
"targets": [
"node14-macos-x64",
"node14-linux-x64"
]
},
"devDependencies": {
"@types/mocha": "^9.0.0",
"@types/node": "^16.4.12",
"@types/tmp": "^0.2.1",
"pkg": "~5.5.1",
"prettier": "2.2.1",
"typescript": "^4.1.5",
"yarn": "^1.22.10",
"pkg": "~5.5.1"
"yarn": "^1.22.10"
}
}
2 changes: 1 addition & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ program
.command("version")
.description("Prints zombienet version")
.action(() => {
console.log("1.1.2");
console.log("1.1.3");
});

// spawn
Expand Down
2 changes: 1 addition & 1 deletion src/configManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const DEFAULT_CHAIN = "rococo-local";
export const DEFAULT_BOOTNODE_PEER_ID =
"12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp";
export const DEFAULT_BOOTNODE_DOMAIN = "bootnode";
export const DEFAULT_CHAIN_SPEC_PATH = "/cfg/{{chainName}}.json";
export const DEFAULT_CHAIN_SPEC_PATH = "/cfg/{{chainName}}-plain.json";
export const DEFAULT_CHAIN_SPEC_RAW_PATH = "/cfg/{{chainName}}-raw.json";
//export const DEFAULT_CHAIN_SPEC_COMMAND =
// "polkadot build-spec --chain {{chainName}} --disable-default-bootnode > /cfg/{{chainName}}-plain.json && polkadot build-spec --chain {{chainName}} --disable-default-bootnode --raw > /cfg/{{chainName}}.json";
Expand Down
12 changes: 7 additions & 5 deletions src/orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@ export async function start(

// Define chain name and file name to use.
const chainSpecFileName = `${networkSpec.relaychain.chain}.json`;
const chainSpecPlainFileName = chainSpecFileName.replace(".json", "-plain.json");
const chainName = networkSpec.relaychain.chain;
const chainSpecFullPath = `${tmpDir.path}/${chainSpecFileName}`;
const chainSpecFullPathPlain = chainSpecFullPath.replace(".json", "-plain.json");

// create namespace
await client.createNamespace();
Expand All @@ -131,23 +133,23 @@ export async function start(
if (!monitor) cronInterval = await client.setupCleaner();

// create or copy chain spec
await setupChainSpec(namespace, networkSpec, chainName, chainSpecFullPath);
await setupChainSpec(namespace, networkSpec, chainName, chainSpecFullPathPlain);

// check if we have the chain spec file
if (!fs.existsSync(chainSpecFullPath))
if (!fs.existsSync(chainSpecFullPathPlain))
throw new Error("Can't find chain spec file!");

// Chain spec customization logic
clearAuthorities(chainSpecFullPath);
clearAuthorities(chainSpecFullPathPlain);
for (const node of networkSpec.relaychain.nodes) {
await addAuthority(chainSpecFullPath, node.name);
await addAuthority(chainSpecFullPathPlain, node.name);
}

for(const parachain of networkSpec.parachains) {
const parachainFilesPath = await generateParachainFiles(namespace, tmpDir.path, chainName,parachain);
const stateLocalFilePath = `${parachainFilesPath}/${GENESIS_STATE_FILENAME}`;
const wasmLocalFilePath = `${parachainFilesPath}/${GENESIS_WASM_FILENAME}`;
if(parachain.addToGenesis) await addParachainToGenesis(chainSpecFullPath, parachain.id.toString(), stateLocalFilePath, wasmLocalFilePath);
if(parachain.addToGenesis) await addParachainToGenesis(chainSpecFullPathPlain, parachain.id.toString(), stateLocalFilePath, wasmLocalFilePath);
}

// generate the raw chain spec
Expand Down
9 changes: 5 additions & 4 deletions src/providers/k8s/chain-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ export async function setupChainSpec(namespace: string, networkSpec: ComputedNet
const client = getClient();
if (networkSpec.relaychain.chainSpecCommand) {
const { defaultImage, chainSpecCommand } = networkSpec.relaychain;
const plainChainSpecOutputFilePath = DEFAULT_CHAIN_SPEC_PATH.replace(/{{chainName}}/ig, chainName);
// set output of command
const fullCommand = `${chainSpecCommand} > ${DEFAULT_CHAIN_SPEC_PATH.replace(/{{chainName}}/ig, chainName)}`;
const fullCommand = `${chainSpecCommand} > ${plainChainSpecOutputFilePath}`;
const node = createTempNodeDef("temp", defaultImage, chainName, fullCommand);

const podDef = await genPodDef(namespace, node);
Expand All @@ -24,7 +25,7 @@ export async function setupChainSpec(namespace: string, networkSpec: ComputedNet
debug("copy file from pod");
await client.copyFileFromPod(
podName,
`/cfg/${chainName}.json`,
plainChainSpecOutputFilePath,
chainFullPath,
podName
);
Expand All @@ -44,7 +45,7 @@ export async function setupChainSpec(namespace: string, networkSpec: ComputedNet
export async function getChainSpecRaw(namespace: string, image: string, chainName: string, chainFullPath: string): Promise<any> {
// backup plain file
const plainPath = chainFullPath.replace(".json", "-plain.json");
fs.copyFileSync(chainFullPath, plainPath);
// fs.copyFileSync(chainFullPath, plainPath);

const remoteChainSpecFullPath = DEFAULT_CHAIN_SPEC_PATH.replace(/{{chainName}}/, chainName);
const remoteChainSpecRawFullPath = DEFAULT_CHAIN_SPEC_RAW_PATH.replace(/{{chainName}}/, chainName);
Expand All @@ -58,7 +59,7 @@ export async function getChainSpecRaw(namespace: string, image: string, chainNam
const client = getClient();
await client.spawnFromDef(podDef,[
{
localFilePath: chainFullPath,
localFilePath: plainPath,
remoteFilePath: remoteChainSpecFullPath
}
]);
Expand Down
2 changes: 1 addition & 1 deletion src/providers/k8s/kubeClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export class KubeClient {
const parts = localFilePath.split("/");
const fileName = parts[parts.length -1];
if(! fileUploadCache[hashedName]) {
console.log("es: "+localFilePath);
console.log("uploading to fileserver: "+localFilePath + " as:" +hashedName);
const args = ["cp", localFilePath, `fileserver:/usr/share/nginx/html/${hashedName}`];
// if (container) args.push("-c", container);
debug("copyFileToPod", args);
Expand Down

0 comments on commit b17b3e5

Please sign in to comment.