From 1541ba9d167248f2f7816c8b26bbcbc47a2f7472 Mon Sep 17 00:00:00 2001 From: Shanith K K Date: Tue, 14 Nov 2023 15:13:46 +0530 Subject: [PATCH] chore: return nodes details --- local.json | 2 +- main.star | 9 ++++++--- parachain/node_setup.star | 10 ++++++---- parachain/parachain.star | 10 +++++++--- relaychain/relay-chain.star | 21 +++++++++++++++++++-- 5 files changed, 39 insertions(+), 13 deletions(-) diff --git a/local.json b/local.json index 47a8d62..1cb471f 100644 --- a/local.json +++ b/local.json @@ -1,7 +1,7 @@ { "chain-type": "testnet", "relaychain": { - "name": "polkadot", + "name": "rococo", "nodes": [ { "name": "alice", diff --git a/main.star b/main.star index 8c391ce..6dc965b 100644 --- a/main.star +++ b/main.star @@ -11,9 +11,12 @@ def run(plan, args): parachain.start_nodes(plan, args, relay_chain_details["relay_service_alice"].ip_address) else: - # relay_chain.start_relay_chain(plan, args) - + if len(args["relaychain"]) != 0: + 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.run_testnet_mainnet(plan, args, paras) + parachain_info = parachain.run_testnet_mainnet(plan, args, paras) + plan.print(parachain_info) + service_details["parachains"] = parachain_info return service_details diff --git a/parachain/node_setup.star b/parachain/node_setup.star index bcd33f5..479a4b0 100644 --- a/parachain/node_setup.star +++ b/parachain/node_setup.star @@ -1,4 +1,4 @@ -def run_testnet_node_with_entrypoint(plan, args, image, chain_name, execute_command): +def run_testnet_node_with_entrypoint(plan, image, chain_name, execute_command): service_config = ServiceConfig( image = image, ports = { @@ -9,10 +9,11 @@ def run_testnet_node_with_entrypoint(plan, args, image, chain_name, execute_comm }, entrypoint = execute_command, ) + parachain = plan.add_service(name = "{0}".format(chain_name), config = service_config) - plan.add_service(name = "{0}".format(chain_name), config = service_config) + return parachain -def run_testnet_node_with_command(plan, args, image, chain_name, execute_command): +def run_testnet_node_with_command(plan, image, chain_name, execute_command): service_config = ServiceConfig( image = image, ports = { @@ -23,5 +24,6 @@ def run_testnet_node_with_command(plan, args, image, chain_name, execute_command }, cmd = execute_command, ) + parachain = plan.add_service(name = "{0}".format(chain_name), config = service_config) - plan.add_service(name = "{0}".format(chain_name), config = service_config) + return parachain diff --git a/parachain/parachain.star b/parachain/parachain.star index 917d326..831219b 100644 --- a/parachain/parachain.star +++ b/parachain/parachain.star @@ -90,7 +90,7 @@ def run_testnet_mainnet(plan, args, parachain): "--unsafe-rpc-external", "--unsafe-ws-external", ] - + parachain_info = {parachain: {}} para_nodes = args["para"][parachain]["nodes"] for node in para_nodes: command = common_command @@ -105,7 +105,11 @@ def run_testnet_mainnet(plan, args, parachain): binary = parachain_details["entrypoint"] command = [binary] + command - node_setup.run_testnet_node_with_entrypoint(plan, args, image, "{0}-{1}".format(parachain, node["name"]), command) + node_details = node_setup.run_testnet_node_with_entrypoint(plan, image, "{0}-{1}".format(parachain, node["name"]), command) + parachain_info[parachain]["parachain_" + node["name"]] = node_details else: - node_setup.run_testnet_node_with_command(plan, args, image, "{0}-{1}".format(parachain, node["name"]), command) + node_details = node_setup.run_testnet_node_with_command(plan, image, "{0}-{1}".format(parachain, node["name"]), command) + parachain_info[parachain]["parachain_" + node["name"]] = node_details + + return parachain_info diff --git a/relaychain/relay-chain.star b/relaychain/relay-chain.star index c892254..02e5c2c 100644 --- a/relaychain/relay-chain.star +++ b/relaychain/relay-chain.star @@ -1,11 +1,12 @@ def start_relay_chain(plan, args): name = args["chain-type"] chain = args["relaychain"]["name"] + relay_node_details = {} for relay_node in args["relaychain"]["nodes"]: port = relay_node["port"] exec_command = ["bin/sh", "-c", "polkadot --rpc-external --rpc-cors=all --rpc-methods=unsafe --chain {0} --name={1} --execution=wasm".format(chain, relay_node["name"])] - plan.add_service( - name = "{0}-{1}".format(name, relay_node["name"]), + relay_node_detail = plan.add_service( + name = "{0}-{1}-{2}".format(name, chain, relay_node["name"]), config = ServiceConfig( image = "parity/polkadot:latest", ports = { @@ -17,6 +18,22 @@ def start_relay_chain(plan, args): entrypoint = exec_command, ), ) + relay_node_details["relay_service_" + relay_node["name"]] = relay_node_detail + + return relay_node_details + +def start_test_main_net_relay_nodes(plan, args): + name = args["chain-type"] + chain = args["relaychain"]["name"] + if name == "testnet": + if chain != "rococo" and chain != "westend": + fail("Please provide rococo or westent as relaychain for testnet") + elif name == "mainnet": + if chain != "polkadot" and chain != "kusama": + fail("Please provide polkadot or kusama as relaychain for mainnet") + relay_node_details = start_relay_chain(plan, args) + + return relay_node_details def spawn_multiple_relay(plan, count): list = ["alice", "bob", "dave", "charlie"]