Skip to content

Commit

Permalink
feat: implement parachain registration without an rpc call (#202)
Browse files Browse the repository at this point in the history
* feat: implement parachain registartion without an rpc call

* chore: code clean up
  • Loading branch information
shanithkk authored Feb 5, 2024
1 parent 2cc6a34 commit 056279d
Show file tree
Hide file tree
Showing 7 changed files with 589 additions and 43 deletions.
21 changes: 19 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
{
"name": "bob",
"node_type": "full",
"node_type": "validator",
"prometheus": true

}
Expand All @@ -33,7 +33,24 @@
"prometheus": true
}
]
},
{
"name":"frequency",
"nodes": [
{
"name": "alice",
"node_type": "validator",
"prometheus": false

},
{
"name": "bob",
"node_type": "full",
"prometheus": true
}
]
}
],
"explorer": true
"explorer": true,
"without_registration" : true
}
34 changes: 19 additions & 15 deletions main.star
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ grafana = import_module("./package_io/grafana.star")
explorer_js = import_module("./package_io/polkadot_js_app.star")
utils = import_module("./package_io/utils.star")
constant = import_module("./package_io/constant.star")
parachain_without_registration = import_module("./parachain/parachain_without_registration.star")

def run(plan, chain_type = "localnet", relaychain = None, parachains = None, explorer = False):
def run(plan, chain_type = "localnet", relaychain = None, parachains = None, explorer = False, without_registration = False):
"""
Main function to run the Polkadot relay and parachain setup.
Args:
chain_type (string): The type of chain (localnet, testnet or mainnet). Default is localnet.
relaychain (json): A json object containing data for relay chain config.
Expand All @@ -30,11 +31,10 @@ def run(plan, chain_type = "localnet", relaychain = None, parachains = None, exp
Returns:
service_details (json): Service details containing information about relay chains, parachains, and Prometheus.
"""
service_details = run_polkadot_setup(plan, chain_type, relaychain, parachains, explorer)
service_details = run_polkadot_setup(plan, chain_type, relaychain, parachains, explorer, without_registration)
return service_details


def run_polkadot_setup(plan, chain_type, relaychain, parachains, explorer):
def run_polkadot_setup(plan, chain_type, relaychain, parachains, explorer, without_registration):
"""
Main function to run the Polkadot relay and parachain setup.
Expand All @@ -61,18 +61,22 @@ def run_polkadot_setup(plan, chain_type, relaychain, parachains, explorer):
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 chain_type == "localnet":
relay_chain_details = relay_chain.start_relay_chains_local(plan, relaychain)
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, chain_type, parachains, relay_chain_details[polkadot_service_name]["ip_address"])
service_details.update(parachain_details)
if without_registration == False:
relay_chain_details = relay_chain.start_relay_chains_local(plan, relaychain)
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, chain_type, parachains, relay_chain_details[polkadot_service_name]["ip_address"])
service_details.update(parachain_details)
else:
parachain_details = parachain_without_registration.start_nodes(plan, chain_type, relaychain, parachains)
service_details.update(parachain_details)
else:
if len(relaychain) != 0:
relay_node_details = relay_chain.start_test_main_net_relay_nodes(plan, chain_type, relaychain)
Expand Down Expand Up @@ -104,4 +108,4 @@ def run_polkadot_setup(plan, chain_type, relaychain, parachains, explorer):
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
56 changes: 30 additions & 26 deletions parachain/node_setup.star
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,40 @@ def run_testnet_node_with_entrypoint(plan, prometheus, image, chain_name, servic
Returns:
dict: The service details of spawned parachain node.
"""
"""

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")
}
"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")
"lib2lib": PortSpec(30333, transport_protocol = "TCP"),
}

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 :
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")

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 = ports,
ports = ports,
public_ports = public_ports,
files = {
"/app": "configs",
Expand Down Expand Up @@ -82,33 +82,33 @@ def run_testnet_node_with_command(plan, prometheus, image, chain_name, service_n
ports = {
"ws": PortSpec(9944, transport_protocol = "TCP"),
"rpc": PortSpec(9947, transport_protocol = "TCP"),
"lib": PortSpec(30333)
"lib": PortSpec(30333),
}
else:
ports = {
"ws": PortSpec(9947, transport_protocol = "TCP"),
"lib": PortSpec(30333)
"lib": PortSpec(30333),
}

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 :
elif 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 = ports,
ports = ports,
public_ports = public_ports,
files = {
"/app": "configs",
Expand All @@ -119,7 +119,7 @@ def run_testnet_node_with_command(plan, prometheus, image, chain_name, service_n

return parachain

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):
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, relay_spec = None):
"""
Spawn a parachain node with specified configuration.
Expand All @@ -140,6 +140,10 @@ def spawn_parachain(plan, prometheus, image, chain_name, service_name, execute_c
files = {
"/app": "configs",
}

if relay_spec != None:
files["/relay"] = relay_spec

if build_file != None:
files["/build"] = build_file

Expand All @@ -154,24 +158,24 @@ def spawn_parachain(plan, prometheus, image, chain_name, service_name, execute_c
"ws": PortSpec(9947, transport_protocol = "TCP", application_protocol = "http"),
"lib2lib": PortSpec(30333, transport_protocol = "TCP", application_protocol = "http"),
}

public_ports = {}

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 :
elif 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(service_name),
config = ServiceConfig(
Expand All @@ -183,4 +187,4 @@ def spawn_parachain(plan, prometheus, image, chain_name, service_name, execute_c
),
)

return parachain_node
return parachain_node
Loading

0 comments on commit 056279d

Please sign in to comment.