From 85267cd2a9757b286f374d6d187a9bda7ffb7041 Mon Sep 17 00:00:00 2001 From: Riya Singh Date: Tue, 23 Jan 2024 17:35:00 +0530 Subject: [PATCH] fix: fix explorer not working in mainnet (#192) --- package_io/constant.star | 1 + parachain/node_setup.star | 88 +++++++++++++++++++++--------- parachain/parachain.star | 74 ++++++++++++++++++------- parachain/static_files/images.star | 2 +- 4 files changed, 117 insertions(+), 48 deletions(-) diff --git a/package_io/constant.star b/package_io/constant.star index 360107a..600144b 100644 --- a/package_io/constant.star +++ b/package_io/constant.star @@ -5,6 +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"] +WS_PORT = ["robonomics", "parallel", "subsocial", "litmus", "pendulum", "kilt"] DIFFERENT_IMAGES_FOR_MAINNET = { "centrifuge": "centrifugeio/centrifuge-chain:main-latest", diff --git a/parachain/node_setup.star b/parachain/node_setup.star index 56decac..6bd43b7 100644 --- a/parachain/node_setup.star +++ b/parachain/node_setup.star @@ -1,4 +1,6 @@ -def run_testnet_node_with_entrypoint(plan, prometheus, image, chain_name, execute_command, rpc_port = None, prometheus_port = None, lib2lib_port = None): +constant = import_module("../package_io/constant.star") + +def run_testnet_node_with_entrypoint(plan, prometheus, image, chain_name, service_name, execute_command, rpc_port = None, prometheus_port = None, lib2lib_port = None, ws_port = None): """ Spawn a parachain node with specified configuration with entrypoint. @@ -6,6 +8,7 @@ def run_testnet_node_with_entrypoint(plan, prometheus, image, chain_name, execut prometheus (bool): Boolean value to enable metrics for a given node. image (string): Docker image for the parachain node. chain_name (string): Name of the parachain. + service_name (string): Name of the service. execute_command (list): Command to execute inside service. rpc_port (int, optional): The RPC port value. Defaults to None. prometheus_port (int, optional): The Prometheus port value. Defaults to None. @@ -13,17 +16,28 @@ def run_testnet_node_with_entrypoint(plan, prometheus, image, chain_name, execut Returns: dict: The service details of spawned parachain node. - """ - ports = { - "ws": PortSpec(9947, transport_protocol = "TCP"), + """ + + if chain_name in constant.WS_PORT: + ports = { + "ws": PortSpec(9944, transport_protocol = "TCP"), + "rpc": PortSpec(9947, transport_protocol = "TCP"), "lib2lib": PortSpec(30333, transport_protocol = "TCP") } - + else: + ports = { + "ws": PortSpec(9947, transport_protocol = "TCP"), + "lib2lib": PortSpec(30333, transport_protocol = "TCP") + } + public_ports = {} - if rpc_port != None : + if ws_port != None: + public_ports["rpc"] = PortSpec(rpc_port, transport_protocol = "TCP") + public_ports["ws"] = PortSpec(ws_port, transport_protocol = "TCP") + elif 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") @@ -42,11 +56,11 @@ def run_testnet_node_with_entrypoint(plan, prometheus, image, chain_name, execut }, entrypoint = execute_command, ) - parachain = plan.add_service(name = "{0}".format(chain_name), config = service_config) + parachain = plan.add_service(name = "{0}".format(service_name), config = service_config) return parachain -def run_testnet_node_with_command(plan, prometheus, image, chain_name, execute_command, rpc_port = None, prometheus_port = None, lib2lib_port = None): +def run_testnet_node_with_command(plan, prometheus, image, chain_name, service_name, execute_command, rpc_port = None, prometheus_port = None, lib2lib_port = None, ws_port = None): """ Spawn a parachain node with specified configuration with command. @@ -54,6 +68,7 @@ def run_testnet_node_with_command(plan, prometheus, image, chain_name, execute_c prometheus (bool): Boolean value to enable metrics for a given node. image (string): Docker image for the parachain node. chain_name (string): Name of the parachain. + service_name (string): Name of the service. execute_command (list): Command to execute inside service. rpc_port (int, optional): The RPC port value. Defaults to None. prometheus_port (int, optional): The Prometheus port value. Defaults to None. @@ -62,14 +77,24 @@ def run_testnet_node_with_command(plan, prometheus, image, chain_name, execute_c Returns: dict: The service details of spawned parachain node. """ - ports = { - "ws": PortSpec(9947, transport_protocol = "TCP"), - "lib": PortSpec(30333) - } - public_ports = {} + if chain_name in constant.WS_PORT: + ports = { + "ws": PortSpec(9944, transport_protocol = "TCP"), + "rpc": PortSpec(9947, transport_protocol = "TCP"), + "lib": PortSpec(30333) + } + else: + ports = { + "ws": PortSpec(9947, transport_protocol = "TCP"), + "lib": PortSpec(30333) + } - if rpc_port != None : + public_ports = {} + if ws_port != None: + public_ports["rpc"] = PortSpec(rpc_port, transport_protocol = "TCP") + public_ports["ws"] = PortSpec(ws_port, transport_protocol = "TCP") + elif rpc_port != None : public_ports["ws"] = PortSpec(rpc_port, transport_protocol = "TCP") if lib2lib_port != None: @@ -90,11 +115,11 @@ def run_testnet_node_with_command(plan, prometheus, image, chain_name, execute_c }, cmd = execute_command, ) - parachain = plan.add_service(name = "{0}".format(chain_name), config = service_config) + parachain = plan.add_service(name = "{0}".format(service_name), config = service_config) return parachain -def spawn_parachain(plan, prometheus, image, chain_name, execute_command, build_file, rpc_port = None, prometheus_port = None, lib2lib_port = None): +def spawn_parachain(plan, prometheus, image, chain_name, service_name, execute_command, build_file, rpc_port = None, prometheus_port = None, lib2lib_port = None, ws_port = None): """ Spawn a parachain node with specified configuration. @@ -102,6 +127,7 @@ def spawn_parachain(plan, prometheus, image, chain_name, execute_command, build_ prometheus (bool): Boolean value to enable metrics for a given node. image (string): Docker image for the parachain node. chain_name (string): Name of the parachain. + service_name (string): Name of the service. execute_command (list): Command to execute inside service. build_file (string): Path to the build spec file. rpc_port (int, optional): The RPC port value. Defaults to None. @@ -116,15 +142,25 @@ def spawn_parachain(plan, prometheus, image, chain_name, execute_command, build_ } if build_file != None: files["/build"] = build_file - - ports = { - "ws": PortSpec(9946, transport_protocol = "TCP", application_protocol = "http"), - "lib2lib": PortSpec(30333, transport_protocol = "TCP", application_protocol = "http"), - } + if chain_name in constant.WS_PORT: + ports = { + "ws": PortSpec(9944, transport_protocol = "TCP", application_protocol = "http"), + "rpc": PortSpec(9947, transport_protocol = "TCP", application_protocol = "http"), + "lib2lib": PortSpec(30333, transport_protocol = "TCP", application_protocol = "http"), + } + else: + ports = { + "ws": PortSpec(9947, transport_protocol = "TCP", application_protocol = "http"), + "lib2lib": PortSpec(30333, transport_protocol = "TCP", application_protocol = "http"), + } + public_ports = {} - - if rpc_port != None : + + if ws_port != None: + public_ports["rpc"] = PortSpec(rpc_port, transport_protocol = "TCP", application_protocol = "http") + public_ports["ws"] = PortSpec(ws_port, transport_protocol = "TCP", application_protocol = "http") + elif rpc_port != None : public_ports["ws"] = PortSpec(rpc_port, transport_protocol = "TCP", application_protocol = "http") if lib2lib_port != None: @@ -137,7 +173,7 @@ def spawn_parachain(plan, prometheus, image, chain_name, execute_command, build_ public_ports["metrics"] = PortSpec(prometheus_port, transport_protocol = "TCP", application_protocol = "http") parachain_node = plan.add_service( - name = "{}".format(chain_name), + name = "{}".format(service_name), config = ServiceConfig( image = image, files = files, @@ -147,4 +183,4 @@ def spawn_parachain(plan, prometheus, image, chain_name, execute_command, build_ ), ) - return parachain_node + return parachain_node \ No newline at end of file diff --git a/parachain/parachain.star b/parachain/parachain.star index 82f1749..1fdd616 100644 --- a/parachain/parachain.star +++ b/parachain/parachain.star @@ -33,19 +33,28 @@ def start_local_parachain_node(plan, chain_type, parachain, para_id): rpc_port = node["ports"]["rpc_port"] lib2lib_port = node["ports"]["lib2lib_port"] prometheus_port = node["ports"]["prometheus_port"] if node["prometheus"] else None + ws_port = node["ports"]["ws_port"] if parachain["name"] in constant.WS_PORT else None else: rpc_port = None lib2lib_port = None prometheus_port = None - - exec_comexec_commandmand = [ - "/bin/bash", - "-c", - "{0} --base-path=/tmp/{1} --chain=/build/{1}-raw.json --rpc-port=9946 --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"]), - ] + ws_port = None + + if chain_name in constant.WS_PORT: + exec_comexec_commandmand = [ + "/bin/bash", + "-c", + "{0} --base-path=/tmp/{1} --chain=/build/{1}-raw.json --ws-port=9944 --port=30333 --rpc-port=9947 --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"]), + ] + else: + exec_comexec_commandmand = [ + "/bin/bash", + "-c", + "{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 - parachain_spawn_detail = node_setup.spawn_parachain(plan, node["prometheus"], image, "{0}-{1}-{2}".format(chain_name, node["name"], chain_type), exec_comexec_commandmand, build_file, rpc_port, prometheus_port, lib2lib_port) + 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) parachain_detail["ip_address"] = parachain_spawn_detail.ip_address @@ -56,7 +65,9 @@ def start_local_parachain_node(plan, chain_type, parachain, para_id): if prometheus_port != None: parachain_detail["prometheus_public_port"] = prometheus_port parachain_detail["endpoint_prometheus"] = utils.get_service_url("tcp", "127.0.0.1", prometheus_port) - if rpc_port != None: + if ws_port != None: + parachain_detail["endpoint_public"] = utils.get_service_url("ws", "127.0.0.1", ws_port) + elif rpc_port != None: parachain_detail["endpoint_public"] = utils.get_service_url("ws", "127.0.0.1", rpc_port) parachain_final[parachain_spawn_detail.name] = parachain_detail @@ -118,15 +129,30 @@ def run_testnet_mainnet(plan, chain_type, relaychain_name, parachain): if base == None: fail("Tesnet is not there for {}".format(parachain["name"])) - common_command = [ - "--chain={0}".format(base), - "--port=30333", - "--rpc-port=9947", - "--prometheus-external", - "--rpc-cors=all", - "--rpc-external", - "--rpc-methods=unsafe", - "--unsafe-rpc-external", + if parachain["name"] in constant.WS_PORT: + common_command = [ + "--chain={0}".format(base), + "--port=30333", + "--ws-port=9944", + "--rpc-port=9947", + "--prometheus-external", + "--rpc-cors=all", + "--rpc-external", + "--ws-external", + "--rpc-methods=unsafe", + "--unsafe-rpc-external", + "--unsafe-ws-external", + ] + else: + common_command = [ + "--chain={0}".format(base), + "--port=30333", + "--rpc-port=9947", + "--prometheus-external", + "--rpc-cors=all", + "--rpc-external", + "--rpc-methods=unsafe", + "--unsafe-rpc-external", ] parachain_info = {parachain["name"]: {}} @@ -144,10 +170,12 @@ def run_testnet_mainnet(plan, chain_type, relaychain_name, parachain): rpc_port = node["ports"]["rpc_port"] lib2lib_port = node["ports"]["lib2lib_port"] prometheus_port = node["ports"]["prometheus_port"] if node["prometheus"] else None + ws_port = node["ports"]["ws_port"] if parachain["name"] in constant.WS_PORT else None else: rpc_port = None lib2lib_port = None prometheus_port = None + ws_port = None command = common_command command = command + ["--name={0}".format(node["name"])] @@ -167,7 +195,7 @@ def run_testnet_mainnet(plan, chain_type, relaychain_name, parachain): binary = parachain_details["entrypoint"] command = [binary] + command node_info = {} - node_details = node_setup.run_testnet_node_with_entrypoint(plan, node["prometheus"], image, "{0}-{1}-{2}".format(parachain["name"], node["name"], chain_type), command, rpc_port, prometheus_port, lib2lib_port) + node_details = node_setup.run_testnet_node_with_entrypoint(plan, node["prometheus"], image, parachain["name"], "{0}-{1}-{2}".format(parachain["name"], node["name"], chain_type), command, rpc_port, prometheus_port, lib2lib_port, ws_port) 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["ip_address"] = node_details.ip_address @@ -178,14 +206,16 @@ def run_testnet_mainnet(plan, chain_type, relaychain_name, parachain): if prometheus_port != None: node_info["prometheus_public_port"] = prometheus_port node_info["endpoint_prometheus"] = utils.get_service_url("tcp", "127.0.0.1", prometheus_port) - if rpc_port != None: + if ws_port != None: + node_info["endpoint_public"] = utils.get_service_url("ws", "127.0.0.1", ws_port) + elif rpc_port != None: node_info["endpoint_public"] = utils.get_service_url("ws", "127.0.0.1", rpc_port) final_parachain_info[node_details.name] = node_info else: node_info = {} - node_details = node_setup.run_testnet_node_with_command(plan, node["prometheus"], image, "{0}-{1}-{2}".format(parachain["name"], node["name"], chain_type), command, rpc_port, prometheus_port, lib2lib_port) + node_details = node_setup.run_testnet_node_with_command(plan, node["prometheus"], image, parachain["name"], "{0}-{1}-{2}".format(parachain["name"], node["name"], chain_type), command, rpc_port, prometheus_port, lib2lib_port, ws_port) 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["ip_address"] = node_details.ip_address @@ -196,7 +226,9 @@ def run_testnet_mainnet(plan, chain_type, relaychain_name, parachain): if prometheus_port != None: node_info["prometheus_public_port"] = prometheus_port node_info["endpoint_prometheus"] = utils.get_service_url("tcp", "127.0.0.1", prometheus_port) - if rpc_port != None: + if ws_port != None: + node_info["endpoint_public"] = utils.get_service_url("ws", "127.0.0.1", ws_port) + elif rpc_port != None: node_info["endpoint_public"] = utils.get_service_url("ws", "127.0.0.1", rpc_port) final_parachain_info[node_details.name] = node_info diff --git a/parachain/static_files/images.star b/parachain/static_files/images.star index 7178529..cb92595 100644 --- a/parachain/static_files/images.star +++ b/parachain/static_files/images.star @@ -76,7 +76,7 @@ parachain_images = { "base": ["local", "test", "main"], }, "parallel": { - "image": "parallelfinance/parallel:latest", + "image": "parallelfinance/parallel:v1.9.0", "entrypoint": "/parallel/.entrypoint.sh", "base": ["parallel-dev", None, "parallel"], },