Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed service details for mainnet and testnet #132

Merged
merged 13 commits into from
Dec 1, 2023
7 changes: 4 additions & 3 deletions local.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
]
},

"para": {
"khala": {
"para": [
{
"name":"acala",
"nodes": [
{
"name": "alice",
Expand All @@ -35,5 +36,5 @@
}
]
}
}
]
}
2 changes: 1 addition & 1 deletion main.star
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def run(plan, args):
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_info = parachain.run_testnet_mainnet(plan, args, paras)
parachain_info = parachain.run_testnet_mainnet(plan, paras, args)
service_details["parachains"] = parachain_info

prometheus_address = promethues.launch_prometheus(plan, args, service_details, prometheus_template)
Expand Down
46 changes: 27 additions & 19 deletions package_io/promethues.star
Original file line number Diff line number Diff line change
Expand Up @@ -76,29 +76,37 @@ def new_config_template_data(plan, args, service_details):
relay_nodes = args["relaychain"]["nodes"]
for node in relay_nodes:
if node["prometheus"] == True:
endpoint = "{0}:{1}".format(service_details["relaychains"][0]["service_details"].ip_address, service_details["relaychains"][0]["service_details"].ports["prometheus"].number)

metrics_jobs.append(
new_metrics_job(
job_name = service_details["relaychains"][0]["service_name"],
endpoint = endpoint,
scrape_interval = "5s",
),
)
for relay_chain in service_details["relaychains"]:
node_name = relay_chain["service_details"].name
if node_name.endswith(node["name"]):
ip = relay_chain["service_details"].ip_address
port_number = relay_chain["service_details"].ports["metrics"].number
endpoint = "{0}:{1}".format(ip, port_number)
metrics_jobs.append(
new_metrics_job(
job_name = "relay_service_{}".format(node["name"]),
endpoint = endpoint,
scrape_interval = "5s",
),
)
plan.print(node["prometheus"])

for parachain in args["para"]:
for node in args["para"][parachain]["nodes"]:
for node in parachain["nodes"]:
if node["prometheus"] == True:
endpoint = "{0}:{1}".format(service_details["parachains"][0]["nodes"][0]["node_details"].ip_address, service_details["parachains"][0]["nodes"][0]["node_details"].ports["prometheus"].number)

metrics_jobs.append(
new_metrics_job(
job_name = service_details["parachains"][0]["parachain_name"],
endpoint = endpoint,
scrape_interval = "5s",
),
)
for relay_chain in service_details["relaychains"]:
riyaoayaw marked this conversation as resolved.
Show resolved Hide resolved
node_name = relay_chain["service_details"].name
if node_name.endswith(node["name"]):
ip = relay_chain["service_details"].ip_address
port_number = relay_chain["service_details"].ports["metrics"].number
endpoint = "{0}:{1}".format(ip, port_number)
metrics_jobs.append(
new_metrics_job(
job_name = "relay_service_{}".format(node["name"]),
endpoint = endpoint,
scrape_interval = "5s",
),
)

return {
"MetricsJobs": metrics_jobs,
Expand Down
4 changes: 2 additions & 2 deletions parachain/node_setup.star
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ def run_testnet_node_with_entrypoint(plan, image, chain_name, execute_command):
image = image,
ports = {
"ws": PortSpec(9944, transport_protocol = "TCP"),
"prometheus": PortSpec(9615, transport_protocol = "TCP", application_protocol = "http"),
"metrics": PortSpec(9615, transport_protocol = "TCP", application_protocol = "http"),
},
files = {
"/app": "configs",
Expand All @@ -19,7 +19,7 @@ def run_testnet_node_with_command(plan, image, chain_name, execute_command):
image = image,
ports = {
"ws": PortSpec(9944, transport_protocol = "TCP"),
"prometheus": PortSpec(9615, transport_protocol = "TCP", application_protocol = "http"),
"metrics": PortSpec(9615, transport_protocol = "TCP", application_protocol = "http"),
},
files = {
"/app": "configs",
Expand Down
70 changes: 38 additions & 32 deletions parachain/parachain.star
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ def spawn_parachain(plan, chain_name, image, command, build_file):
files = files,
ports = {
"ws": PortSpec(9944, transport_protocol = "TCP"),
"prometheus": PortSpec(9615, transport_protocol = "TCP"),
"metrics": PortSpec(9615, transport_protocol = "TCP"),
},
entrypoint = command,
),
)

return parachain_node

def start_local_parachain_node(plan, args, parachain_name, para_id):
parachain = parachain_name.lower()
def start_local_parachain_node(plan, args, parachain_config, para_id):
parachain = parachain_config["name"].lower()
parachain_details = parachain_list.parachain_images[parachain]
image = parachain_details["image"]
binary = parachain_details["entrypoint"]
Expand All @@ -49,7 +49,7 @@ def start_local_parachain_node(plan, args, parachain_name, para_id):
]
parachain_final = []
parachain_detail = {}
for node in args["para"][parachain]["nodes"]:
for node in parachain_config["nodes"]:
parachain_detail = {}
parachain_spawn_detail = spawn_parachain(plan, "{0}-{1}-{2}".format(parachain, node["name"], args["chain-type"]), image, exec_comexec_commandmand, build_file = raw_service.name)
parachain_detail["node_details"] = parachain_spawn_detail
Expand All @@ -64,39 +64,39 @@ def start_nodes(plan, args, relay_chain_ip):
parachain_details = {}
para_id = register_para_slot.register_para_id(plan, relay_chain_ip)
parachain_details["nodes"] = start_local_parachain_node(plan, args, parachain, para_id)
parachain_details["service_name"] = "parachain_service_" + parachain
parachain_details["parachain_name"] = parachain
register_para_slot.onboard_genesis_state_and_wasm(plan, para_id, parachain, relay_chain_ip)
parachain_details["service_name"] = "parachain_service_" + parachain["name"]
parachain_details["parachain_name"] = parachain["name"]
register_para_slot.onboard_genesis_state_and_wasm(plan, para_id, parachain["name"], relay_chain_ip)
final_parachain_details.append(parachain_details)
return final_parachain_details

def run_testnet_mainnet(plan, args, parachain):
parachain_config = parachain
def run_testnet_mainnet(plan, parachain, args):
if args["chain-type"] == "testnet":
main_chain = "rococo"
if parachain == "ajuna":
parachain = "bajun"
parachain_details = parachain_list.parachain_images[parachain]
if parachain["name"] == "ajuna":
parachain["name"] = "bajun"
parachain_details = parachain_list.parachain_images[parachain["name"]]
image = parachain_details["image"]
base = parachain_details["base"][1]

if parachain in constant.DIFFERENT_IMAGES_FOR_TESTNET:
image = constant.DIFFERENT_IMAGES_FOR_TESTNET[parachain]
if parachain["name"] in constant.DIFFERENT_IMAGES_FOR_TESTNET:
image = constant.DIFFERENT_IMAGES_FOR_TESTNET[parachain["name"].lower()]

else:
main_chain = "polkadot"
parachain_details = parachain_list.parachain_images[parachain]
parachain_details = parachain_list.parachain_images[parachain["name"].lower()]
image = parachain_details["image"]
base = parachain_details["base"][2]

if parachain in constant.DIFFERENT_IMAGES_FOR_MAINNET:
image = constant.DIFFERENT_IMAGES_FOR_MAINNET[parachain]
if parachain["name"] in constant.DIFFERENT_IMAGES_FOR_MAINNET:
image = constant.DIFFERENT_IMAGES_FOR_MAINNET[parachain["name"].lower()]


if base == None:
fail("Tesnet is not there for {}".format(parachain))
fail("Tesnet is not there for {}".format(parachain["name"]))

if parachain in constant.NO_WS_PORT:
common_command = [
if parachain["name"] in constant.NO_WS_PORT:
common_command = [
"--chain={0}".format(base),
"--port=30333",
"--rpc-port=9944",
Expand All @@ -123,9 +123,10 @@ def run_testnet_mainnet(plan, args, parachain):

if parachain == "altair" or "centrifuge":
common_command = common_command + ["--database=auto"]
parachain_info = {parachain: {}}
para_nodes = args["para"][parachain_config]["nodes"]
for node in para_nodes:

final_parachain_info = []
for node in parachain["nodes"]:
parachain_info = {}
command = common_command
command = command + ["--name={0}".format(node["name"])]
if node["node-type"] == "collator":
Expand All @@ -134,21 +135,26 @@ def run_testnet_mainnet(plan, args, parachain):
if node["node-type"] == "validator":
command = command + ["--validator"]

if parachain in constant.CHAIN_COMMAND:
if parachain["name"] in constant.CHAIN_COMMAND:
command = command + ["--", "--chain={0}".format(main_chain)]

if parachain == "kilt-spiritnet" and args["chain-type"] == "testnet":
if parachain["name"] == "kilt-spiritnet" and args["chain-type"] == "testnet":
command = command + ["--", "--chain=/node/dev-specs/kilt-parachain/peregrine-relay.json"]

if parachain in constant.BINARY_COMMAND_CHAINS:
if parachain["name"] in constant.BINARY_COMMAND_CHAINS:
binary = parachain_details["entrypoint"]
command = [binary] + command

node_details = node_setup.run_testnet_node_with_entrypoint(plan, image, "{0}-{1}-{2}".format(parachain, node["name"], args["chain-type"]), command)
parachain_info[parachain]["parachain_" + node["name"]] = node_details
parachain_info["service_name"] = "parachain_service_" + parachain["name"]
parachain_info["parachain_name"] = parachain["name"]
node_details = node_setup.run_testnet_node_with_entrypoint(plan, image, "{0}-{1}-{2}".format(parachain["name"], node["name"], args["chain-type"]), command)
parachain_info["nodes"] = node_details
final_parachain_info.append(parachain_info)

else:
node_details = node_setup.run_testnet_node_with_command(plan, image, "{0}-{1}-{2}".format(parachain, node["name"], args["chain-type"]), command)
parachain_info[parachain]["parachain_" + node["name"]] = node_details
parachain_info["service_name"] = "parachain_service_" + parachain["name"]
parachain_info["parachain_name"] = parachain["name"]
node_details = node_setup.run_testnet_node_with_command(plan, image, "{0}-{1}-{2}".format(parachain["name"], node["name"], args["chain-type"]), command)
parachain_info["nodes"] = node_details
final_parachain_info.append(parachain_info)

return parachain_info
return final_parachain_info
2 changes: 1 addition & 1 deletion parachain/static_files/images.star
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ parachain_images = {
"encointer": {
"image": "encointer/parachain:1.5.1",
"entrypoint": "/usr/local/bin/encointer-collator",
"base": ["encointer-rococo-local", "encointer-rococo", "mainnet"],
"base": ["encointer-rococo-local", "encointer-rococo", "encointer-kusama"],
},
"altair": {
"image": "centrifugeio/centrifuge-chain:test-PR1628-354d76c-23-11-28",
Expand Down
24 changes: 14 additions & 10 deletions relaychain/relay-chain.star
Original file line number Diff line number Diff line change
@@ -1,37 +1,41 @@
def start_relay_chain(plan, args):
name = args["chain-type"]
chain = args["relaychain"]["name"]
relay_node_details = {}
final_details=[]

prometheus = 9615
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 --prometheus-external".format(chain, relay_node["name"])]
relay_node_detail = plan.add_service(
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"),
"prometheus": PortSpec(9615, transport_protocol = "TCP"),
"metrics": PortSpec(9615, transport_protocol = "TCP"),
},
public_ports = {
"ws": PortSpec(port, transport_protocol = "TCP"),
"prometheus": PortSpec(prometheus, transport_protocol = "TCP"),
"metrics": PortSpec(prometheus, transport_protocol = "TCP"),
},
entrypoint = exec_command,
),
)
prometheus += 1
relay_node_details["relay_service_" + relay_node["name"]] = relay_node_detail
relay_node_details = {}
relay_node_details["service_details"] = service_details
relay_node_details["service_name"] = service_details.name
final_details.append(relay_node_details)

return relay_node_details
return final_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")
fail("Please provide rococo or westend as relaychain for testnet")
elif name == "mainnet":
if chain != "polkadot" and chain != "kusama":
fail("Please provide polkadot or kusama as relaychain for mainnet")
Expand All @@ -54,7 +58,7 @@ def start_relay_chains_local(plan, args):
relay_detail = {}
service_details = start_relay_chain_local(plan, node["name"], node["port"], prometheus_port)
relay_detail["service_details"] = service_details
relay_detail["service_name"] = "relay_service_" + node["name"]
relay_detail["service_name"] = service_details.name
final_details.append(relay_detail)
prometheus_port = prometheus_port + 1
return final_details
Expand All @@ -70,11 +74,11 @@ def start_relay_chain_local(plan, name, port, prometheus_port):
},
ports = {
"ws": PortSpec(9944, transport_protocol = "TCP"),
"prometheus": PortSpec(9615, transport_protocol = "TCP"),
"metrics": PortSpec(9615, transport_protocol = "TCP"),
},
public_ports = {
"ws": PortSpec(port, transport_protocol = "TCP"),
"prometheus": PortSpec(prometheus_port, transport_protocol = "TCP"),
"metrics": PortSpec(prometheus_port, transport_protocol = "TCP"),
},
entrypoint = exec_command,
),
Expand Down