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

fix: para-id slot registration #198

Merged
merged 4 commits into from
Jan 30, 2024
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
79 changes: 36 additions & 43 deletions parachain/build-spec.star
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 2 additions & 2 deletions parachain/parachain.star
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
54 changes: 28 additions & 26 deletions parachain/register-para-id.star
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
2 changes: 1 addition & 1 deletion parachain/static_files/images.star
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
1 change: 0 additions & 1 deletion testdata/chain_value.csv
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
acala,Polkadot
bifrost,Polkadot
clover,Polkadot
integritee,Polkadot
kilt,Polkadot
moonbeam,Polkadot
litentry,Polkadot
Expand Down
Loading