Skip to content

Commit

Permalink
refactor: refactor public ports for relay and para chains (#175)
Browse files Browse the repository at this point in the history
* refactor: refactor public ports for relay and para chains

* refactor: refactor args and ports allocation

* chore: removed unused function

* chore: changed node-type to node_type

---------

Co-authored-by: Shreyas S Bhat <[email protected]>
  • Loading branch information
Riya Singh and shreyasbhat0 authored Jan 10, 2024
1 parent 43aa3e3 commit 31fcc1c
Show file tree
Hide file tree
Showing 11 changed files with 359 additions and 204 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ To use the Polkadot-kurtosis-package, you need to create a configuration file sp
"nodes": [
{
"name": "alice",
"node-type": "validator",
"node_type": "validator",
"port": 9944,
"prometheus": false
},
{
"name": "bob",
"node-type": "full",
"node_type": "full",
"port": 9945,
"prometheus": false
}
Expand All @@ -132,12 +132,12 @@ To use the Polkadot-kurtosis-package, you need to create a configuration file sp
"nodes": [
{
"name": "alice",
"node-type": "validator",
"node_type": "validator",
"prometheus": false
},
{
"name": "bob",
"node-type": "full",
"node_type": "full",
"prometheus": false
}
]
Expand All @@ -158,14 +158,14 @@ To use the Polkadot-kurtosis-package, you need to create a configuration file sp
- **name:** Name of the relay chain (e.g., "rococo-local", "rococo", "polkadot" or "kusama").
- **nodes:** List of nodes on the relay chain, each with:
- **name:** Node name (e.g., "alice").
- **node-type:** Node type, can be "validator" or "full".
- **node_type:** Node type, can be "validator" or "full".
- **port:** Port number for the node (e.g., 9944).
- **prometheus:** Whether Prometheus monitoring is enabled (true/false).
- **para:** List of parachains, each with:
- **name:** Parachain name (e.g., "kilt").
- **nodes:** List of nodes on the parachain, similar to relay chain nodes.
- **name:** Node name (e.g., "alice").
- **node-type:** Node type, can be "callator" or "full".
- **node_type:** Node type, can be "callator" or "full".
- **prometheus:** Whether Prometheus monitoring is enabled (true/false).
- **chopstick:** Configuration for Chopstick integration.
- **xcm:** Whether XCM (Cross-Chain Messaging) is enabled (true/false).
Expand Down
14 changes: 7 additions & 7 deletions local.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
{
"chain-type": "local",
"chain_type": "local",
"relaychain": {
"name": "rococo",
"name": "rococo-local",
"nodes": [
{
"name": "alice",
"node-type": "validator",
"node_type": "validator",
"prometheus": false
},
{
"name": "bob",
"node-type": "full",
"node_type": "full",
"prometheus": true

}
]
},

"para": [
"parachains": [
{
"name":"acala",
"nodes": [
{
"name": "alice",
"node-type": "validator",
"node_type": "validator",
"prometheus": false

},
{
"name": "bob",
"node-type": "full",
"node_type": "full",
"prometheus": true
}
]
Expand Down
37 changes: 18 additions & 19 deletions main.star
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ relay_chain = import_module("./relaychain/relay-chain.star")
package = import_module("./package_io/build-spec.star")
promethues = import_module("./package_io/promethues.star")
grafana = import_module("./package_io/grafana.star")
explorer = import_module("./package_io/polkadot_js_app.star")
explorer_js = import_module("./package_io/polkadot_js_app.star")
utils = import_module("./package_io/utils.star")

def run(plan, args):
def run(plan, chain_type = "local", relaychain = None, parachains = None, explorer = False):
"""
Main function to run the Polkadot relay and parachain setup.
Expand All @@ -17,11 +17,11 @@ def run(plan, args):
Returns:
dict: Service details containing information about relay chains, parachains, and Prometheus.
"""
service_details = run_polkadot_setup(plan, args)
service_details = run_polkadot_setup(plan, chain_type, relaychain, parachains, explorer)
return service_details


def run_polkadot_setup(plan, args):
def run_polkadot_setup(plan, chain_type, relaychain, parachains, explorer):
"""
Main function to run the Polkadot relay and parachain setup.
Expand All @@ -33,42 +33,41 @@ def run_polkadot_setup(plan, args):
dict: Service details containing information about relay chains, parachains, and Prometheus.
"""

utils.check_config_validity(plan, args)

chain_type, relaychain, parachains = utils.convert_to_lowercase(chain_type, relaychain, parachains)
utils.check_config_validity(plan, chain_type, relaychain, parachains)
utils.upload_files(plan)

service_details = {}

if args["chain-type"] == "local":
relay_chain_details = relay_chain.start_relay_chains_local(plan, args)
if chain_type == "local":
relay_chain_details = relay_chain.start_relay_chains_local(plan, chain_type, relaychain["name"], relaychain["nodes"])
polkadot_service_name = None
for key in relay_chain_details:
polkadot_service_name = key
break
service_details.update(relay_chain_details)
parachain_details = parachain.start_nodes(plan, args, relay_chain_details[polkadot_service_name]["ip_address"])
parachain_details = parachain.start_nodes(plan, chain_type, parachains, relay_chain_details[polkadot_service_name]["ip_address"])
service_details.update(parachain_details)
else:
if len(args["relaychain"]) != 0:
relay_node_details = relay_chain.start_test_main_net_relay_nodes(plan, args)
if len(relaychain) != 0:
relay_node_details = relay_chain.start_test_main_net_relay_nodes(plan, chain_type, relaychain["name"], relaychain["nodes"])
service_details.update(relay_node_details)
for paras in args["para"]:
parachain_info = parachain.run_testnet_mainnet(plan, paras, args)
for paras in parachains:
parachain_info = parachain.run_testnet_mainnet(plan, chain_type, relaychain["name"], paras)
service_details.update(parachain_info)

#run prometheus , if it returs some endpoint then grafana will up
prometheus_service_details = promethues.launch_prometheus(plan, args, service_details)
prometheus_service_details = promethues.launch_prometheus(plan, service_details)

if len(prometheus_service_details) != 0:
service_details.update(prometheus_service_details)
if prometheus_service_details["prometheus"]["endpoint"].startswith("http://"):
grafana_service_details = grafana.launch_grafana(plan, grafana)
grafana_service_details = grafana.launch_grafana(plan)
service_details.update(grafana_service_details)

#run the polkadot js App explorer
if args["explorer"] == True:
explorer_service_details = explorer.run_pokadot_js_app(plan, "ws://127.0.0.1:9944")
if explorer == True:
explorer_service_details = explorer_js.run_pokadot_js_app(plan, "ws://127.0.0.1:9944")

service_details.update(explorer_service_details)
return service_details

return service_details
5 changes: 4 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,6 @@ 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/grafana.star
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def prometheus_grafana_service(plan, service_name, image, port, command, build_f

return service

def launch_grafana(plan, args):
def launch_grafana(plan):
command = ["/run.sh"]
service = prometheus_grafana_service(plan, "grafana", "grafana/grafana-dev:10.3.0-147071", 3000, command, None)

Expand Down
6 changes: 2 additions & 4 deletions package_io/promethues.star
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ USED_PORTS = {

def launch_prometheus(
plan,
args,
service_details
):
template_data = new_config_template_data(
plan,
args,
service_details,
)

Expand Down Expand Up @@ -80,10 +78,10 @@ def get_config(config_files_artifact_name):
],
)

def new_config_template_data(plan, args, service_details):
def new_config_template_data(plan, 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
64 changes: 55 additions & 9 deletions 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 @@ -53,25 +55,69 @@ def get_service_url(protocol ,ip_address, ports):
return url


def check_config_validity(plan, args):
if len(args["relaychain"]) != 0:
for node in args["relaychain"]["nodes"]:
def check_config_validity(plan, chain_type, relaychain, parachains):
if relaychain != {}:
chain_name = relaychain["name"]
relay_nodes = relaychain["nodes"]

if chain_type == "testnet":
if chain_name != "rococo" and chain_name != "westend":
return fail("Please provide rococo or westend as relaychain for testnet")
elif chain_type == "mainnet":
if chain_name != "polkadot" and chain_name != "kusama":
return fail("Please provide polkadot or kusama as relaychain for mainnet")
elif chain_type == "local":
if chain_name != "rococo-local":
return fail("Please provide rococo-local as relaychain for localnet")
elif len(relay_nodes) < 2:
return fail("relay nodes must contain at least two nodes for localnet")

if chain_name == "polkadot":
if len(parachains) != 0:
for para in parachains:
if para["name"] not in constant.POLKADOT_PARACHAINS:
return fail("Invalid parachain for POLKADOT")

if chain_name == "kusama":
if len(parachains) != 0:
for para in parachains:
if para["name"] not in constant.KUSAMA_PARACHAINS:
return fail("Invalid parachain for KUSAMA")

if len(relaychain) != 0:
for node in relay_nodes:
if len(node) != 0:
if node["node-type"] in ["validator", "full", "archive"]:
if node["node_type"] in ["validator", "full", "archive"]:
plan.print("config for relaynodes is valid")
else:
return fail("relaychain node-type can be only validator/full")
return fail("relaychain node_type can be only validator/full")

if len(args["para"]) != 0:
for para in args["para"]:
if len(parachains) != 0:
for para in parachains:
if len(para["nodes"]) != 0:
for node in para["nodes"]:
if node["node-type"] in ["validator", "full", "collator"]:
if node["node_type"] in ["validator", "full", "collator"]:
plan.print("config for parachain is valid")
else:
return fail("parachain node-type can be only validator/full/collator")
return fail("parachain node_type can be only validator/full/collator")

def upload_files(plan):
plan.upload_files(src = "../parachain/static_files/configs", name = "configs")
plan.upload_files(src = "../parachain/static_files/javascript", name = "javascript")


def convert_to_lowercase(chain_type, relaychain, parachains):
chain_type = chain_type.lower()
relaychain["name"] = relaychain["name"].lower()
for node in relaychain["nodes"]:
node["name"] = node["name"].lower()
node["node_type"] = node["node_type"].lower()

for para in parachains:
para["name"] = para["name"].lower()
for node in para["nodes"]:
node["name"] = node["name"].lower()
node["node_type"] = node["node_type"].lower()

return chain_type, relaychain, parachains

Loading

0 comments on commit 31fcc1c

Please sign in to comment.