Skip to content

Commit

Permalink
fix onboarding parachain (#682)
Browse files Browse the repository at this point in the history
* fix onboarding parachain

* add custom endpoint
  • Loading branch information
mikiquantum authored Mar 9, 2022
1 parent 00f5e59 commit 94d1e1a
Show file tree
Hide file tree
Showing 6 changed files with 775 additions and 6 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ Icon
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
.apdisk

# Node Modules
**/node_modules
13 changes: 8 additions & 5 deletions scripts/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,21 @@ start-parachain)
;;

onboard-parachain)
echo "NOTE: This command does NOT onboard the parachain; It only outputs the required parameters for the parachain to be onboarded."
echo "NOTE: This command onboards the parachain; Block production will start in a few minutes"

genesis=$(./target/release/centrifuge-chain export-genesis-state --chain="${parachain}" --parachain-id="${para_id}")
# Extract the runtime id from $parachain.
# For example, 'development-local' becomes 'development', 'altair-local' becomes 'altair', etc.
runtime_id=$(echo $parachain | cut -d'-' -f 1)
wasm_location="${PWD}/${parachain}-${para_id}.wasm"
./target/release/centrifuge-chain export-genesis-wasm --chain="${parachain}" > $wasm_location

echo "Parachain Id:" $para_id
echo "Genesis state:" $genesis
echo "WASM path:" "./target/release/wbuild/${runtime_id}-runtime/${runtime_id}_runtime.compact.wasm"
echo "WASM path:" "${parachain}-${para_id}.wasm"

cd scripts/js/onboard
yarn && yarn execute "ws://0.0.0.0:9944" "//Alice" ${para_id} "${genesis}" $wasm_location
;;

benchmark)
./scripts/run_benchmark.sh "${parachain}" "$2" "$3"
;;
esac
5 changes: 5 additions & 0 deletions scripts/js/onboard/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Onboard Parachain
Simple Node JS script that onboards the parachain against a local target

## Requirements
- yarn 1.22.x
70 changes: 70 additions & 0 deletions scripts/js/onboard/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
const { ApiPromise, WsProvider, Keyring } = require('@polkadot/api');
const fs = require('fs')

const run = async () => {
try {
console.log("Parsing Args ...")
// 0 & 1 are command context
const endpoint = process.argv[2];
const seed = process.argv[3];
const id = process.argv[4];
const header = process.argv[5];
const wasmFile = process.argv[6]

const wsProvider = new WsProvider(endpoint);

const api = await ApiPromise.create({
provider: wsProvider,
});

const keyring = new Keyring({ type: "sr25519" });
const alice = keyring.addFromUri(seed);

let wasm;
try {
wasm = fs.readFileSync(wasmFile, 'utf8')
} catch (err) {
console.error(err)
throw err
}

let paraGenesisArgs = {
genesis_head: header,
validation_code: wasm,
parachain: true,
};
let genesis = api.createType("ParaGenesisArgs", paraGenesisArgs);

const nonce = Number((await api.query.system.account(alice.address)).nonce);

console.log(
`--- Submitting extrinsic to register parachain ${id}. (nonce: ${nonce}) ---`
);
const unsub = await api.tx.sudo
.sudo(api.tx.parasSudoWrapper.sudoScheduleParaInitialize(id, genesis))
.signAndSend(alice, { nonce: nonce, era: 0 }, (result) => {
console.log(`Current status is ${result.status}`);
if (result.status.isInBlock) {
console.log(
`Transaction included at blockHash ${result.status.asInBlock}`
);
console.log("Waiting for finalization...");
} else if (result.status.isFinalized) {
console.log(
`Transaction finalized at blockHash ${result.status.asFinalized}`
);
unsub();
process.exit()
} else if (result.isError) {
console.log(`Transaction Error`);
process.exit()
}
});

} catch (error) {
console.log('error:', error);
}

};

run();
17 changes: 17 additions & 0 deletions scripts/js/onboard/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "onboard",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"execute": "node index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@polkadot/api": "^7.6.1",
"@polkadot/util": "^7.6.1",
"@polkadot/util-crypto": "^8.3.3"
}
}
Loading

0 comments on commit 94d1e1a

Please sign in to comment.