Skip to content

Commit

Permalink
fix: fix explorer not working in mainnet (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
Riya Singh authored Jan 23, 2024
1 parent c0f6e35 commit 85267cd
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 48 deletions.
1 change: 1 addition & 0 deletions package_io/constant.star
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
88 changes: 62 additions & 26 deletions parachain/node_setup.star
Original file line number Diff line number Diff line change
@@ -1,29 +1,43 @@
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.
Args:
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.
lib2lib_port (int, optional): The lib2lib port value. Defaults to None.
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")

Expand All @@ -42,18 +56,19 @@ 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.
Args:
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.
Expand All @@ -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:
Expand All @@ -90,18 +115,19 @@ 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.
Args:
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.
Expand All @@ -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:
Expand All @@ -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,
Expand All @@ -147,4 +183,4 @@ def spawn_parachain(plan, prometheus, image, chain_name, execute_command, build_
),
)

return parachain_node
return parachain_node
74 changes: 53 additions & 21 deletions parachain/parachain.star
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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"]: {}}
Expand All @@ -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"])]
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion parachain/static_files/images.star
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
},
Expand Down

0 comments on commit 85267cd

Please sign in to comment.