Skip to content

Commit

Permalink
refactor: refactor public ports for relay and para chains
Browse files Browse the repository at this point in the history
  • Loading branch information
riyasng12 committed Jan 9, 2024
1 parent 223bbcc commit 63d6772
Show file tree
Hide file tree
Showing 6 changed files with 302 additions and 117 deletions.
43 changes: 42 additions & 1 deletion package_io/constant.star
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
]
2 changes: 1 addition & 1 deletion package_io/promethues.star
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 16 additions & 1 deletion package_io/utils.star
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
constant = import_module("./constant.star")

NOT_PROVIDED_APPLICATION_PROTOCOL = ""
NOT_PROVIDED_WAIT = "not-provided-wait"

Expand Down Expand Up @@ -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")
Expand Down
109 changes: 97 additions & 12 deletions parachain/node_setup.star
Original file line number Diff line number Diff line change
@@ -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",
},
Expand All @@ -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",
},
Expand All @@ -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
108 changes: 54 additions & 54 deletions parachain/parachain.star
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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",
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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":
Expand All @@ -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
Loading

0 comments on commit 63d6772

Please sign in to comment.