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: error in parachain artifact #152

Merged
merged 2 commits into from
Dec 7, 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
13 changes: 8 additions & 5 deletions main.star
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def run(plan, args):
dict: Service details containing information about relay chains, parachains, and Prometheus.
"""
plan.upload_files(src = "./parachain/static_files/configs", name = "configs")
plan.upload_files(src = "./parachain/static_files/javascript", name = "javascript")

prometheus_template = read_file("./package_io/static_files/prometheus.yml.tmpl")
service_details = {"relaychains": {}, "parachains": {}, "prometheus": ""}
Expand All @@ -32,20 +33,22 @@ def run(plan, args):
service_details["relaychains"] = relay_node_detals
final_parachain_detail = []
for paras in args["para"]:
parachain_details={}
parachain_details = {}
parachain_details["service_name"] = "parachain_service_" + paras["name"]
parachain_details["parachain_name"] = paras["name"]
parachain_info = parachain.run_testnet_mainnet(plan, paras, args)
parachain_details["nodes"] = parachain_info
final_parachain_detail.append(parachain_details)
service_details["parachains"] = final_parachain_detail

#run prometheus , if it returs some endpoint then grafana will up
prometheus_address = promethues.launch_prometheus(plan, args, service_details, prometheus_template)
service_details["prometheus"] = prometheus_address
grafana.launch_grafana(plan, grafana)
if prometheus_address.startswith("http://"):
service_details["prometheus"] = prometheus_address
grafana.launch_grafana(plan, grafana)

#run the polkadot js App explorer
if args["explorer"] == True:
service_details["explorer"] = explorer.run_pokadot_js_app(plan, "wss://127.0.0.1:9944")
service_details["explorer"] = explorer.run_pokadot_js_app(plan, "ws://127.0.0.1:9944")

return service_details
return service_details
12 changes: 8 additions & 4 deletions package_io/promethues.star
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ def launch_prometheus(
args,
service_details,
)

if len(template_data["MetricsJobs"]) == 0:
return "No Prometheus is available"

template_and_data = shared_utils.new_template_and_data(
config_template,
template_data,
Expand Down Expand Up @@ -89,21 +93,21 @@ def new_config_template_data(plan, args, service_details):
scrape_interval = "5s",
),
)

for parachain in args["para"]:
for node in parachain["nodes"]:
if node["prometheus"] == True:
for para_chain in service_details["parachains"]:
for para_chain in service_details["parachains"]:
for para_chain_node in para_chain["nodes"]:
service_name = para_chain_node["node_details"].name
string = "{}-{}-{}".format(parachain["name"],node["name"],args["chain-type"])
string = "{}-{}-{}".format(parachain["name"], node["name"], args["chain-type"])
if string == service_name:
ip = para_chain_node["node_details"].ip_address
port_number = para_chain_node["node_details"].ports["metrics"].number
endpoint = "{0}:{1}".format(ip, port_number)
metrics_jobs.append(
new_metrics_job(
job_name = "parachain_{}_service_{}".format(parachain["name"],node["name"]),
job_name = "parachain_{}_service_{}".format(parachain["name"], node["name"]),
endpoint = endpoint,
scrape_interval = "5s",
),
Expand Down
20 changes: 10 additions & 10 deletions parachain/build-spec.star
Original file line number Diff line number Diff line change
Expand Up @@ -7,52 +7,52 @@ def create_parachain_build_spec_with_para_id(plan, image, binary, chain_name, ch
"-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, constant.PLAIN_BUILD_SPEC, image, chain_name, command, build_file = None)
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},/' /build/{1}.json > /tmp/{1}.json".format(para_id, chain_name),
])
build_spec.create_edit_and_build_spec(plan, constant.EDIT_BUILD_SPEC, constant.CURL_JQ_IMAGE, chain_name, command, constant.PLAIN_BUILD_SPEC)
raw_service = create_raw_build_spec_genisis_state_genisis_wasm(plan, binary, image, chain_name, constant.EDIT_BUILD_SPEC)
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")

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, constant.RAW_BUILD_SPEC, image, 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 = constant.RAW_BUILD_SPEC, recipe = command)
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 = constant.RAW_BUILD_SPEC, recipe = command)
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 = constant.RAW_BUILD_SPEC, recipe = command)
result = plan.exec(service_name = chain_name + "raw", recipe = command)
plan.verify(result["code"], "==", 0)

# command = ExecRecipe(command = [
# "/bin/sh",
# "-c",
# "cp /build/{0}.json /tmp/{0}.json".format(chain_name),
# ])
# plan.exec(service_name = constant.RAW_BUILD_SPEC, recipe = command)
# plan.exec(service_name = chain_name+"raw", recipe = command)

plan.store_service_files(service_name = constant.RAW_BUILD_SPEC, src = "/tmp/*", name = constant.RAW_BUILD_SPEC)
plan.stop_service(constant.RAW_BUILD_SPEC)
plan.store_service_files(service_name = chain_name + "raw", src = "/tmp/*", name = chain_name + "raw")
plan.stop_service(chain_name + "raw")

return raw_service
2 changes: 1 addition & 1 deletion parachain/parachain.star
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def run_testnet_mainnet(plan, parachain, args):
]

parachain_info = {parachain["name"]: {}}
if parachain == "altair" or "centrifuge":
if parachain["name"] == "altair" or parachain["name"] == "centrifuge":
common_command = common_command + ["--database=auto"]

if parachain["name"] == "subzero" and args["chain-type"] == "mainnet":
Expand Down
5 changes: 2 additions & 3 deletions parachain/register-para-id.star
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ build_spec = import_module("../package_io/build-spec.star")
constant = import_module("../package_io/constant.star")

def register_para_id(plan, alice_ip):
plan.upload_files(src = "./static_files/javascript", name = "javascript")
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)
Expand All @@ -15,12 +14,12 @@ def register_para_id(plan, alice_ip):

def onboard_genesis_state_and_wasm(plan, para_id, chain_name, alice_ip):
service = plan.add_service(
name = "upload-genesis-file",
name = "upload-{}-genesis-file".format(chain_name),
config = ServiceConfig(
image = constant.NODE_IMAGE,
files = {
"/app": "configs",
"/build": constant.RAW_BUILD_SPEC,
"/build": chain_name + "raw",
"/javascript": "javascript",
},
entrypoint = ["/bin/sh"],
Expand Down
14 changes: 5 additions & 9 deletions relaychain/relay-chain.star
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def start_relay_chain(plan, args):
"""
name = args["chain-type"]
chain = args["relaychain"]["name"]
final_details=[]
final_details = []

prometheus = 9615
for relay_node in args["relaychain"]["nodes"]:
port = relay_node["port"]
Expand Down Expand Up @@ -40,7 +40,6 @@ def start_relay_chain(plan, args):

return final_details


def start_test_main_net_relay_nodes(plan, args):
"""
Starts testnet/mainnet relay nodes based on the provided arguments.
Expand All @@ -66,7 +65,6 @@ def start_test_main_net_relay_nodes(plan, args):

return relay_node_details


def spawn_multiple_relay(plan, count):
"""
Spawns multiple local relay chain nodes.
Expand All @@ -81,7 +79,6 @@ def spawn_multiple_relay(plan, count):
port = port + count
start_relay_chain_local(plan, node_list[i], port)


def start_relay_chains_local(plan, args):
"""
Starts local relay chain nodes based on the provided arguments.
Expand All @@ -102,15 +99,14 @@ def start_relay_chains_local(plan, args):
prometheus_port = 9615
for node in relay_nodes:
relay_detail = {}
service_details = start_relay_chain_local(plan, node["name"], node["port"], prometheus_port)
service_details = start_relay_chain_local(plan, args, node["name"], node["port"], prometheus_port)
relay_detail["service_details"] = service_details
relay_detail["service_name"] = service_details.name
final_details.append(relay_detail)
prometheus_port = prometheus_port + 1
return final_details


def start_relay_chain_local(plan, name, port, prometheus_port):
def start_relay_chain_local(plan, args, name, port, prometheus_port):
"""
Starts a local relay chain node based on the provided arguments.

Expand All @@ -125,7 +121,7 @@ def start_relay_chain_local(plan, name, port, prometheus_port):
"""
exec_command = ["bin/sh", "-c", "polkadot --base-path=/data --chain=/app/raw-polkadot.json --validator --rpc-external --rpc-cors=all --name=alice --{0} --rpc-methods=unsafe --execution=wasm --prometheus-external".format(name)]
service_details = plan.add_service(
name = "polkadot-{0}".format(name),
name = "{0}-{1}".format(args["relaychain"]["name"], name),
config = ServiceConfig(
image = "parity/polkadot:latest",
files = {
Expand Down