From 9ae9205829581be243b34ad3d18ebdfabc6cf43c Mon Sep 17 00:00:00 2001 From: abhiyana Date: Thu, 8 Feb 2024 06:17:28 +0530 Subject: [PATCH 01/17] fix: fix issue for robonomics mainnet relay not showing blocks --- package_io/constant.star | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package_io/constant.star b/package_io/constant.star index ded48ff..a017e80 100644 --- a/package_io/constant.star +++ b/package_io/constant.star @@ -25,5 +25,5 @@ DIFFERENT_IMAGES_FOR_TESTNET = { CHAIN_COMMAND = ["manta", "moonsama", "interlay", "kintsugi-btc", "polkadex", "centrifuge", "altair", "robonomics", "kilt", "mangata", "litentry", "kylin"] -KUSAMA_PARACHAINS = ["altair", "bajun", "bifrost", "calamari", "encointer", "karura", "khala", "kintsugi-btc", "integritee", "litmus", "mangata", "moonriver", "robonomics", "subzero", "turing"] -POLKADOT_PARACHAINS = ["acala", "ajuna", "bifrost", "centrifuge", "clover", "frequency", "interlay", "kilt", "kylin", "litentry", "manta", "moonbeam", "moonsama", "nodle", "parallel", "pendulum", "phala", "polkadex", "subsocial", "zeitgeist"] +KUSAMA_PARACHAINS = ["altair", "bajun", "bifrost", "calamari", "encointer", "karura", "khala", "kintsugi-btc", "integritee", "litmus", "mangata", "moonriver", "subzero", "turing"] +POLKADOT_PARACHAINS = ["acala", "ajuna", "bifrost", "centrifuge", "clover", "frequency", "interlay", "kilt", "kylin", "litentry", "manta", "moonbeam", "moonsama", "nodle", "parallel", "pendulum", "phala", "polkadex", "subsocial", "zeitgeist", "robonomics"] From 46c1a956073c862a94a956cd0572e76c10a524e4 Mon Sep 17 00:00:00 2001 From: abhiyana Date: Thu, 8 Feb 2024 06:38:37 +0530 Subject: [PATCH 02/17] fix: fix issue litentry parachain testnet not showing blocks --- parachain/parachain.star | 3 +++ 1 file changed, 3 insertions(+) diff --git a/parachain/parachain.star b/parachain/parachain.star index 3de909a..1c9eb4b 100644 --- a/parachain/parachain.star +++ b/parachain/parachain.star @@ -155,6 +155,9 @@ def run_testnet_mainnet(plan, chain_type, relaychain_name, parachain): "--unsafe-rpc-external", ] + if chain_type == "testnet" and parachain["name"] == "litentry": + common_command = common_command + ["--bootnodes=/dns/rpc.rococo-parachain.litentry.io/tcp/40333/ws/p2p/12D3KooWD9t5jsf5m2g4acXfyVf2KxR5j11F9SLC5wKhv6JRquyv"] + parachain_info = {parachain["name"]: {}} if parachain["name"] == "altair" or parachain["name"] == "centrifuge": common_command = common_command + ["--database=auto"] From 16f4d4baf7a477691659a4e1f53017530a304108 Mon Sep 17 00:00:00 2001 From: abhiyana Date: Thu, 8 Feb 2024 13:38:26 +0530 Subject: [PATCH 03/17] fix: kilt issue and acala karura testnet issue --- package_io/constant.star | 6 +++--- parachain/static_files/images.star | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package_io/constant.star b/package_io/constant.star index a017e80..97248a0 100644 --- a/package_io/constant.star +++ b/package_io/constant.star @@ -5,7 +5,7 @@ CURL_JQ_IMAGE = "badouralix/curl-jq" NODE_IMAGE = "hugobyte/parachain-node-modules" PARA_SLOT_REGISTER_SERVICE_NAME = "para-slot-registration" BINARY_COMMAND_CHAINS = ["manta", "khala", "phala", "clover", "calamari", "subzero", "robonomics"] -WS_PORT = ["robonomics", "parallel", "subsocial", "litmus", "pendulum", "kilt", "litentry", "zeitgeist", "kylin", "subzero", "polkadex", "clover"] +WS_PORT = ["robonomics", "parallel", "subsocial", "litmus", "pendulum", "litentry", "zeitgeist", "kylin", "subzero", "polkadex", "clover"] DIFFERENT_IMAGES_FOR_MAINNET = { "centrifuge": "centrifugeio/centrifuge-chain:main-latest", @@ -16,11 +16,11 @@ DIFFERENT_IMAGES_FOR_MAINNET = { DIFFERENT_IMAGES_FOR_TESTNET = { "frequency": "frequencychain/parachain-node-rococo", "centrifuge": "centrifugeio/centrifuge-chain:main-latest", - "karura": "acala/mandala-node:latest", + "karura": "acala/mandala-node:2.22.0", "clover": "cloverio/clover-iris:0.1.15", "subsocial": "dappforce/subsocial-parachain:latest", "altair": "centrifugeio/centrifuge-chain:main-latest", - "acala": "acala/mandala-node:latest", + "acala": "acala/mandala-node:2.22.0", } CHAIN_COMMAND = ["manta", "moonsama", "interlay", "kintsugi-btc", "polkadex", "centrifuge", "altair", "robonomics", "kilt", "mangata", "litentry", "kylin"] diff --git a/parachain/static_files/images.star b/parachain/static_files/images.star index c746561..a2b745b 100644 --- a/parachain/static_files/images.star +++ b/parachain/static_files/images.star @@ -3,7 +3,7 @@ parachain_images = { "acala": { "image": "acala/acala-node:latest", # NO ws port "entrypoint": "/usr/local/bin/acala", - "base": ["acala-local", "mandala-latest", "acala"], + "base": ["acala-local", "/mandala.json", "acala"], }, "ajuna": { "image": "ajuna/parachain-ajuna:latest", @@ -58,7 +58,7 @@ parachain_images = { "manta": { "image": "mantanetwork/manta:latest", "entrypoint": "/usr/local/bin/manta", - "base": ["manta-local", "manta-testnet", "manta"], + "base": ["manta-local", "=manta-testnet", "manta"], }, "moonbeam": { "image": "moonbeamfoundation/moonbeam:sha-32933811", @@ -128,7 +128,7 @@ parachain_images = { "karura": { "image": "acala/karura-node:latest", "entrypoint": "/usr/local/bin/acala", - "base": ["karura-local", "mandala-latest", "karura"], + "base": ["karura-local", "/mandala.json", "karura"], }, "khala": { "image": "phalanetwork/khala-node:latest", From 3594e1a509f5b5c04db1770892abc70007fc6e79 Mon Sep 17 00:00:00 2001 From: abhiyana Date: Thu, 8 Feb 2024 15:47:51 +0530 Subject: [PATCH 04/17] fix: acala, karura testnet issue --- package_io/constant.star | 2 +- parachain/parachain.star | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/package_io/constant.star b/package_io/constant.star index 97248a0..2018aaf 100644 --- a/package_io/constant.star +++ b/package_io/constant.star @@ -23,7 +23,7 @@ DIFFERENT_IMAGES_FOR_TESTNET = { "acala": "acala/mandala-node:2.22.0", } -CHAIN_COMMAND = ["manta", "moonsama", "interlay", "kintsugi-btc", "polkadex", "centrifuge", "altair", "robonomics", "kilt", "mangata", "litentry", "kylin"] +CHAIN_COMMAND = ["manta", "moonsama", "interlay", "kintsugi-btc", "polkadex", "centrifuge", "altair", "robonomics", "kilt", "mangata", "litentry", "kylin", "acala", "karura"] KUSAMA_PARACHAINS = ["altair", "bajun", "bifrost", "calamari", "encointer", "karura", "khala", "kintsugi-btc", "integritee", "litmus", "mangata", "moonriver", "subzero", "turing"] POLKADOT_PARACHAINS = ["acala", "ajuna", "bifrost", "centrifuge", "clover", "frequency", "interlay", "kilt", "kylin", "litentry", "manta", "moonbeam", "moonsama", "nodle", "parallel", "pendulum", "phala", "polkadex", "subsocial", "zeitgeist", "robonomics"] diff --git a/parachain/parachain.star b/parachain/parachain.star index 1c9eb4b..e2f4240 100644 --- a/parachain/parachain.star +++ b/parachain/parachain.star @@ -157,7 +157,7 @@ def run_testnet_mainnet(plan, chain_type, relaychain_name, parachain): if chain_type == "testnet" and parachain["name"] == "litentry": common_command = common_command + ["--bootnodes=/dns/rpc.rococo-parachain.litentry.io/tcp/40333/ws/p2p/12D3KooWD9t5jsf5m2g4acXfyVf2KxR5j11F9SLC5wKhv6JRquyv"] - + parachain_info = {parachain["name"]: {}} if parachain["name"] == "altair" or parachain["name"] == "centrifuge": common_command = common_command + ["--database=auto"] @@ -189,7 +189,10 @@ def run_testnet_mainnet(plan, chain_type, relaychain_name, parachain): command = command + ["--validator"] if parachain["name"] in constant.CHAIN_COMMAND: - command = command + ["--", "--chain={0}".format(relaychain_name)] + if parachain["name"] in ["acala", "karura"] and chain_type == "testnet": + command = command + ["--", "--chain={0}".format("/rococo-mandala.json")] + else: + command = command + ["--", "--chain={0}".format(relaychain_name)] if parachain["name"] == "kilt-spiritnet" and chain_type == "testnet": command = command + ["--", "--chain=/node/dev-specs/kilt-parachain/peregrine-relay.json"] From 04667d64b2a25b0f30557b10786879388fe775cb Mon Sep 17 00:00:00 2001 From: abhiyana Date: Thu, 8 Feb 2024 16:52:00 +0530 Subject: [PATCH 05/17] chore: change base for manta parachain --- parachain/static_files/images.star | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parachain/static_files/images.star b/parachain/static_files/images.star index a2b745b..94c35ef 100644 --- a/parachain/static_files/images.star +++ b/parachain/static_files/images.star @@ -58,7 +58,7 @@ parachain_images = { "manta": { "image": "mantanetwork/manta:latest", "entrypoint": "/usr/local/bin/manta", - "base": ["manta-local", "=manta-testnet", "manta"], + "base": ["manta-local", "manta-testnet", "manta"], }, "moonbeam": { "image": "moonbeamfoundation/moonbeam:sha-32933811", From a7f70617164465f3e783754f8444401eb9055a49 Mon Sep 17 00:00:00 2001 From: abhiyana Date: Fri, 9 Feb 2024 09:22:39 +0530 Subject: [PATCH 06/17] feat: implement add custom sudo key for parachain --- main.star | 8 +-- parachain/build-spec.star | 19 +++++-- parachain/parachain.star | 27 ++++++++-- .../javascript/edit_parachain_plain.js | 51 +++++++++++++++++++ .../static_files/javascript/insert_key.js | 35 +++++++++++++ 5 files changed, 128 insertions(+), 12 deletions(-) create mode 100644 parachain/static_files/javascript/edit_parachain_plain.js create mode 100644 parachain/static_files/javascript/insert_key.js diff --git a/main.star b/main.star index 58c0ea3..1d05518 100644 --- a/main.star +++ b/main.star @@ -8,7 +8,7 @@ utils = import_module("./package_io/utils.star") constant = import_module("./package_io/constant.star") parachain_without_registration = import_module("./parachain/parachain_without_registration.star") -def run(plan, chain_type = "localnet", relaychain = None, parachains = None, explorer = False, without_registration = False): +def run(plan, chain_type = "localnet", relaychain = None, parachains = None, explorer = False, without_registration = False, sudo_key=None): """ Main function to run the Polkadot relay and parachain setup. @@ -31,10 +31,10 @@ def run(plan, chain_type = "localnet", relaychain = None, parachains = None, exp Returns: service_details (json): Service details containing information about relay chains, parachains, and Prometheus. """ - service_details = run_polkadot_setup(plan, chain_type, relaychain, parachains, explorer, without_registration) + service_details = run_polkadot_setup(plan, chain_type, relaychain, parachains, explorer, without_registration, sudo_key) return service_details -def run_polkadot_setup(plan, chain_type, relaychain, parachains, explorer, without_registration): +def run_polkadot_setup(plan, chain_type, relaychain, parachains, explorer, without_registration, sudo_key): """ Main function to run the Polkadot relay and parachain setup. @@ -72,7 +72,7 @@ def run_polkadot_setup(plan, chain_type, relaychain, parachains, explorer, witho polkadot_service_name = key break service_details.update(relay_chain_details) - parachain_details = parachain.start_nodes(plan, chain_type, parachains, relay_chain_details[polkadot_service_name]["ip_address"]) + parachain_details = parachain.start_nodes(plan, chain_type, parachains, relay_chain_details[polkadot_service_name]["ip_address"], sudo_key) service_details.update(parachain_details) else: parachain_details = parachain_without_registration.start_nodes(plan, chain_type, relaychain, parachains) diff --git a/parachain/build-spec.star b/parachain/build-spec.star index 5c10b95..23f44b9 100644 --- a/parachain/build-spec.star +++ b/parachain/build-spec.star @@ -1,7 +1,7 @@ build_spec = import_module("../package_io/build-spec.star") constant = import_module("../package_io/constant.star") -def create_parachain_build_spec_with_para_id(plan, image, binary, chain_name, chain_base, para_id): +def create_parachain_build_spec_with_para_id(plan, image, binary, chain_name, chain_base, para_id, sudo_key=None): files = { "/app": "configs", } @@ -16,13 +16,24 @@ def create_parachain_build_spec_with_para_id(plan, image, binary, chain_name, ch files = { "/app": "configs", "/build": chain_name + "plain", + "/javascript": "javascript", } + + #start + #if Sudo key is given, we will add it to chain_spec + run_command = "" + if sudo_key != None: + run_command = "cd /javascript && npm i && node edit_parachain_plain.js /build/{0}.json {1} {2}".format(chain_name, para_id, sudo_key["public_key"]) + else: + run_command = "cd /javascript && npm i && node edit_parachain_plain.js /build/{0}.json {1}".format(chain_name, para_id) + plan.run_sh( - run = "sed -e 's/\"parachainId\": *[0-9]\\+/\"parachainId\": {0}/' -e 's/\"para_id\": [0-9]*,/\"para_id\": {0},/' -e 's/\"paraId\": [0-9]*,/\"paraId\": {0},/' -e 's/\"parachain_id\": [0-9]*,/\"parachain_id\": {0},/' /build/{1}.json > /tmp/{1}.json".format(para_id, chain_name), - image = constant.CURL_JQ_IMAGE, + run = run_command, + image = constant.NODE_IMAGE, files = files, - store = [StoreSpec(src = "/tmp/{0}.json".format(chain_name), name = chain_name + "edit")], + store = [StoreSpec(src = "/build/{0}.json".format(chain_name), name = chain_name + "edit")], ) + raw_service = create_raw_build_spec_genisis_state_genisis_wasm_for_parachain(plan, binary, image, chain_name) diff --git a/parachain/parachain.star b/parachain/parachain.star index e2f4240..e90c122 100644 --- a/parachain/parachain.star +++ b/parachain/parachain.star @@ -5,7 +5,7 @@ parachain_list = import_module("./static_files/images.star") node_setup = import_module("./node_setup.star") utils = import_module("../package_io/utils.star") -def start_local_parachain_node(plan, chain_type, parachain, para_id): +def start_local_parachain_node(plan, chain_type, parachain, para_id, sudo_key=None): """ Start local parachain nodes based on configuration. @@ -22,7 +22,7 @@ def start_local_parachain_node(plan, chain_type, parachain, para_id): image = parachain_details["image"] binary = parachain_details["entrypoint"] chain_base = parachain_details["base"][0] - raw_service = build_spec.create_parachain_build_spec_with_para_id(plan, image, binary, chain_name, chain_base, para_id) + raw_service = build_spec.create_parachain_build_spec_with_para_id(plan, image, binary, chain_name, chain_base, para_id, sudo_key) parachain_final = {} @@ -72,9 +72,18 @@ def start_local_parachain_node(plan, chain_type, parachain, para_id): parachain_final[parachain_spawn_detail.name] = parachain_detail + if sudo_key != None: + http_uri = "" + http_uri = utils.get_service_url("http", parachain_spawn_detail.ip_address, parachain_spawn_detail.ports["ws"].number) + # if ws_port != None: + # http_uri = utils.get_service_url("http", parachain_spawn_detail.ip_address, ws_port) + # elif rpc_port != None: + # http_uri = utils.get_service_url("http", parachain_spawn_detail.ip_address, rpc_port) + insert_keys(plan, parachain_spawn_detail.name, sudo_key["private_phrase"], sudo_key["public_key_hex"], http_uri) + return parachain_final -def start_nodes(plan, chain_type, parachains, relay_chain_ip): +def start_nodes(plan, chain_type, parachains, relay_chain_ip, sudo_key=None): """ Start multiple parachain nodes. @@ -90,7 +99,7 @@ def start_nodes(plan, chain_type, parachains, relay_chain_ip): for parachain in parachains: para_id = register_para_slot.register_para_id(plan, relay_chain_ip, parachain["name"]) - parachain_details = start_local_parachain_node(plan, chain_type, parachain, para_id) + parachain_details = start_local_parachain_node(plan, chain_type, parachain, para_id, sudo_key) register_para_slot.onboard_genesis_state_and_wasm(plan, para_id, parachain["name"], relay_chain_ip) final_parachain_details.update(parachain_details) @@ -239,3 +248,13 @@ def run_testnet_mainnet(plan, chain_type, relaychain_name, parachain): final_parachain_info[node_details.name] = node_info return final_parachain_info + + + +def insert_keys(plan, service_name, private_phrase, sudo_key_in_hex, uri): + original_command = 'curl -vH \'Content-Type: application/json\' --data \'{{ "jsonrpc":"2.0", "method":"author_insertKey", "params":["aura", {0}, {1}],"id":1 }}\' {2}' + modified_command = original_command.format(private_phrase, sudo_key_in_hex, uri) + plan.run_sh( + run = modified_command, + image = "curlimages/curl:latest" + ) \ No newline at end of file diff --git a/parachain/static_files/javascript/edit_parachain_plain.js b/parachain/static_files/javascript/edit_parachain_plain.js new file mode 100644 index 0000000..1d1d611 --- /dev/null +++ b/parachain/static_files/javascript/edit_parachain_plain.js @@ -0,0 +1,51 @@ +const fs = require("fs"); + +function updateParachainSpec(PARA_SPEC_FILE, PARA_ID, NEW_SUDO_KEY) { + try { + // Read the existing parachain spec + const rawdata = fs.readFileSync(PARA_SPEC_FILE); + const chainSpec = JSON.parse(rawdata); + + // Update the para_id + chainSpec.para_id = PARA_ID; + chainSpec.genesis.runtime.parachainInfo.parachainId = PARA_ID; + console.log("sudo key:", NEW_SUDO_KEY) + + // Update the sudo key if provided + if (NEW_SUDO_KEY) { + // chainSpec.genesis.runtime.sudo.key = NEW_SUDO_KEY; + + // Add session keys + const SESSION_KEYS = [ + NEW_SUDO_KEY, + NEW_SUDO_KEY, + { aura: NEW_SUDO_KEY } + ]; + chainSpec.genesis.runtime.session.keys.push(SESSION_KEYS); + + // Add balance + const BALANCE = [ + NEW_SUDO_KEY, + chainSpec.genesis.runtime.balances.balances[0][1] + ]; + chainSpec.genesis.runtime.balances.balances.push(BALANCE); + + // Add initial collators + chainSpec.genesis.runtime.collatorSelection.invulnerables.push(NEW_SUDO_KEY); + } + + // Write the modified spec back to the file + fs.writeFileSync(PARA_SPEC_FILE, JSON.stringify(chainSpec, null, 2)); + + console.log("✓ Updated sudo key and session keys in parachain spec"); + } catch (error) { + console.error("Error updating parachain spec:", error.message); + } +} + + +const paraSpecFile = process.argv[2]; +const paraId = parseInt(process.argv[3], 10) || 2000; +const newSudoKey = process.argv[4] + +updateParachainSpec(paraSpecFile, paraId, newSudoKey); \ No newline at end of file diff --git a/parachain/static_files/javascript/insert_key.js b/parachain/static_files/javascript/insert_key.js new file mode 100644 index 0000000..f784362 --- /dev/null +++ b/parachain/static_files/javascript/insert_key.js @@ -0,0 +1,35 @@ +const { ApiPromise, WsProvider, Keyring } = require('@polkadot/api'); + +async function insertKey(providerUrl, keyType, mnemonicOrPrivateKey) { + try { + const wsProvider = new WsProvider(providerUrl); + + const api = await ApiPromise.create({ provider: wsProvider }); + + const keyring = new Keyring({ type: 'sr25519' }); + + const account = keyring.addFromUri(mnemonicOrPrivateKey); + + const result = await api.rpc.author.insertKey(keyType, mnemonicOrPrivateKey, account.publicKey); + + console.log(`Account ${account.address} inserted successfully!`); + + return result; + } catch (error) { + + console.error('Error inserting account:', error); + throw error; + } +} + +const providerUrl = process.argv[2]; +const keyType = process.argv[3]; +const mnemonicOrPrivateKey = process.argv[4]; + +insertKey(providerUrl, keyType, mnemonicOrPrivateKey) + .then((result) => { + console.log('Insertion result:', result.toHex()); + }) + .catch((err) => { + console.error('Error:', err.message); + }); From 0a7c25deb5ae6119598eca7024bd9c2cf19ce511 Mon Sep 17 00:00:00 2001 From: abhiyana Date: Fri, 9 Feb 2024 09:48:52 +0530 Subject: [PATCH 07/17] refactor: change insert_keys function, from js script to curl command --- parachain/parachain.star | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/parachain/parachain.star b/parachain/parachain.star index e90c122..7350bb7 100644 --- a/parachain/parachain.star +++ b/parachain/parachain.star @@ -252,9 +252,10 @@ def run_testnet_mainnet(plan, chain_type, relaychain_name, parachain): def insert_keys(plan, service_name, private_phrase, sudo_key_in_hex, uri): - original_command = 'curl -vH \'Content-Type: application/json\' --data \'{{ "jsonrpc":"2.0", "method":"author_insertKey", "params":["aura", {0}, {1}],"id":1 }}\' {2}' + original_command = 'curl -vH \'Content-Type: application/json\' --data \'{{"jsonrpc":"2.0", "method":"author_insertKey", "params":["aura", "{0}", "{1}"], "id":1}}\' {2}' modified_command = original_command.format(private_phrase, sudo_key_in_hex, uri) + plan.print(modified_command) plan.run_sh( - run = modified_command, - image = "curlimages/curl:latest" - ) \ No newline at end of file + run=modified_command, + image="curlimages/curl:latest" + ) From b5bb6ee5c096ff1bb92855764450f19c3df83ee9 Mon Sep 17 00:00:00 2001 From: abhiyana Date: Fri, 9 Feb 2024 09:53:48 +0530 Subject: [PATCH 08/17] chore: code clean in parachain.star --- parachain/parachain.star | 6 ------ 1 file changed, 6 deletions(-) diff --git a/parachain/parachain.star b/parachain/parachain.star index 7350bb7..cad4f4e 100644 --- a/parachain/parachain.star +++ b/parachain/parachain.star @@ -73,14 +73,8 @@ def start_local_parachain_node(plan, chain_type, parachain, para_id, sudo_key=No parachain_final[parachain_spawn_detail.name] = parachain_detail if sudo_key != None: - http_uri = "" http_uri = utils.get_service_url("http", parachain_spawn_detail.ip_address, parachain_spawn_detail.ports["ws"].number) - # if ws_port != None: - # http_uri = utils.get_service_url("http", parachain_spawn_detail.ip_address, ws_port) - # elif rpc_port != None: - # http_uri = utils.get_service_url("http", parachain_spawn_detail.ip_address, rpc_port) insert_keys(plan, parachain_spawn_detail.name, sudo_key["private_phrase"], sudo_key["public_key_hex"], http_uri) - return parachain_final def start_nodes(plan, chain_type, parachains, relay_chain_ip, sudo_key=None): From ec8f03421b3580d9d45000c0a11fa520d0053928 Mon Sep 17 00:00:00 2001 From: abhiyana Date: Fri, 9 Feb 2024 21:03:41 +0530 Subject: [PATCH 09/17] refactor: change insertkey function from curl to js script --- config.json | 20 ++++++--- parachain/parachain.star | 21 +++++----- .../static_files/javascript/insert_key.js | 42 ++++++++++--------- 3 files changed, 48 insertions(+), 35 deletions(-) diff --git a/config.json b/config.json index 7016870..683b94b 100644 --- a/config.json +++ b/config.json @@ -24,22 +24,32 @@ { "name": "alice", "node_type": "collator", - "prometheus": false + "prometheus": false, + "key":{ + "private_phrase":"dizzy rose offer wall social glory debris gift govern seminar almost bicycle" , + "public_key_hex":"0xb0571932b80c2c7b592757630d7efc2133223eb2b72be914da729e4b1d65335d", + "public_key":"5G3vA9UC6J7hPN5Jqfiz4qFNqYAfahHxffbuQf6dcZZx3Yx6" + } }, { "name": "bob", "node_type": "full", - "prometheus": false + "prometheus": false, + "key": { + "private_phrase":"diamond crane pioneer aisle conduct media news cup price olive dust light" , + "public_key_hex":"0xcc94ef97d4a8ae8ac1478dfba90079359f238f4cd886ccf5d32fb6635de12e65", + "public_key":"5GgwsM48CCT7oPUyFTTpE5L1t7Fjpe7D8SDNKxJxug15YEKy" + } } ] } ], - "explorer": false, - "without_registration" : false, "sudo_key": { "private_phrase":"dizzy rose offer wall social glory debris gift govern seminar almost bicycle" , "public_key_hex":"0xb0571932b80c2c7b592757630d7efc2133223eb2b72be914da729e4b1d65335d", "public_key":"5G3vA9UC6J7hPN5Jqfiz4qFNqYAfahHxffbuQf6dcZZx3Yx6" - } + }, + "explorer": false, + "without_registration" : false } \ No newline at end of file diff --git a/parachain/parachain.star b/parachain/parachain.star index cad4f4e..88a919c 100644 --- a/parachain/parachain.star +++ b/parachain/parachain.star @@ -44,13 +44,13 @@ def start_local_parachain_node(plan, chain_type, parachain, para_id, sudo_key=No exec_comexec_commandmand = [ "/bin/bash", "-c", - "{0} --base-path=/tmp/{1} --chain=/build/{1}-raw.json --ws-port=9944 --port=30333 --rpc-port=9947 --ws-external --rpc-external --prometheus-external --rpc-cors=all --{2} --collator --rpc-methods=unsafe --force-authoring --execution=wasm -- --chain=/app/raw-polkadot.json --execution=wasm".format(binary, chain_name, node["name"]), + "{0} --base-path=/tmp/{1} --chain=/build/{1}-raw.json --ws-port=9944 --port=30333 --rpc-port=9947 --ws-external --rpc-external --prometheus-external --rpc-cors=all --name={2} --collator --rpc-methods=unsafe --force-authoring --execution=wasm -- --chain=/app/raw-polkadot.json --execution=wasm".format(binary, chain_name, node["name"]), ] else: exec_comexec_commandmand = [ "/bin/bash", "-c", - "{0} --base-path=/tmp/{1} --chain=/build/{1}-raw.json --rpc-port=9947 --port=30333 --rpc-external --rpc-cors=all --prometheus-external --{2} --collator --rpc-methods=unsafe --force-authoring --execution=wasm -- --chain=/app/raw-polkadot.json --execution=wasm".format(binary, chain_name, node["name"]), + "{0} --base-path=/tmp/{1} --chain=/build/{1}-raw.json --rpc-port=9947 --port=30333 --rpc-external --rpc-cors=all --prometheus-external --name={2} --collator --rpc-methods=unsafe --force-authoring --execution=wasm -- --chain=/app/raw-polkadot.json --execution=wasm".format(binary, chain_name, node["name"]), ] build_file = raw_service @@ -73,8 +73,7 @@ def start_local_parachain_node(plan, chain_type, parachain, para_id, sudo_key=No parachain_final[parachain_spawn_detail.name] = parachain_detail if sudo_key != None: - http_uri = utils.get_service_url("http", parachain_spawn_detail.ip_address, parachain_spawn_detail.ports["ws"].number) - insert_keys(plan, parachain_spawn_detail.name, sudo_key["private_phrase"], sudo_key["public_key_hex"], http_uri) + insert_keys(plan, "aura", sudo_key["private_phrase"], sudo_key["public_key_hex"], parachain_detail["endpoint"]) return parachain_final def start_nodes(plan, chain_type, parachains, relay_chain_ip, sudo_key=None): @@ -245,11 +244,13 @@ def run_testnet_mainnet(plan, chain_type, relaychain_name, parachain): -def insert_keys(plan, service_name, private_phrase, sudo_key_in_hex, uri): - original_command = 'curl -vH \'Content-Type: application/json\' --data \'{{"jsonrpc":"2.0", "method":"author_insertKey", "params":["aura", "{0}", "{1}"], "id":1}}\' {2}' - modified_command = original_command.format(private_phrase, sudo_key_in_hex, uri) - plan.print(modified_command) +def insert_keys(plan, key_type, private_phrase, sudo_key_in_hex, uri): + files = { + "/javascript": "javascript", + } + plan.run_sh( - run=modified_command, - image="curlimages/curl:latest" + run = 'cd /javascript && npm i && node insert_key.js "{0}" "{1}" "{2}"'.format(key_type, private_phrase, uri), + image = constant.NODE_IMAGE, + files = files, ) diff --git a/parachain/static_files/javascript/insert_key.js b/parachain/static_files/javascript/insert_key.js index f784362..0f679cd 100644 --- a/parachain/static_files/javascript/insert_key.js +++ b/parachain/static_files/javascript/insert_key.js @@ -1,35 +1,37 @@ const { ApiPromise, WsProvider, Keyring } = require('@polkadot/api'); +const { encodeAddress } = require('@polkadot/util-crypto'); +const { createType } = require('@polkadot/types'); +const { u8aToHex } =require("@polkadot/util") +const { decodeAddress } = require("@polkadot/util-crypto") -async function insertKey(providerUrl, keyType, mnemonicOrPrivateKey) { + + +async function insertKey(keyType, mnemonicOrPrivateKey, providerUrl) { try { const wsProvider = new WsProvider(providerUrl); - const api = await ApiPromise.create({ provider: wsProvider }); - const keyring = new Keyring({ type: 'sr25519' }); - - const account = keyring.addFromUri(mnemonicOrPrivateKey); - - const result = await api.rpc.author.insertKey(keyType, mnemonicOrPrivateKey, account.publicKey); - + const account = keyring.addFromMnemonic(mnemonicOrPrivateKey); + const result = await api.rpc.author.insertKey(keyType, mnemonicOrPrivateKey, u8aToHex(decodeAddress(account.address))); console.log(`Account ${account.address} inserted successfully!`); - return result; } catch (error) { - console.error('Error inserting account:', error); throw error; } } -const providerUrl = process.argv[2]; -const keyType = process.argv[3]; -const mnemonicOrPrivateKey = process.argv[4]; +const keyType = process.argv[2]; +const mnemonicOrPrivateKey = process.argv[3]; +const providerUrl = process.argv[4]; -insertKey(providerUrl, keyType, mnemonicOrPrivateKey) - .then((result) => { - console.log('Insertion result:', result.toHex()); - }) - .catch((err) => { - console.error('Error:', err.message); - }); +(async () => { + try { + await insertKey(keyType, mnemonicOrPrivateKey, providerUrl); + console.log('Script executed successfully!'); + process.exit(0); + } catch (error) { + console.error('Error executing script:', error); + process.exit(1); + } +})(); From fa93a271b668996fc9a2a1466926c67a72ccc7cc Mon Sep 17 00:00:00 2001 From: abhiyana Date: Fri, 9 Feb 2024 21:19:38 +0530 Subject: [PATCH 10/17] chore: updated the config.json --- config.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/config.json b/config.json index 683b94b..5b32dc1 100644 --- a/config.json +++ b/config.json @@ -27,7 +27,6 @@ "prometheus": false, "key":{ "private_phrase":"dizzy rose offer wall social glory debris gift govern seminar almost bicycle" , - "public_key_hex":"0xb0571932b80c2c7b592757630d7efc2133223eb2b72be914da729e4b1d65335d", "public_key":"5G3vA9UC6J7hPN5Jqfiz4qFNqYAfahHxffbuQf6dcZZx3Yx6" } @@ -38,7 +37,6 @@ "prometheus": false, "key": { "private_phrase":"diamond crane pioneer aisle conduct media news cup price olive dust light" , - "public_key_hex":"0xcc94ef97d4a8ae8ac1478dfba90079359f238f4cd886ccf5d32fb6635de12e65", "public_key":"5GgwsM48CCT7oPUyFTTpE5L1t7Fjpe7D8SDNKxJxug15YEKy" } } @@ -47,7 +45,6 @@ ], "sudo_key": { "private_phrase":"dizzy rose offer wall social glory debris gift govern seminar almost bicycle" , - "public_key_hex":"0xb0571932b80c2c7b592757630d7efc2133223eb2b72be914da729e4b1d65335d", "public_key":"5G3vA9UC6J7hPN5Jqfiz4qFNqYAfahHxffbuQf6dcZZx3Yx6" }, "explorer": false, From ada835c803871462a41d62e14cfea9c6e6416cd9 Mon Sep 17 00:00:00 2001 From: abhiyana Date: Fri, 9 Feb 2024 21:20:13 +0530 Subject: [PATCH 11/17] refactor: refactor the insert_keys function parameter --- parachain/parachain.star | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/parachain/parachain.star b/parachain/parachain.star index 88a919c..ccdb4c0 100644 --- a/parachain/parachain.star +++ b/parachain/parachain.star @@ -73,7 +73,7 @@ def start_local_parachain_node(plan, chain_type, parachain, para_id, sudo_key=No parachain_final[parachain_spawn_detail.name] = parachain_detail if sudo_key != None: - insert_keys(plan, "aura", sudo_key["private_phrase"], sudo_key["public_key_hex"], parachain_detail["endpoint"]) + insert_keys(plan, "aura", sudo_key["private_phrase"], parachain_detail["endpoint"]) return parachain_final def start_nodes(plan, chain_type, parachains, relay_chain_ip, sudo_key=None): @@ -244,7 +244,7 @@ def run_testnet_mainnet(plan, chain_type, relaychain_name, parachain): -def insert_keys(plan, key_type, private_phrase, sudo_key_in_hex, uri): +def insert_keys(plan, key_type, private_phrase, uri): files = { "/javascript": "javascript", } From 9eafea5ccbabea38bfc57f94ab226b959b95376a Mon Sep 17 00:00:00 2001 From: abhiyana Date: Sat, 10 Feb 2024 01:36:34 +0530 Subject: [PATCH 12/17] refactor: refactor config.json, change sudo_key key position --- config.json | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/config.json b/config.json index 5b32dc1..7ea7125 100644 --- a/config.json +++ b/config.json @@ -40,13 +40,14 @@ "public_key":"5GgwsM48CCT7oPUyFTTpE5L1t7Fjpe7D8SDNKxJxug15YEKy" } } - ] + ], + "sudo_key": { + "private_phrase":"dizzy rose offer wall social glory debris gift govern seminar almost bicycle" , + "public_key":"5G3vA9UC6J7hPN5Jqfiz4qFNqYAfahHxffbuQf6dcZZx3Yx6" + } } ], - "sudo_key": { - "private_phrase":"dizzy rose offer wall social glory debris gift govern seminar almost bicycle" , - "public_key":"5G3vA9UC6J7hPN5Jqfiz4qFNqYAfahHxffbuQf6dcZZx3Yx6" - }, + "explorer": false, "without_registration" : false } \ No newline at end of file From 32be31c758ec4c179da2df94c2aa2ab50d87ee6a Mon Sep 17 00:00:00 2001 From: abhiyana Date: Sat, 10 Feb 2024 01:38:00 +0530 Subject: [PATCH 13/17] feat: add functionality to add sepate key wallet for each node --- main.star | 2 +- parachain/build-spec.star | 11 +--- parachain/parachain.star | 20 +++++-- .../javascript/edit_parachain_plain.js | 57 ++++++++++++------- 4 files changed, 55 insertions(+), 35 deletions(-) diff --git a/main.star b/main.star index 1d05518..3cd7b0c 100644 --- a/main.star +++ b/main.star @@ -72,7 +72,7 @@ def run_polkadot_setup(plan, chain_type, relaychain, parachains, explorer, witho polkadot_service_name = key break service_details.update(relay_chain_details) - parachain_details = parachain.start_nodes(plan, chain_type, parachains, relay_chain_details[polkadot_service_name]["ip_address"], sudo_key) + parachain_details = parachain.start_nodes(plan, chain_type, parachains, relay_chain_details[polkadot_service_name]["ip_address"]) service_details.update(parachain_details) else: parachain_details = parachain_without_registration.start_nodes(plan, chain_type, relaychain, parachains) diff --git a/parachain/build-spec.star b/parachain/build-spec.star index 23f44b9..d1d153c 100644 --- a/parachain/build-spec.star +++ b/parachain/build-spec.star @@ -1,7 +1,7 @@ build_spec = import_module("../package_io/build-spec.star") constant = import_module("../package_io/constant.star") -def create_parachain_build_spec_with_para_id(plan, image, binary, chain_name, chain_base, para_id, sudo_key=None): +def create_parachain_build_spec_with_para_id(plan, image, binary, chain_name, chain_base, para_id, sudo_key, collators_keys): files = { "/app": "configs", } @@ -19,14 +19,9 @@ def create_parachain_build_spec_with_para_id(plan, image, binary, chain_name, ch "/javascript": "javascript", } - #start - #if Sudo key is given, we will add it to chain_spec - run_command = "" - if sudo_key != None: - run_command = "cd /javascript && npm i && node edit_parachain_plain.js /build/{0}.json {1} {2}".format(chain_name, para_id, sudo_key["public_key"]) - else: - run_command = "cd /javascript && npm i && node edit_parachain_plain.js /build/{0}.json {1}".format(chain_name, para_id) + run_command = "cd /javascript && npm i && node edit_parachain_plain.js /build/{0}.json {1} \"{2}\" \'{3}\'".format(chain_name, para_id, sudo_key, collators_keys) + plan.print(run_command) plan.run_sh( run = run_command, image = constant.NODE_IMAGE, diff --git a/parachain/parachain.star b/parachain/parachain.star index ccdb4c0..7fea16a 100644 --- a/parachain/parachain.star +++ b/parachain/parachain.star @@ -5,7 +5,7 @@ parachain_list = import_module("./static_files/images.star") node_setup = import_module("./node_setup.star") utils = import_module("../package_io/utils.star") -def start_local_parachain_node(plan, chain_type, parachain, para_id, sudo_key=None): +def start_local_parachain_node(plan, chain_type, parachain, para_id): """ Start local parachain nodes based on configuration. @@ -22,7 +22,15 @@ def start_local_parachain_node(plan, chain_type, parachain, para_id, sudo_key=No image = parachain_details["image"] binary = parachain_details["entrypoint"] chain_base = parachain_details["base"][0] - raw_service = build_spec.create_parachain_build_spec_with_para_id(plan, image, binary, chain_name, chain_base, para_id, sudo_key) + + sudo_key = "" + if len(parachain["sudo_key"]) != 0: + sudo_key = parachain["sudo_key"]["public_key"] + + public_keys = [node.get("key", {}).get("public_key", "") for node in parachain["nodes"] if node.get("key")] + collators_keys = "[" + ", ".join(["\"{}\"".format(key) for key in public_keys]) + "]" + + raw_service = build_spec.create_parachain_build_spec_with_para_id(plan, image, binary, chain_name, chain_base, para_id, sudo_key, collators_keys) parachain_final = {} @@ -72,11 +80,11 @@ def start_local_parachain_node(plan, chain_type, parachain, para_id, sudo_key=No parachain_final[parachain_spawn_detail.name] = parachain_detail - if sudo_key != None: - insert_keys(plan, "aura", sudo_key["private_phrase"], parachain_detail["endpoint"]) + if len(node["key"]) != 0: + insert_keys(plan, "aura", node["key"]["private_phrase"], parachain_detail["endpoint"]) return parachain_final -def start_nodes(plan, chain_type, parachains, relay_chain_ip, sudo_key=None): +def start_nodes(plan, chain_type, parachains, relay_chain_ip): """ Start multiple parachain nodes. @@ -92,7 +100,7 @@ def start_nodes(plan, chain_type, parachains, relay_chain_ip, sudo_key=None): for parachain in parachains: para_id = register_para_slot.register_para_id(plan, relay_chain_ip, parachain["name"]) - parachain_details = start_local_parachain_node(plan, chain_type, parachain, para_id, sudo_key) + parachain_details = start_local_parachain_node(plan, chain_type, parachain, para_id) register_para_slot.onboard_genesis_state_and_wasm(plan, para_id, parachain["name"], relay_chain_ip) final_parachain_details.update(parachain_details) diff --git a/parachain/static_files/javascript/edit_parachain_plain.js b/parachain/static_files/javascript/edit_parachain_plain.js index 1d1d611..fe45bdf 100644 --- a/parachain/static_files/javascript/edit_parachain_plain.js +++ b/parachain/static_files/javascript/edit_parachain_plain.js @@ -1,40 +1,58 @@ const fs = require("fs"); -function updateParachainSpec(PARA_SPEC_FILE, PARA_ID, NEW_SUDO_KEY) { +function updateParachainSpec(PARA_SPEC_FILE, PARA_ID, NEW_SUDO_KEY, INITIAL_COLLATORS) { try { - // Read the existing parachain spec const rawdata = fs.readFileSync(PARA_SPEC_FILE); const chainSpec = JSON.parse(rawdata); - - // Update the para_id + const collators = JSON.parse(INITIAL_COLLATORS); + chainSpec.para_id = PARA_ID; chainSpec.genesis.runtime.parachainInfo.parachainId = PARA_ID; - console.log("sudo key:", NEW_SUDO_KEY) - - // Update the sudo key if provided - if (NEW_SUDO_KEY) { - // chainSpec.genesis.runtime.sudo.key = NEW_SUDO_KEY; + - // Add session keys + if (NEW_SUDO_KEY.length > 0) { + chainSpec.genesis.runtime.sudo.key = NEW_SUDO_KEY; + const SESSION_KEYS = [ NEW_SUDO_KEY, NEW_SUDO_KEY, { aura: NEW_SUDO_KEY } ]; chainSpec.genesis.runtime.session.keys.push(SESSION_KEYS); - - // Add balance + const BALANCE = [ NEW_SUDO_KEY, chainSpec.genesis.runtime.balances.balances[0][1] ]; chainSpec.genesis.runtime.balances.balances.push(BALANCE); - - // Add initial collators - chainSpec.genesis.runtime.collatorSelection.invulnerables.push(NEW_SUDO_KEY); + console.log("changed sudo key:", NEW_SUDO_KEY); } - // Write the modified spec back to the file + if (collators.length > 0) { + collators.forEach(collator => { + //adding this condition to prevent adding duplicate keys + if(collator!=NEW_SUDO_KEY){ + console.log("updating collator:", collator); + const sessionKey = [ + collator, + collator, + { aura: collator } + ]; + chainSpec.genesis.runtime.session.keys.push(sessionKey); + + const balance = [ + collator, + chainSpec.genesis.runtime.balances.balances[0][1] + ]; + chainSpec.genesis.runtime.balances.balances.push(balance); + + chainSpec.genesis.runtime.collatorSelection.invulnerables.push(collator); + } else{ + chainSpec.genesis.runtime.collatorSelection.invulnerables.push(collator); + } + }); + } + fs.writeFileSync(PARA_SPEC_FILE, JSON.stringify(chainSpec, null, 2)); console.log("✓ Updated sudo key and session keys in parachain spec"); @@ -43,9 +61,8 @@ function updateParachainSpec(PARA_SPEC_FILE, PARA_ID, NEW_SUDO_KEY) { } } - const paraSpecFile = process.argv[2]; const paraId = parseInt(process.argv[3], 10) || 2000; -const newSudoKey = process.argv[4] - -updateParachainSpec(paraSpecFile, paraId, newSudoKey); \ No newline at end of file +const newSudoKey = process.argv[4]; +const initialCollators = process.argv[5]; +updateParachainSpec(paraSpecFile, paraId, newSudoKey, initialCollators); From 976cf19185b4af59b93220d0fa891c1565d92fe9 Mon Sep 17 00:00:00 2001 From: abhiyana Date: Sat, 10 Feb 2024 01:57:19 +0530 Subject: [PATCH 14/17] refactor: refactor code in parachain.star, nodes can start with and without keys --- parachain/parachain.star | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/parachain/parachain.star b/parachain/parachain.star index 7fea16a..107923d 100644 --- a/parachain/parachain.star +++ b/parachain/parachain.star @@ -49,17 +49,32 @@ def start_local_parachain_node(plan, chain_type, parachain, para_id): ws_port = None if chain_name in constant.WS_PORT: - exec_comexec_commandmand = [ - "/bin/bash", - "-c", - "{0} --base-path=/tmp/{1} --chain=/build/{1}-raw.json --ws-port=9944 --port=30333 --rpc-port=9947 --ws-external --rpc-external --prometheus-external --rpc-cors=all --name={2} --collator --rpc-methods=unsafe --force-authoring --execution=wasm -- --chain=/app/raw-polkadot.json --execution=wasm".format(binary, chain_name, node["name"]), - ] + if len(node["key"]) != 0: + exec_comexec_commandmand = [ + "/bin/bash", + "-c", + "{0} --base-path=/tmp/{1} --chain=/build/{1}-raw.json --ws-port=9944 --port=30333 --rpc-port=9947 --ws-external --rpc-external --prometheus-external --rpc-cors=all --name={2} --collator --rpc-methods=unsafe --force-authoring --execution=wasm -- --chain=/app/raw-polkadot.json --execution=wasm".format(binary, chain_name, node["name"]), + ] + else: + exec_comexec_commandmand = [ + "/bin/bash", + "-c", + "{0} --base-path=/tmp/{1} --chain=/build/{1}-raw.json --ws-port=9944 --port=30333 --rpc-port=9947 --ws-external --rpc-external --prometheus-external --rpc-cors=all --{2} --collator --rpc-methods=unsafe --force-authoring --execution=wasm -- --chain=/app/raw-polkadot.json --execution=wasm".format(binary, chain_name, node["name"]), + ] else: - exec_comexec_commandmand = [ - "/bin/bash", - "-c", - "{0} --base-path=/tmp/{1} --chain=/build/{1}-raw.json --rpc-port=9947 --port=30333 --rpc-external --rpc-cors=all --prometheus-external --name={2} --collator --rpc-methods=unsafe --force-authoring --execution=wasm -- --chain=/app/raw-polkadot.json --execution=wasm".format(binary, chain_name, node["name"]), - ] + if len(node["key"]) != 0: + exec_comexec_commandmand = [ + "/bin/bash", + "-c", + "{0} --base-path=/tmp/{1} --chain=/build/{1}-raw.json --rpc-port=9947 --port=30333 --rpc-external --rpc-cors=all --prometheus-external --name={2} --collator --rpc-methods=unsafe --force-authoring --execution=wasm -- --chain=/app/raw-polkadot.json --execution=wasm".format(binary, chain_name, node["name"]), + ] + else: + exec_comexec_commandmand = [ + "/bin/bash", + "-c", + "{0} --base-path=/tmp/{1} --chain=/build/{1}-raw.json --rpc-port=9947 --port=30333 --rpc-external --rpc-cors=all --prometheus-external --{2} --collator --rpc-methods=unsafe --force-authoring --execution=wasm -- --chain=/app/raw-polkadot.json --execution=wasm".format(binary, chain_name, node["name"]), + ] + build_file = raw_service parachain_spawn_detail = node_setup.spawn_parachain(plan, node["prometheus"], image, parachain["name"], "{0}-{1}-{2}".format(chain_name, node["name"], chain_type), exec_comexec_commandmand, build_file, rpc_port, prometheus_port, lib2lib_port, ws_port) From 42c899b664ad2ff5a6fc9000164d2d9bee852012 Mon Sep 17 00:00:00 2001 From: abhiyana Date: Mon, 12 Feb 2024 22:54:14 +0530 Subject: [PATCH 15/17] refactor: update script to update parachain spec --- main.star | 6 +-- parachain/build-spec.star | 1 + parachain/parachain.star | 5 ++- .../javascript/edit_parachain_plain.js | 43 ++++++++++++------- 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/main.star b/main.star index 3cd7b0c..58c0ea3 100644 --- a/main.star +++ b/main.star @@ -8,7 +8,7 @@ utils = import_module("./package_io/utils.star") constant = import_module("./package_io/constant.star") parachain_without_registration = import_module("./parachain/parachain_without_registration.star") -def run(plan, chain_type = "localnet", relaychain = None, parachains = None, explorer = False, without_registration = False, sudo_key=None): +def run(plan, chain_type = "localnet", relaychain = None, parachains = None, explorer = False, without_registration = False): """ Main function to run the Polkadot relay and parachain setup. @@ -31,10 +31,10 @@ def run(plan, chain_type = "localnet", relaychain = None, parachains = None, exp Returns: service_details (json): Service details containing information about relay chains, parachains, and Prometheus. """ - service_details = run_polkadot_setup(plan, chain_type, relaychain, parachains, explorer, without_registration, sudo_key) + service_details = run_polkadot_setup(plan, chain_type, relaychain, parachains, explorer, without_registration) return service_details -def run_polkadot_setup(plan, chain_type, relaychain, parachains, explorer, without_registration, sudo_key): +def run_polkadot_setup(plan, chain_type, relaychain, parachains, explorer, without_registration): """ Main function to run the Polkadot relay and parachain setup. diff --git a/parachain/build-spec.star b/parachain/build-spec.star index d1d153c..fbfdfdf 100644 --- a/parachain/build-spec.star +++ b/parachain/build-spec.star @@ -48,3 +48,4 @@ def create_raw_build_spec_genisis_state_genisis_wasm_for_parachain(plan, binary, ) return chain_name + "raw" + \ No newline at end of file diff --git a/parachain/parachain.star b/parachain/parachain.star index 107923d..3005d56 100644 --- a/parachain/parachain.star +++ b/parachain/parachain.star @@ -25,9 +25,9 @@ def start_local_parachain_node(plan, chain_type, parachain, para_id): sudo_key = "" if len(parachain["sudo_key"]) != 0: - sudo_key = parachain["sudo_key"]["public_key"] + sudo_key = parachain["sudo_key"]["private_phrase"] - public_keys = [node.get("key", {}).get("public_key", "") for node in parachain["nodes"] if node.get("key")] + public_keys = [node.get("key", {}).get("private_phrase", "") for node in parachain["nodes"] if node.get("key")] collators_keys = "[" + ", ".join(["\"{}\"".format(key) for key in public_keys]) + "]" raw_service = build_spec.create_parachain_build_spec_with_para_id(plan, image, binary, chain_name, chain_base, para_id, sudo_key, collators_keys) @@ -97,6 +97,7 @@ def start_local_parachain_node(plan, chain_type, parachain, para_id): if len(node["key"]) != 0: insert_keys(plan, "aura", node["key"]["private_phrase"], parachain_detail["endpoint"]) + return parachain_final def start_nodes(plan, chain_type, parachains, relay_chain_ip): diff --git a/parachain/static_files/javascript/edit_parachain_plain.js b/parachain/static_files/javascript/edit_parachain_plain.js index fe45bdf..9a667a4 100644 --- a/parachain/static_files/javascript/edit_parachain_plain.js +++ b/parachain/static_files/javascript/edit_parachain_plain.js @@ -1,37 +1,48 @@ const fs = require("fs"); +const { Keyring } = require('@polkadot/keyring'); +const { encodeAddress, cryptoWaitReady } = require('@polkadot/util-crypto'); -function updateParachainSpec(PARA_SPEC_FILE, PARA_ID, NEW_SUDO_KEY, INITIAL_COLLATORS) { +async function updateParachainSpec(paraSpecFile, paraId, newSudoKeyPhrase, initialCollatorsPhrase) { try { - const rawdata = fs.readFileSync(PARA_SPEC_FILE); + const rawdata = fs.readFileSync(paraSpecFile); const chainSpec = JSON.parse(rawdata); - const collators = JSON.parse(INITIAL_COLLATORS); + const collators = JSON.parse(initialCollatorsPhrase); - chainSpec.para_id = PARA_ID; - chainSpec.genesis.runtime.parachainInfo.parachainId = PARA_ID; + chainSpec.para_id = paraId; + chainSpec.genesis.runtime.parachainInfo.parachainId = paraId; - if (NEW_SUDO_KEY.length > 0) { - chainSpec.genesis.runtime.sudo.key = NEW_SUDO_KEY; + await cryptoWaitReady(); + const keyring = new Keyring({ type: 'sr25519' }); + + let newSudoKey = ''; // Declaring newSudoKey as let instead of const + + if (newSudoKeyPhrase.length > 0) { + const newSudoAccount = keyring.addFromUri(newSudoKeyPhrase); + newSudoKey = newSudoAccount.address; + chainSpec.genesis.runtime.sudo.key = newSudoKey; const SESSION_KEYS = [ - NEW_SUDO_KEY, - NEW_SUDO_KEY, - { aura: NEW_SUDO_KEY } + newSudoKey, + newSudoKey, + { aura: newSudoKey } ]; chainSpec.genesis.runtime.session.keys.push(SESSION_KEYS); const BALANCE = [ - NEW_SUDO_KEY, + newSudoKey, chainSpec.genesis.runtime.balances.balances[0][1] ]; chainSpec.genesis.runtime.balances.balances.push(BALANCE); - console.log("changed sudo key:", NEW_SUDO_KEY); + console.log("changed sudo key:", newSudoKey); } - if (collators.length > 0) { - collators.forEach(collator => { + if (initialCollatorsPhrase.length > 0) { + collators.forEach(collatorPhrase => { + var collatorAccount = keyring.addFromUri(collatorPhrase); + var collator = collatorAccount.address; //adding this condition to prevent adding duplicate keys - if(collator!=NEW_SUDO_KEY){ + if(collatorPhrase!=newSudoKeyPhrase){ console.log("updating collator:", collator); const sessionKey = [ collator, @@ -53,7 +64,7 @@ function updateParachainSpec(PARA_SPEC_FILE, PARA_ID, NEW_SUDO_KEY, INITIAL_COLL }); } - fs.writeFileSync(PARA_SPEC_FILE, JSON.stringify(chainSpec, null, 2)); + fs.writeFileSync(paraSpecFile, JSON.stringify(chainSpec, null, 2)); console.log("✓ Updated sudo key and session keys in parachain spec"); } catch (error) { From f5b940f98ff44c27017a3cb691d73da593c41ca3 Mon Sep 17 00:00:00 2001 From: abhiyana Date: Tue, 13 Feb 2024 22:54:20 +0530 Subject: [PATCH 16/17] fix: fix issue if sudo_key, key is not provided in config then it throw error --- parachain/parachain.star | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/parachain/parachain.star b/parachain/parachain.star index 3005d56..60f4642 100644 --- a/parachain/parachain.star +++ b/parachain/parachain.star @@ -24,7 +24,7 @@ def start_local_parachain_node(plan, chain_type, parachain, para_id): chain_base = parachain_details["base"][0] sudo_key = "" - if len(parachain["sudo_key"]) != 0: + if parachain.get("sudo_key") != None and len(parachain["sudo_key"]) != 0: sudo_key = parachain["sudo_key"]["private_phrase"] public_keys = [node.get("key", {}).get("private_phrase", "") for node in parachain["nodes"] if node.get("key")] @@ -49,7 +49,7 @@ def start_local_parachain_node(plan, chain_type, parachain, para_id): ws_port = None if chain_name in constant.WS_PORT: - if len(node["key"]) != 0: + if node.get("key") != None and len(node["key"]) != 0: exec_comexec_commandmand = [ "/bin/bash", "-c", @@ -62,7 +62,7 @@ def start_local_parachain_node(plan, chain_type, parachain, para_id): "{0} --base-path=/tmp/{1} --chain=/build/{1}-raw.json --ws-port=9944 --port=30333 --rpc-port=9947 --ws-external --rpc-external --prometheus-external --rpc-cors=all --{2} --collator --rpc-methods=unsafe --force-authoring --execution=wasm -- --chain=/app/raw-polkadot.json --execution=wasm".format(binary, chain_name, node["name"]), ] else: - if len(node["key"]) != 0: + if node.get("key") != None and len(node["key"]) != 0: exec_comexec_commandmand = [ "/bin/bash", "-c", @@ -95,7 +95,7 @@ def start_local_parachain_node(plan, chain_type, parachain, para_id): parachain_final[parachain_spawn_detail.name] = parachain_detail - if len(node["key"]) != 0: + if node.get("key") != None and len(node["key"]) != 0: insert_keys(plan, "aura", node["key"]["private_phrase"], parachain_detail["endpoint"]) return parachain_final From e44b7496bd555999fee96fc10f5e8ecc7db5f997 Mon Sep 17 00:00:00 2001 From: Shanith K K Date: Wed, 14 Feb 2024 02:00:40 +0530 Subject: [PATCH 17/17] fix: issue with sudo key while without registratioon is true --- parachain/parachain_without_registration.star | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/parachain/parachain_without_registration.star b/parachain/parachain_without_registration.star index f2423a2..bcd2faa 100644 --- a/parachain/parachain_without_registration.star +++ b/parachain/parachain_without_registration.star @@ -22,8 +22,15 @@ def start_nodes(plan, chain_type, relaychain, parachains): binary = parachain_details["entrypoint"] chain_base = parachain_details["base"][0] + sudo_key = "" + if parachain.get("sudo_key") != None and len(parachain["sudo_key"]) != 0: + sudo_key = parachain["sudo_key"]["private_phrase"] + + public_keys = [node.get("key", {}).get("private_phrase", "") for node in parachain["nodes"] if node.get("key")] + collators_keys = "[" + ", ".join(["\"{}\"".format(key) for key in public_keys]) + "]" + # Creating the genisis state genesis wasm and raw build spec for parachain - build_spec.create_parachain_build_spec_with_para_id(plan, image, binary, chain_name, chain_base, para_id) + build_spec.create_parachain_build_spec_with_para_id(plan, image, binary, chain_name, chain_base, para_id, sudo_key, collators_keys) # if parachain are more than one, adding the genisis state genesis wasm to relay(polkadot) chain spec if counter > 0: