From edf37a806a2d81d7b98cf19ffa76595dfadef888 Mon Sep 17 00:00:00 2001 From: Abhishek Harde <47945971+abhiyana@users.noreply.github.com> Date: Thu, 30 Nov 2023 18:11:00 +0530 Subject: [PATCH] refactor: refactor config file, change para from dict to list (#128) * refactor: refactor config file, change para from dict to list * fix: typo and encointer mainnet --------- Co-authored-by: Shanith K K --- local.json | 7 ++-- main.star | 2 +- package_io/promethues.star | 2 +- parachain/parachain.star | 58 +++++++++++++++--------------- parachain/static_files/images.star | 2 +- relaychain/relay-chain.star | 2 +- 6 files changed, 37 insertions(+), 36 deletions(-) diff --git a/local.json b/local.json index e32c51b..8f3b3b1 100644 --- a/local.json +++ b/local.json @@ -19,8 +19,9 @@ ] }, - "para": { - "khala": { + "para": [ + { + "name":"acala", "nodes": [ { "name": "alice", @@ -35,5 +36,5 @@ } ] } - } + ] } \ No newline at end of file diff --git a/main.star b/main.star index 89395da..0395a7a 100644 --- a/main.star +++ b/main.star @@ -20,7 +20,7 @@ def run(plan, args): relay_node_detals = relay_chain.start_test_main_net_relay_nodes(plan, args) service_details["relaychains"] = relay_node_detals for paras in args["para"]: - parachain_info = parachain.run_testnet_mainnet(plan, args, paras) + parachain_info = parachain.run_testnet_mainnet(plan, paras, args) service_details["parachains"] = parachain_info prometheus_address = promethues.launch_prometheus(plan, args, service_details, prometheus_template) diff --git a/package_io/promethues.star b/package_io/promethues.star index 4a0f90e..3b947df 100644 --- a/package_io/promethues.star +++ b/package_io/promethues.star @@ -88,7 +88,7 @@ def new_config_template_data(plan, args, service_details): plan.print(node["prometheus"]) for parachain in args["para"]: - for node in args["para"][parachain]["nodes"]: + for node in parachain["nodes"]: if node["prometheus"] == True: endpoint = "{0}:{1}".format(service_details["parachains"][0]["nodes"][0]["node_details"].ip_address, service_details["parachains"][0]["nodes"][0]["node_details"].ports["prometheus"].number) diff --git a/parachain/parachain.star b/parachain/parachain.star index 3f7b70c..e4adbf6 100644 --- a/parachain/parachain.star +++ b/parachain/parachain.star @@ -26,8 +26,8 @@ def spawn_parachain(plan, chain_name, image, command, build_file): return parachain_node -def start_local_parachain_node(plan, args, parachain_name, para_id): - parachain = parachain_name.lower() +def start_local_parachain_node(plan, args, parachain_config, para_id): + parachain = parachain_config["name"].lower() parachain_details = parachain_list.parachain_images[parachain] image = parachain_details["image"] binary = parachain_details["entrypoint"] @@ -49,7 +49,7 @@ def start_local_parachain_node(plan, args, parachain_name, para_id): ] parachain_final = [] parachain_detail = {} - for node in args["para"][parachain]["nodes"]: + for node in parachain_config["nodes"]: parachain_detail = {} parachain_spawn_detail = spawn_parachain(plan, "{0}-{1}-{2}".format(parachain, node["name"], args["chain-type"]), image, exec_comexec_commandmand, build_file = raw_service.name) parachain_detail["node_details"] = parachain_spawn_detail @@ -64,39 +64,39 @@ def start_nodes(plan, args, relay_chain_ip): parachain_details = {} para_id = register_para_slot.register_para_id(plan, relay_chain_ip) parachain_details["nodes"] = start_local_parachain_node(plan, args, parachain, para_id) - parachain_details["service_name"] = "parachain_service_" + parachain - parachain_details["parachain_name"] = parachain - register_para_slot.onboard_genesis_state_and_wasm(plan, para_id, parachain, relay_chain_ip) + parachain_details["service_name"] = "parachain_service_" + parachain["name"] + parachain_details["parachain_name"] = parachain["name"] + register_para_slot.onboard_genesis_state_and_wasm(plan, para_id, parachain["name"], relay_chain_ip) final_parachain_details.append(parachain_details) return final_parachain_details -def run_testnet_mainnet(plan, args, parachain): - parachain_config = parachain +def run_testnet_mainnet(plan, parachain, args): if args["chain-type"] == "testnet": main_chain = "rococo" - if parachain == "ajuna": - parachain = "bajun" - parachain_details = parachain_list.parachain_images[parachain] + if parachain["name"] == "ajuna": + parachain["name"] = "bajun" + parachain_details = parachain_list.parachain_images[parachain["name"]] image = parachain_details["image"] base = parachain_details["base"][1] - if parachain in constant.DIFFERENT_IMAGES_FOR_TESTNET: - image = constant.DIFFERENT_IMAGES_FOR_TESTNET[parachain] + if parachain["name"] in constant.DIFFERENT_IMAGES_FOR_TESTNET: + image = constant.DIFFERENT_IMAGES_FOR_TESTNET[parachain["name"]] else: main_chain = "polkadot" - parachain_details = parachain_list.parachain_images[parachain] + parachain_details = parachain_list.parachain_images[parachain["name"]] image = parachain_details["image"] base = parachain_details["base"][2] - if parachain in constant.DIFFERENT_IMAGES_FOR_MAINNET: - image = constant.DIFFERENT_IMAGES_FOR_MAINNET[parachain] + if parachain["name"] in constant.DIFFERENT_IMAGES_FOR_MAINNET: + image = constant.DIFFERENT_IMAGES_FOR_MAINNET[parachain["name"]] + if base == None: - fail("Tesnet is not there for {}".format(parachain)) + fail("Tesnet is not there for {}".format(parachain["name"])) - if parachain in constant.NO_WS_PORT: - common_command = [ + if parachain["name"] in constant.NO_WS_PORT: + common_command = [ "--chain={0}".format(base), "--port=30333", "--rpc-port=9944", @@ -121,11 +121,11 @@ def run_testnet_mainnet(plan, args, parachain): "--unsafe-ws-external", ] + parachain_info = {parachain["name"]: {}} if parachain == "altair" or "centrifuge": common_command = common_command + ["--database=auto"] - parachain_info = {parachain: {}} - para_nodes = args["para"][parachain_config]["nodes"] - for node in para_nodes: + + for node in parachain["nodes"]: command = common_command command = command + ["--name={0}".format(node["name"])] if node["node-type"] == "collator": @@ -134,21 +134,21 @@ def run_testnet_mainnet(plan, args, parachain): if node["node-type"] == "validator": command = command + ["--validator"] - if parachain in constant.CHAIN_COMMAND: + if parachain["name"] in constant.CHAIN_COMMAND: command = command + ["--", "--chain={0}".format(main_chain)] - if parachain == "kilt-spiritnet" and args["chain-type"] == "testnet": + if parachain["name"] == "kilt-spiritnet" and args["chain-type"] == "testnet": command = command + ["--", "--chain=/node/dev-specs/kilt-parachain/peregrine-relay.json"] - if parachain in constant.BINARY_COMMAND_CHAINS: + if parachain["name"] in constant.BINARY_COMMAND_CHAINS: binary = parachain_details["entrypoint"] command = [binary] + command - node_details = node_setup.run_testnet_node_with_entrypoint(plan, image, "{0}-{1}-{2}".format(parachain, node["name"], args["chain-type"]), command) - parachain_info[parachain]["parachain_" + node["name"]] = node_details + node_details = node_setup.run_testnet_node_with_entrypoint(plan, image, "{0}-{1}-{2}".format(parachain["name"], node["name"], args["chain-type"]), command) + parachain_info[parachain["name"]]["parachain_" + node["name"]] = node_details else: - node_details = node_setup.run_testnet_node_with_command(plan, image, "{0}-{1}-{2}".format(parachain, node["name"], args["chain-type"]), command) - parachain_info[parachain]["parachain_" + node["name"]] = node_details + node_details = node_setup.run_testnet_node_with_command(plan, image, "{0}-{1}-{2}".format(parachain["name"], node["name"], args["chain-type"]), command) + parachain_info[parachain["name"]]["parachain_" + node["name"]] = node_details return parachain_info diff --git a/parachain/static_files/images.star b/parachain/static_files/images.star index acd8247..2f97466 100644 --- a/parachain/static_files/images.star +++ b/parachain/static_files/images.star @@ -108,7 +108,7 @@ parachain_images = { "encointer": { "image": "encointer/parachain:1.5.1", "entrypoint": "/usr/local/bin/encointer-collator", - "base": ["encointer-rococo-local", "encointer-rococo", "mainnet"], + "base": ["encointer-rococo-local", "encointer-rococo", "encointer-kusama"], }, "altair": { "image": "centrifugeio/centrifuge-chain:test-PR1628-354d76c-23-11-28", diff --git a/relaychain/relay-chain.star b/relaychain/relay-chain.star index 1b41bf2..4e50f69 100644 --- a/relaychain/relay-chain.star +++ b/relaychain/relay-chain.star @@ -31,7 +31,7 @@ def start_test_main_net_relay_nodes(plan, args): chain = args["relaychain"]["name"] if name == "testnet": if chain != "rococo" and chain != "westend": - fail("Please provide rococo or westent as relaychain for testnet") + fail("Please provide rococo or westend as relaychain for testnet") elif name == "mainnet": if chain != "polkadot" and chain != "kusama": fail("Please provide polkadot or kusama as relaychain for mainnet")