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 onboard_as_parachain flag to parachain options #886

Merged
merged 17 commits into from
Apr 6, 2023
Merged
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
7 changes: 5 additions & 2 deletions docs/src/network-definition-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ The network config can be provided both in `json` or `toml` format and each sect
- `parachains` Array of `parachain` definition objects

- `*id`: (Number) The id to assign to this parachain. Must be unique.
- `add_to_genesis`: (Boolean) flag to add parachain to genesis or register in runtime.
- `cumulus_based`: (Boolean) flag to use `cumulus` command generation; Set to `true` by default.
- `add_to_genesis`: (Boolean, default true) flag to add parachain to genesis or register in runtime.
- `cumulus_based`: (Boolean, default true) flag to use `cumulus` command generation.
- `genesis_wasm_path`: (String) Path to the wasm file to use.
- `genesis_wasm_generator`: (String) Command to generate the wasm file.
- `genesis_state_path`: (String) Path to the state file to use.
Expand All @@ -98,6 +98,9 @@ The network config can be provided both in `json` or `toml` format and each sect
- name: (String) name of the `env` var.
- value: (String| number) Value of the env var.

- `onboard_as_parachain`: (Boolean, default true) flag to specify whether the para should be onboarded as a parachain or stay a parathread
- `register_para`: (Boolean, default true) flag to specify whether the para should be registered. The `add_to_genesis` flag **must** be set to false for this flag to have any effect.

## `hrmp_channels`: (Array of objects)

- `sender`: (Number) parachain Id.
Expand Down
2 changes: 1 addition & 1 deletion flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
default = pkgs.buildNpmPackage rec {
# root hash (hash of hashes of each dependnecies)
# this should be updated on each dependency change (use `prefetch-npm-deps` to get new hash)
npmDepsHash = "sha256-hsQ7Z0/wU8FPNWeR68N9NnbvW95Ux1gHwk+MoTQYBRE=";
npmDepsHash = "sha256-lA8xOKnzthgscr0pMmQ6KcZjYxNdOK5lfZ301PZ29Xg=";

pname = "zombienet";
name = pname;
Expand Down
4 changes: 4 additions & 0 deletions javascript/packages/orchestrator/src/configGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,10 @@ export async function generateNetworkSpec(
parachain.register_para === undefined
? true
: parachain.register_para, // register by default
onboardAsParachain:
parachain.onboard_as_parachain !== undefined
? parachain.onboard_as_parachain
: true, // onboard by default
collators,
};

Expand Down
18 changes: 10 additions & 8 deletions javascript/packages/orchestrator/src/jsapi-helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ApiPromise, WsProvider } from "@polkadot/api";
import { Keyring } from "@polkadot/keyring";
import { cryptoWaitReady } from "@polkadot/util-crypto";
import { readDataFile } from "@zombienet/utils";
import { RegisterParachainOptions } from "../types";
import {
chainCustomSectionUpgrade,
chainUpgradeFromLocalFile,
Expand All @@ -18,14 +19,15 @@ async function connect(apiUrl: string, types?: any): Promise<ApiPromise> {
return api;
}

async function registerParachain(
id: number,
wasmPath: string,
statePath: string,
apiUrl: string,
seed: string = "//Alice",
async function registerParachain({
id,
wasmPath,
statePath,
apiUrl,
onboardAsParachain,
seed = "//Alice",
finalization = false,
) {
}: RegisterParachainOptions) {
return new Promise<void>(async (resolve, reject) => {
await cryptoWaitReady();

Expand All @@ -42,7 +44,7 @@ async function registerParachain(
const parachainGenesisArgs = {
genesis_head: genesis_state,
validation_code: wasm_data,
parachain: true,
parachain: onboardAsParachain,
};

const genesis = api.createType("ParaGenesisArgs", parachainGenesisArgs);
Expand Down
14 changes: 8 additions & 6 deletions javascript/packages/orchestrator/src/orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -703,12 +703,14 @@ export async function start(
for (const parachain of networkSpec.parachains) {
if (!parachain.addToGenesis && parachain.registerPara) {
// register parachain on a running network
await registerParachain(
parachain.id,
`${tmpDir.path}/${parachain.name}/${GENESIS_WASM_FILENAME}`,
`${tmpDir.path}/${parachain.name}/${GENESIS_STATE_FILENAME}`,
network.relay[0].wsUri,
);
const basePath = `${tmpDir.path}/${parachain.name}`;
await registerParachain({
id: parachain.id,
wasmPath: `${basePath}/${GENESIS_WASM_FILENAME}`,
statePath: `${basePath}/${GENESIS_STATE_FILENAME}`,
apiUrl: network.relay[0].wsUri,
onboardAsParachain: parachain.onboardAsParachain,
});
}

if (parachain.cumulusBased) {
Expand Down
12 changes: 12 additions & 0 deletions javascript/packages/orchestrator/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export interface ParachainConfig {
chain?: string;
add_to_genesis?: boolean;
register_para?: boolean;
onboard_as_parachain?: boolean;
balance?: number;
genesis_wasm_path?: string;
genesis_wasm_generator?: string;
Expand Down Expand Up @@ -203,6 +204,7 @@ export interface Parachain {
para: PARA;
addToGenesis: boolean;
registerPara: boolean;
onboardAsParachain: boolean;
cumulusBased: boolean;
genesisWasmPath?: string;
genesisWasmGenerator?: string;
Expand Down Expand Up @@ -315,3 +317,13 @@ export interface FnArgs {
after?: number;
seconds?: number;
}

export interface RegisterParachainOptions {
id: number;
wasmPath: string;
statePath: string;
apiUrl: string;
onboardAsParachain: boolean;
seed?: string;
finalization?: boolean;
}