diff --git a/package_io/constant.star b/package_io/constant.star index 8c481b0..2cb4b70 100644 --- a/package_io/constant.star +++ b/package_io/constant.star @@ -5,7 +5,7 @@ CURL_JQ_IMAGE = "badouralix/curl-jq" NODE_IMAGE = "hugobyte/parachain-node-modules" PARA_SLOT_REGISTER_SERVICE_NAME = "para-slot-registration" BINARY_COMMAND_CHAINS = ["manta", "khala", "phala", "clover", "calamari", "subzero", "robonomics"] -NO_WS_PORT = ["acala", "frequency", "moonbeam", "karura", "ajuna", "bajun", "centrifuge", "moonsama", "encointer", "moonriver", "altair", "mangata", "khala", "phala", "turing", "bifrost", "khala", "phala"] +NO_WS_PORT = ["acala", "frequency", "moonbeam", "karura", "ajuna", "bajun", "centrifuge", "moonsama", "encointer", "moonriver", "altair", "mangata", "khala", "phala", "turing", "bifrost", "khala", "phala", "nodle"] DIFFERENT_IMAGES_FOR_MAINNET = { "centrifuge": "centrifugeio/centrifuge-chain:main-latest", @@ -24,3 +24,44 @@ DIFFERENT_IMAGES_FOR_TESTNET = { } CHAIN_COMMAND = ["manta", "moonsama", "interlay", "kintsugi-btc", "polkadex", "centrifuge", "altair", "robonomics", "kilt"] + +KUSAMA_PARACHAINS = [ + "altair", + "bajun", + "bifrost", + "calamari", + "encointer", + "khala", + "kintsugi-btc", + "litmus", + "mangata", + "moonriver", + "robonomics", + "subzero", + "turing" +] + +POLKADOT_PARACHAINS = [ + "acala", + "ajuna", + "bifrost", + "centrifuge", + "clover", + "frequency", + "integritee", + "interlay", + "karura", + "kilt", + "kylin", + "litentry", + "manta", + "moonbeam", + "moonsama", + "nodle", + "parallel", + "pendulum", + "phala", + "polkadex", + "subsocial", + "zeitgeist" +] \ No newline at end of file diff --git a/package_io/promethues.star b/package_io/promethues.star index c49df73..b83081b 100644 --- a/package_io/promethues.star +++ b/package_io/promethues.star @@ -83,7 +83,7 @@ def get_config(config_files_artifact_name): def new_config_template_data(plan, args, service_details): metrics_jobs = [] for service in service_details: - if service_details[service]["prometheus"] == True: + if "prometheus" in service_details[service] and service_details[service]["prometheus"] == True: ip = service_details[service]["ip_address"] port_number = service_details[service]["prometheus_port"] endpoint = "{0}:{1}".format(ip, port_number) diff --git a/package_io/utils.star b/package_io/utils.star index c3d5bf6..5528197 100644 --- a/package_io/utils.star +++ b/package_io/utils.star @@ -1,3 +1,5 @@ +constant = import_module("./constant.star") + NOT_PROVIDED_APPLICATION_PROTOCOL = "" NOT_PROVIDED_WAIT = "not-provided-wait" @@ -70,7 +72,20 @@ def check_config_validity(plan, args): plan.print("config for parachain is valid") else: return fail("parachain node-type can be only validator/full/collator") - + + if args["relaychain"] != {}: + chain = args["relaychain"]["name"] + if chain == "polkadot": + if len(args["para"]) != 0: + for para in args["para"]: + if para["name"] not in constant.POLKADOT_PARACHAINS: + return fail("Invalid parachain for POLKADOT") + if chain == "kusama": + if len(args["para"]) != 0: + for para in args["para"]: + if para["name"] not in constant.KUSAMA_PARACHAINS: + return fail("Invalid parachain for KUSAMA") + def upload_files(plan): plan.upload_files(src = "../parachain/static_files/configs", name = "configs") plan.upload_files(src = "../parachain/static_files/javascript", name = "javascript") diff --git a/parachain/node_setup.star b/parachain/node_setup.star index 6b3b9fb..1788219 100644 --- a/parachain/node_setup.star +++ b/parachain/node_setup.star @@ -1,11 +1,28 @@ -def run_testnet_node_with_entrypoint(plan, image, chain_name, execute_command): +def run_testnet_node_with_entrypoint(plan, prometheus, image, chain_name, execute_command, rpc_port = None, prometheus_port = None, lib2lib_port = None): + + ports = { + "ws": PortSpec(9947, transport_protocol = "TCP"), + "lib2lib": PortSpec(30333, transport_protocol = "TCP") + } + + public_ports = {} + + if rpc_port != None : + public_ports["ws"] = PortSpec(rpc_port, transport_protocol = "TCP") + + if lib2lib_port != None: + public_ports["lib2lib"] = PortSpec(lib2lib_port, transport_protocol = "TCP") + + if prometheus: + ports["metrics"] = PortSpec(9615, transport_protocol = "TCP", application_protocol = "http") + + if prometheus_port != None: + public_ports["metrics"] = PortSpec(prometheus_port, transport_protocol = "TCP", application_protocol = "http") + service_config = ServiceConfig( image = image, - ports = { - "ws": PortSpec(9947, transport_protocol = "TCP"), - "metrics": PortSpec(9615, transport_protocol = "TCP", application_protocol = "http"), - "lib": PortSpec(30333), - }, + ports = ports, + public_ports = public_ports, files = { "/app": "configs", }, @@ -15,14 +32,31 @@ def run_testnet_node_with_entrypoint(plan, image, chain_name, execute_command): return parachain -def run_testnet_node_with_command(plan, image, chain_name, execute_command): +def run_testnet_node_with_command(plan, prometheus, image, chain_name, execute_command, rpc_port = None, prometheus_port = None, lib2lib_port = None): + + ports = { + "ws": PortSpec(9947, transport_protocol = "TCP"), + "lib": PortSpec(30333) + } + + public_ports = {} + + if rpc_port != None : + public_ports["ws"] = PortSpec(rpc_port, transport_protocol = "TCP") + + if lib2lib_port != None: + public_ports["lib"] = PortSpec(lib2lib_port, transport_protocol = "TCP") + + if prometheus: + ports["metrics"] = PortSpec(9615, transport_protocol = "TCP", application_protocol = "http") + + if prometheus_port != None: + public_ports["metrics"] = PortSpec(prometheus_port, transport_protocol = "TCP", application_protocol = "http") + service_config = ServiceConfig( image = image, - ports = { - "ws": PortSpec(9947, transport_protocol = "TCP"), - "metrics": PortSpec(9615, transport_protocol = "TCP", application_protocol = "http"), - "lib": PortSpec(30333), - }, + ports = ports, + public_ports = public_ports, files = { "/app": "configs", }, @@ -31,3 +65,54 @@ def run_testnet_node_with_command(plan, image, chain_name, execute_command): parachain = plan.add_service(name = "{0}".format(chain_name), config = service_config) return parachain + +def spawn_parachain(plan, prometheus, chain_name, image, command, build_file, rpc_port = None, prometheus_port = None, lib2lib_port = None): + """Spawn a parachain node with specified configuration. + + Args: + plan (object): The Kurtosis plan. + chain_name (str): Name of the parachain. + image (str): Docker image for the parachain node. + command (list): Command to execute inside service. + build_file (str): Path to the build spec file. + + Returns: + dict: The service details of spawned parachain node. + """ + files = { + "/app": "configs", + } + if build_file != None: + files["/build"] = build_file + + ports = { + "ws": PortSpec(9946, transport_protocol = "TCP", application_protocol = "http"), + "lib": PortSpec(30333, transport_protocol = "TCP", application_protocol = "http"), + } + + public_ports = {} + + if rpc_port != None : + public_ports["ws"] = PortSpec(rpc_port, transport_protocol = "TCP", application_protocol = "http") + + if lib2lib_port != None: + public_ports["lib2lib"] = PortSpec(lib2lib_port, transport_protocol = "TCP", application_protocol = "http") + + if prometheus: + ports["metrics"] = PortSpec(9615, transport_protocol = "TCP", application_protocol = "http") + + if prometheus_port != None: + public_ports["metrics"] = PortSpec(prometheus_port, transport_protocol = "TCP", application_protocol = "http") + + parachain_node = plan.add_service( + name = "{}".format(chain_name), + config = ServiceConfig( + image = image, + files = files, + ports = ports, + public_ports = public_ports, + entrypoint = command, + ), + ) + + return parachain_node diff --git a/parachain/parachain.star b/parachain/parachain.star index 8bec0e9..32d88a1 100644 --- a/parachain/parachain.star +++ b/parachain/parachain.star @@ -5,42 +5,7 @@ parachain_list = import_module("./static_files/images.star") node_setup = import_module("./node_setup.star") utils = import_module("../package_io/utils.star") -def spawn_parachain(plan, chain_name, image, command, build_file): - """Spawn a parachain node with specified configuration. - - Args: - plan (object): The Kurtosis plan. - chain_name (str): Name of the parachain. - image (str): Docker image for the parachain node. - command (list): Command to execute inside service. - build_file (str): Path to the build spec file. - - Returns: - dict: The service details of spawned parachain node. - """ - files = { - "/app": "configs", - } - if build_file != None: - files["/build"] = build_file - - parachain_node = plan.add_service( - name = "{}".format(chain_name), - config = ServiceConfig( - image = image, - files = files, - ports = { - "ws": PortSpec(9946, transport_protocol = "TCP", application_protocol = "http"), - "metrics": PortSpec(9615, transport_protocol = "TCP", application_protocol = "http"), - "lib": PortSpec(30333, transport_protocol = "TCP", application_protocol = "http"), - }, - entrypoint = command, - ), - ) - - return parachain_node - -def start_local_parachain_node(plan, args, parachain_config, para_id): +def start_local_parachain_node(plan, args, parachain_config, para_id, rpc_port = [], prometheus_port = [], lib2lib_port = []): """Start local parachain nodes based on configuration. Args: @@ -61,8 +26,12 @@ def start_local_parachain_node(plan, args, parachain_config, para_id): raw_service = build_spec.create_parachain_build_spec_with_para_id(plan, image, binary, chain_name, chain_base, para_id) parachain_final = {} - for node in parachain_config["nodes"]: + for idx, node in enumerate(parachain_config["nodes"]): parachain_detail = {} + rpc_port_value = rpc_port[idx] if rpc_port else None + prometheus_port_value = prometheus_port[idx] if prometheus_port else None + lib2lib_port_value = lib2lib_port[idx] if lib2lib_port else None + if parachain in constant.NO_WS_PORT: exec_comexec_commandmand = [ "/bin/bash", @@ -75,19 +44,27 @@ def start_local_parachain_node(plan, args, parachain_config, para_id): "-c", "{0} --base-path=/tmp/{1} --chain=/build/{1}-raw.json --ws-port=9946 --port=30333 --rpc-port=9933 --ws-external --rpc-external --prometheus-external --rpc-cors=all --{2} --collator --rpc-methods=unsafe --force-authoring --execution=wasm -- --chain=/app/raw-polkadot.json --execution=wasm".format(binary, chain_name, node["name"]), ] - parachain_spawn_detail = spawn_parachain(plan, "{0}-{1}-{2}".format(parachain, node["name"].lower(), args["chain-type"]), image, exec_comexec_commandmand, build_file = raw_service.name) + + build_file = raw_service.name + parachain_spawn_detail = node_setup.spawn_parachain(plan, node["prometheus"], "{0}-{1}-{2}".format(parachain, node["name"].lower(), args["chain-type"]), image, exec_comexec_commandmand, build_file, rpc_port_value, prometheus_port_value, lib2lib_port_value) 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) - parachain_detail["endpoint_prometheus"] = utils.get_service_url("tcp", parachain_spawn_detail.ip_address, parachain_spawn_detail.ports["metrics"].number) - parachain_detail["service_name"] = parachain_spawn_detail.name - parachain_detail["prometheus_port"] = parachain_spawn_detail.ports["metrics"].number parachain_detail["ip_address"] = parachain_spawn_detail.ip_address parachain_detail["prometheus"] = node["prometheus"] parachain_detail["node-type"] = node["node-type"] + if node["prometheus"] == True: + parachain_detail["prometheus_port"] = parachain_spawn_detail.ports["metrics"].number + if prometheus_port_value != None or prometheus_port_value != 0: + parachain_detail["prometheus_public_port"] = prometheus_port_value + parachain_detail["endpoint_prometheus"] = utils.get_service_url("tcp", "127.0.0.1", prometheus_port_value) + if rpc_port_value != None: + parachain_detail["endpoint_public"] = utils.get_service_url("ws", "127.0.0.1", rpc_port_value) + parachain_final[parachain_spawn_detail.name] = parachain_detail + return parachain_final -def start_nodes(plan, args, relay_chain_ip): +def start_nodes(plan, args, relay_chain_ip, rpc_port = [[]], prometheus_port = [[]], lib2lib_port = [[]]): """Start multiple parachain nodes. Args: @@ -100,14 +77,20 @@ def start_nodes(plan, args, relay_chain_ip): """ parachains = args["para"] final_parachain_details = {} - for parachain in parachains: + for idx, parachain in enumerate(parachains): para_id = register_para_slot.register_para_id(plan, relay_chain_ip) - parachain_details = start_local_parachain_node(plan, args, parachain, para_id) + + rpc_port_idx = rpc_port[idx] if idx < len(rpc_port) else [] + prometheus_port_idx = prometheus_port[idx] if idx < len(prometheus_port) else [] + lib2lib_port_idx = lib2lib_port[idx] if idx < len(lib2lib_port) else [] + + parachain_details = start_local_parachain_node(plan, args, parachain, para_id, rpc_port_idx, prometheus_port_idx, lib2lib_port_idx) register_para_slot.onboard_genesis_state_and_wasm(plan, para_id, parachain["name"], relay_chain_ip) final_parachain_details.update(parachain_details) + return final_parachain_details -def run_testnet_mainnet(plan, parachain, args): +def run_testnet_mainnet(plan, parachain, args, rpc_port = [], prometheus_port = [], lib2lib_port = []): """Run a testnet or mainnet based on configuration. Args: @@ -176,7 +159,14 @@ def run_testnet_mainnet(plan, parachain, args): common_command = [x for x in common_command if x != "--port=30333"] final_parachain_info = {} - for node in parachain["nodes"]: + for idx, node in enumerate(parachain["nodes"]): + rpc_port_value = rpc_port[idx] if rpc_port else None + prometheus_port_value = prometheus_port[idx] if prometheus_port else None + lib2lib_port_value = lib2lib_port[idx] if lib2lib_port else None + + if prometheus_port_value == 0: + prometheus_port_value = None + command = common_command command = command + ["--name={0}".format(node["name"])] if node["node-type"] == "collator": @@ -195,27 +185,37 @@ def run_testnet_mainnet(plan, parachain, args): binary = parachain_details["entrypoint"] command = [binary] + command node_info = {} - node_details = node_setup.run_testnet_node_with_entrypoint(plan, image, "{0}-{1}-{2}".format(parachain["name"], node["name"], args["chain-type"]), command) + node_details = node_setup.run_testnet_node_with_entrypoint(plan, node["prometheus"], image, "{0}-{1}-{2}".format(parachain["name"], node["name"], args["chain-type"]), command, rpc_port_value, prometheus_port_value, lib2lib_port_value) node_info["service_name"] = node_details.name node_info["endpoint"] = utils.get_service_url("ws", node_details.ip_address, node_details.ports["ws"].number) - node_info["endpoint_prometheus"] = utils.get_service_url("tcp", node_details.ip_address, node_details.ports["metrics"].number) - node_info["service_name"] = node_details.name node_info["ip_address"] = node_details.ip_address - node_info["prometheus_port"] = node_details.ports["metrics"].number node_info["prometheus"] = node["prometheus"] node_info["node-type"] = node["node-type"] + if node["prometheus"] == True: + node_info["prometheus_port"] = node_details.ports["metrics"].number + if prometheus_port_value != None: + node_info["prometheus_public_port"] = prometheus_port_value + node_info["endpoint_prometheus"] = utils.get_service_url("tcp", "127.0.0.1", prometheus_port_value) + if rpc_port_value != None: + node_info["endpoint_public"] = utils.get_service_url("ws", "127.0.0.1", rpc_port_value) + final_parachain_info[node_details.name] = node_info else: node_info = {} - node_details = node_setup.run_testnet_node_with_command(plan, image, "{0}-{1}-{2}".format(parachain["name"], node["name"], args["chain-type"]), command) + node_details = node_setup.run_testnet_node_with_command(plan, node["prometheus"], image, "{0}-{1}-{2}".format(parachain["name"], node["name"], args["chain-type"]), command, rpc_port_value, prometheus_port_value, lib2lib_port_value) node_info["service_name"] = node_details.name node_info["endpoint"] = utils.get_service_url("ws", node_details.ip_address, node_details.ports["ws"].number) - node_info["endpoint_prometheus"] = utils.get_service_url("tcp", node_details.ip_address, node_details.ports["metrics"].number) - node_info["service_name"] = node_details.name node_info["ip_address"] = node_details.ip_address - node_info["prometheus_port"] = node_details.ports["metrics"].number node_info["prometheus"] = node["prometheus"] node_info["node-type"] = node["node-type"] + if node["prometheus"] == True: + node_info["prometheus_port"] = node_details.ports["metrics"].number + if prometheus_port_value != None: + node_info["prometheus_public_port"] = prometheus_port_value + node_info["endpoint_prometheus"] = utils.get_service_url("tcp", "127.0.0.1", prometheus_port_value) + if rpc_port_value != None: + node_info["endpoint_public"] = utils.get_service_url("ws", "127.0.0.1", rpc_port_value) + final_parachain_info[node_details.name] = node_info return final_parachain_info diff --git a/relaychain/relay-chain.star b/relaychain/relay-chain.star index 09d6102..455ef3b 100644 --- a/relaychain/relay-chain.star +++ b/relaychain/relay-chain.star @@ -1,7 +1,7 @@ utils = import_module("../package_io/utils.star") -def start_relay_chain(plan, args): +def start_relay_chain(plan, args, rpc_port = [], prometheus_port = [], lib2lib_port = []): """ Starts relay chain nodes based on the provided arguments. @@ -16,45 +16,66 @@ def start_relay_chain(plan, args): chain = args["relaychain"]["name"] final_details = {} - for relay_node in args["relaychain"]["nodes"]: - - - command = "polkadot --rpc-external --rpc-cors=all --rpc-methods=unsafe --chain {0} --name={1} --execution=wasm --prometheus-external".format(chain, relay_node["name"]) - - if relay_node["node-type"] == "validator": - command = command + " --validator --insecure-validator-i-know-what-i-do" - elif relay_node["node-type"] == "archive": - command = command + " --pruning=archive" - - plan.print(command) - - exec_command = ["bin/sh", "-c", command] + ports = { + "ws": PortSpec(9944, transport_protocol = "TCP"), + "lib2lib": PortSpec(30333, transport_protocol = "TCP") + } + + relay_nodes = args["relaychain"]["nodes"] + for idx, relay_node in enumerate(relay_nodes): + public_ports = {} + + rpc_port_value = rpc_port[idx] if rpc_port else None + prometheus_port_value = prometheus_port[idx] if prometheus_port else None + lib2lib_port_value = lib2lib_port[idx] if lib2lib_port else None + + + if rpc_port_value != None : + public_ports["ws"] = PortSpec(rpc_port_value, transport_protocol = "TCP") + + if lib2lib_port_value != None: + public_ports["lib2lib"] = PortSpec(lib2lib_port_value, transport_protocol = "TCP") + + if relay_node["prometheus"]: + ports["metrics"] = PortSpec(9615, transport_protocol="TCP") + + if prometheus_port_value == 0: + prometheus_port_value = None + + if prometheus_port_value != None: + public_ports["metrics"] = PortSpec(prometheus_port_value, transport_protocol = "TCP") + + exec_command = ["bin/sh", "-c", "polkadot --rpc-external --rpc-cors=all --rpc-methods=unsafe --chain {0} --name={1} --execution=wasm --prometheus-external".format(chain, relay_node["name"])] service_details = plan.add_service( name = "{0}-{1}-{2}".format(name, chain, relay_node["name"]), config = ServiceConfig( image = "parity/polkadot:latest", - ports = { - "ws": PortSpec(9944, transport_protocol = "TCP"), - "metrics": PortSpec(9615, transport_protocol = "TCP"), - }, + ports = ports, + public_ports = public_ports, entrypoint = exec_command, ), ) relay_node_details = {} relay_node_details["endpoint"] = utils.get_service_url("ws", service_details.ip_address, service_details.ports["ws"].number) - relay_node_details["endpoint_prometheus"] = utils.get_service_url("tcp" , service_details.ip_address, service_details.ports["metrics"].number) relay_node_details["service_name"] = service_details.name - relay_node_details["prometheus_port"] = service_details.ports["metrics"].number relay_node_details["prometheus"] = relay_node["prometheus"] relay_node_details["ip_address"] = service_details.ip_address relay_node_details["node-type"] = relay_node["node-type"] + if relay_node["prometheus"] == True: + relay_node_details["prometheus_port"] = service_details.ports["metrics"].number + if prometheus_port_value != None: + relay_node_details["prometheus_public_port"] = prometheus_port_value + relay_node_details["endpoint_prometheus"] = utils.get_service_url("tcp", "127.0.0.1", prometheus_port_value) + if rpc_port_value != None: + relay_node_details["endpoint_public"] = utils.get_service_url("ws", "127.0.0.1", rpc_port_value) + final_details[service_details.name] = relay_node_details return final_details -def start_test_main_net_relay_nodes(plan, args): +def start_test_main_net_relay_nodes(plan, args, rpc_port = [], prometheus_port = [], lib2lib_port = []): """ Starts testnet/mainnet relay nodes based on the provided arguments. @@ -75,25 +96,11 @@ def start_test_main_net_relay_nodes(plan, args): if chain != "polkadot" and chain != "kusama": fail("Please provide polkadot or kusama as relaychain for mainnet") - relay_node_details = start_relay_chain(plan, args) + relay_node_details = start_relay_chain(plan, args, rpc_port, prometheus_port, lib2lib_port) return relay_node_details -def spawn_multiple_relay(plan, count): - """ - Spawns multiple local relay chain nodes. - - Args: - plan (object): The Kurtosis plan object for orchestrating the test. - count (int): Number of relay nodes to spawn. - """ - node_list = ["alice", "bob", "dave", "charlie"] - port = 9944 - for i in range(0, count): - port = port + count - start_relay_chain_local(plan, node_list[i]) - -def start_relay_chains_local(plan, args): +def start_relay_chains_local(plan, args, rpc_port = [], prometheus_port = [], lib2lib_port = []): """ Starts local relay chain nodes based on the provided arguments. @@ -104,27 +111,48 @@ def start_relay_chains_local(plan, args): Returns: list: List of dictionaries containing sevice details of started relay chain nodes. """ + name = args["chain-type"] + chain = args["relaychain"]["name"] + + if name == "local": + if chain != "rococo-local": + fail("Please provide rococo-local as relaychain for localnet") + relay_nodes = args["relaychain"]["nodes"] if len(relay_nodes) < 2: fail("relay nodes must contain at least two nodes") final_details = {} - for node in relay_nodes: + for idx, node in enumerate(relay_nodes): relay_detail = {} - service_details = start_relay_chain_local(plan, args, node["name"]) + rpc_port_value = rpc_port[idx] if rpc_port else None + prometheus_port_value = prometheus_port[idx] if prometheus_port else None + lib2lib_port_value = lib2lib_port[idx] if lib2lib_port else None + + if prometheus_port_value == 0: + prometheus_port_value = None + + service_details = start_relay_chain_local(plan, args, node["name"], node["prometheus"], rpc_port_value, prometheus_port_value, lib2lib_port_value) + relay_detail["endpoint"] = utils.get_service_url("ws", service_details.ip_address, service_details.ports["ws"].number) - relay_detail["endpoint_prometheus"] = utils.get_service_url("tcp" , service_details.ip_address, service_details.ports["metrics"].number) relay_detail["service_name"] = service_details.name - relay_detail["prometheus_port"] = service_details.ports["metrics"].number relay_detail["prometheus"] = node["prometheus"] relay_detail["ip_address"] = service_details.ip_address relay_detail["node-type"] = node["node-type"] + if node["prometheus"] == True: + relay_detail["prometheus_port"] = service_details.ports["metrics"].number + if prometheus_port_value != None: + relay_detail["prometheus_public_port"] = prometheus_port_value + relay_detail["endpoint_prometheus"] = utils.get_service_url("tcp", "127.0.0.1", prometheus_port_value) + if rpc_port_value != None: + relay_detail["endpoint_public"] = utils.get_service_url("ws", "127.0.0.1", rpc_port_value) + final_details[service_details.name] = relay_detail return final_details -def start_relay_chain_local(plan, args, name): +def start_relay_chain_local(plan, args, name, prometheus, rpc_port = None, prometheus_port = None, lib2lib_port = None): """ Starts a local relay chain node based on the provided arguments. @@ -135,6 +163,25 @@ def start_relay_chain_local(plan, args, name): Returns: object: Service details of the started relay chain node. """ + ports = { + "ws": PortSpec(9944, transport_protocol = "TCP"), + "lib2lib": PortSpec(30333, transport_protocol = "TCP"), + } + + public_ports = {} + + if rpc_port != None : + public_ports["ws"] = PortSpec(rpc_port, transport_protocol = "TCP") + + if lib2lib_port != None: + public_ports["lib2lib"] = PortSpec(lib2lib_port, transport_protocol = "TCP") + + if prometheus: + ports["metrics"] = PortSpec(9615, transport_protocol="TCP") + + if prometheus_port != None: + public_ports["metrics"] = PortSpec(prometheus_port, transport_protocol = "TCP") + exec_command = ["bin/sh", "-c", "polkadot --base-path=/data --chain=/app/raw-polkadot.json --validator --rpc-external --port=30333 --rpc-cors=all --name=alice --{0} --rpc-methods=unsafe --execution=wasm --prometheus-external --insecure-validator-i-know-what-i-do".format(name)] service_details = plan.add_service( name = "{0}-{1}".format(args["relaychain"]["name"], name), @@ -143,12 +190,9 @@ def start_relay_chain_local(plan, args, name): files = { "/app": "configs", }, - ports = { - "ws": PortSpec(9944, transport_protocol = "TCP"), - "metrics": PortSpec(9615, transport_protocol = "TCP"), - "lib2lib": PortSpec(30333, transport_protocol = "TCP"), - }, - entrypoint = exec_command, + ports = ports, + public_ports = public_ports, + entrypoint = exec_command, ), ) return service_details