From b43ab47b0e2fe04bbd2e0b922457eb35cddea4f5 Mon Sep 17 00:00:00 2001 From: SHANiTH K K <59169878+shanithkk@users.noreply.github.com> Date: Tue, 30 Jan 2024 12:31:14 +0530 Subject: [PATCH] fix: para-id slot registration (#198) * fix: para-id slot registration * fix: localnet github workflow for localnet * refactor: removed unused function for registration of parachain --- parachain/build-spec.star | 79 ++++++++++++++---------------- parachain/parachain.star | 4 +- parachain/register-para-id.star | 54 ++++++++++---------- parachain/static_files/images.star | 2 +- testdata/chain_value.csv | 1 - 5 files changed, 67 insertions(+), 73 deletions(-) diff --git a/parachain/build-spec.star b/parachain/build-spec.star index 0d19095..5c10b95 100644 --- a/parachain/build-spec.star +++ b/parachain/build-spec.star @@ -2,50 +2,43 @@ 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): - command = ExecRecipe(command = [ - "/bin/sh", - "-c", - "{0} build-spec --chain={1} --disable-default-bootnode > /tmp/{2}.json".format(binary, chain_base, chain_name), - ]) - build_spec.create_edit_and_build_spec(plan, chain_name + "plain", image, chain_name, command, build_file = None) - command = ExecRecipe(command = [ - "/bin/sh", - "-c", - "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), - ]) - build_spec.create_edit_and_build_spec(plan, chain_name + "edit", constant.CURL_JQ_IMAGE, chain_name, command, chain_name + "plain") - raw_service = create_raw_build_spec_genisis_state_genisis_wasm(plan, binary, image, chain_name, chain_name + "edit") + files = { + "/app": "configs", + } + + plan.run_sh( + run = "{0} build-spec --chain={1} --disable-default-bootnode > /tmp/{2}.json".format(binary, chain_base, chain_name), + image = image, + files = files, + store = [StoreSpec(src = "/tmp/{0}.json".format(chain_name), name = chain_name + "plain")], + ) + + files = { + "/app": "configs", + "/build": chain_name + "plain", + } + 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, + files = files, + store = [StoreSpec(src = "/tmp/{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) return raw_service -def create_raw_build_spec_genisis_state_genisis_wasm(plan, binary, image, chain_name, build_file): - raw_service = build_spec.create_service_for_build_spec(plan, chain_name + "raw", image, build_file) - - command = ExecRecipe(command = [ - "/bin/sh", - "-c", - "{0} build-spec --chain=/build/{1}.json --raw --disable-default-bootnode > /tmp/{1}-raw.json".format(binary, chain_name), - ]) - result = plan.exec(service_name = chain_name + "raw", recipe = command) - plan.verify(result["code"], "==", 0) - - command = ExecRecipe(command = [ - "/bin/sh", - "-c", - "{0} export-genesis-wasm --chain=/tmp/{1}-raw.json > /tmp/{1}-genesis-wasm".format(binary, chain_name), - ]) - result = plan.exec(service_name = chain_name + "raw", recipe = command) - plan.verify(result["code"], "==", 0) - - command = ExecRecipe(command = [ - "/bin/sh", - "-c", - "{0} export-genesis-state --chain=/tmp/{1}-raw.json > /tmp/{1}-genesis-state".format(binary, chain_name), - ]) - result = plan.exec(service_name = chain_name + "raw", recipe = command) - plan.verify(result["code"], "==", 0) - - plan.store_service_files(service_name = chain_name + "raw", src = "/tmp/*", name = chain_name + "raw") - plan.stop_service(chain_name + "raw") +def create_raw_build_spec_genisis_state_genisis_wasm_for_parachain(plan, binary, image, chain_name): + files = { + "/app": "configs", + "/build": chain_name + "edit", + } - return raw_service + plan.run_sh( + run = "{0} build-spec --chain=/build/{1}.json --raw --disable-default-bootnode > /tmp/{1}-raw.json && {0} export-genesis-wasm --chain=/tmp/{1}-raw.json > /tmp/{1}-genesis-wasm && {0} export-genesis-state --chain=/tmp/{1}-raw.json > /tmp/{1}-genesis-state".format(binary, chain_name), + image = image, + files = files, + store = [StoreSpec(src = "/tmp/*", name = chain_name + "raw")], + ) + + return chain_name + "raw" diff --git a/parachain/parachain.star b/parachain/parachain.star index 1fdd616..b06fd76 100644 --- a/parachain/parachain.star +++ b/parachain/parachain.star @@ -53,7 +53,7 @@ def start_local_parachain_node(plan, chain_type, parachain, para_id): "{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.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) parachain_detail["service_name"] = parachain_spawn_detail.name parachain_detail["endpoint"] = utils.get_service_url("ws", parachain_spawn_detail.ip_address, parachain_spawn_detail.ports["ws"].number) @@ -89,7 +89,7 @@ def start_nodes(plan, chain_type, parachains, relay_chain_ip): final_parachain_details = {} for parachain in parachains: - para_id = register_para_slot.register_para_id(plan, relay_chain_ip) + para_id = register_para_slot.register_para_id(plan, relay_chain_ip) 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/register-para-id.star b/parachain/register-para-id.star index 44b1928..013b2f8 100644 --- a/parachain/register-para-id.star +++ b/parachain/register-para-id.star @@ -2,33 +2,35 @@ build_spec = import_module("../package_io/build-spec.star") constant = import_module("../package_io/constant.star") def register_para_id(plan, alice_ip): - test = build_spec.create_service_for_build_spec(plan, constant.PARA_SLOT_REGISTER_SERVICE_NAME, constant.NODE_IMAGE, "javascript") - result = plan.exec(service_name = test.name, recipe = ExecRecipe(command = ["/bin/sh", "-c", "cd /build && npm i "])) - plan.verify(result["code"], "==", 0) - result = plan.exec(service_name = test.name, recipe = ExecRecipe(command = ["/bin/sh", "-c", "cd /build && node register ws://{0}:9944 //Alice ".format(alice_ip)])) - plan.verify(result["code"], "==", 0) - para_id = plan.exec(service_name = test.name, recipe = ExecRecipe(command = ["/bin/sh", "-c", "cat /tmp/para.json | tr -d '\n\r'"])) - plan.verify(para_id["code"], "==", 0) - plan.remove_service(test.name) - return para_id["output"] + files = { + "/app": "configs", + "/build": "javascript", + } -def onboard_genesis_state_and_wasm(plan, para_id, chain_name, alice_ip): - service = plan.add_service( - name = "upload-{}-genesis-file".format(chain_name), - config = ServiceConfig( - image = constant.NODE_IMAGE, - files = { - "/app": "configs", - "/build": chain_name + "raw", - "/javascript": "javascript", - }, - entrypoint = ["/bin/sh"], - ), + plan.run_sh( + run = "cd /build && npm i && node register ws://{0}:9944 //Alice".format(alice_ip), + image = constant.NODE_IMAGE, + files = files, + store = [StoreSpec(src = "/tmp/para.json", name = "parathread_id")], ) - result = plan.exec(service_name = service.name, recipe = ExecRecipe(command = ["/bin/sh", "-c", "cd /javascript && npm i "])) - plan.verify(result["code"], "==", 0) - result = plan.exec(service_name = service.name, recipe = ExecRecipe(command = ["/bin/sh", "-c", "cd /javascript && node onboard ws://{0}:9944 //Alice {1} /build/{2}-genesis-state /build/{2}-genesis-wasm".format(alice_ip, para_id, chain_name)])) - plan.verify(result["code"], "==", 0) + id = plan.run_sh( + run = "cat /build/para.json | tr -d '\n\r'", + image = "badouralix/curl-jq", + files = { + "/build": "parathread_id", + }, + ) + return id.output - plan.remove_service(service.name) +def onboard_genesis_state_and_wasm(plan, para_id, chain_name, alice_ip): + files = { + "/app": "configs", + "/build": chain_name + "raw", + "/javascript": "javascript", + } + plan.run_sh( + run = "cd /javascript && npm i && node onboard ws://{0}:9944 //Alice {1} /build/{2}-genesis-state /build/{2}-genesis-wasm".format(alice_ip, para_id, chain_name), + image = constant.NODE_IMAGE, + files = files, + ) diff --git a/parachain/static_files/images.star b/parachain/static_files/images.star index cb92595..c746561 100644 --- a/parachain/static_files/images.star +++ b/parachain/static_files/images.star @@ -32,7 +32,7 @@ parachain_images = { }, "integritee": { "image": "integritee/parachain:latest", - "entrypoint": "/usr/local/bin/integritee-node", + "entrypoint": "/usr/local/bin/integritee-collator", "base": ["integritee-rococo-local-dev", "integritee-rococo", "integritee-kusama"], }, "interlay": { diff --git a/testdata/chain_value.csv b/testdata/chain_value.csv index a56dda8..9045427 100644 --- a/testdata/chain_value.csv +++ b/testdata/chain_value.csv @@ -1,7 +1,6 @@ acala,Polkadot bifrost,Polkadot clover,Polkadot -integritee,Polkadot kilt,Polkadot moonbeam,Polkadot litentry,Polkadot