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

feat: Implementation of mainnet setup for polkadot package #73

Merged
merged 5 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion local.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"chain-type": "testnet",
"relaychain": {
"name": "polkadot",
"name": "rococo",
"nodes": [
{
"name": "alice",
Expand Down
8 changes: 6 additions & 2 deletions main.star
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ def run(plan, args):
parachain.start_nodes(plan, args, relay_chain_details["relay_service_alice"].ip_address)

else:
relay_chain.start_relay_chain(plan, args)
parachain.run_testnet(plan, args, "encointer")
if len(args["relaychain"]) != 0:
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)
service_details["parachains"] = parachain_info

return service_details
15 changes: 14 additions & 1 deletion package_io/constant.star
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,17 @@ EDIT_BUILD_SPEC = "edit-build-spec"
CURL_JQ_IMAGE = "badouralix/curl-jq"
NODE_IMAGE = "node:21.1"
PARA_SLOT_REGISTER_SERVICE_NAME = "para-slot-registration"
TEST_CHAIN = ["manta", "khala", "phala"]
BINARY_COMMAND_CHAINS = ["manta", "khala", "phala"]
NO_WS_PORT = ["acala", "frequency"]

DIFFERENT_IMAGES_FOR_MAINNET = {
"centrifuge": "centrifugeio/centrifuge-chain:main-latest",
"frequency": "frequencychain/parachain-node-mainnet",
"acala": "acala/acala-node:latest",
}
DIFFERENT_IMAGES_FOR_TESTNET = {
"frequency": "frequencychain/parachain-node-rococo",
"centrifuge": "centrifugeio/centrifuge-chain:main-latest",
}

CHAIN_COMMAND = ["manta", "moonsama", "interlay", "kintsugi-btc"]
29 changes: 29 additions & 0 deletions parachain/node_setup.star
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
def run_testnet_node_with_entrypoint(plan, image, chain_name, execute_command):
service_config = ServiceConfig(
image = image,
ports = {
"ws": PortSpec(9944, transport_protocol = "TCP"),
},
files = {
"/app": "configs",
},
entrypoint = execute_command,
)
parachain = plan.add_service(name = "{0}".format(chain_name), config = service_config)

return parachain

def run_testnet_node_with_command(plan, image, chain_name, execute_command):
service_config = ServiceConfig(
image = image,
ports = {
"ws": PortSpec(9944, transport_protocol = "TCP"),
},
files = {
"/app": "configs",
},
cmd = execute_command,
)
parachain = plan.add_service(name = "{0}".format(chain_name), config = service_config)

return parachain
94 changes: 61 additions & 33 deletions parachain/parachain.star
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ build_spec = import_module("./build-spec.star")
register_para_slot = import_module("./register-para-id.star")
constant = import_module("../package_io/constant.star")
parachain_list = import_module("./static_files/images.star")
node_setup = import_module("./node_setup.star")

def spawn_parachain(plan, chain_name, image, command, build_file):
files = {
Expand Down Expand Up @@ -47,41 +48,68 @@ def start_nodes(plan, args, relay_chain_ip):
start_local_parachain_node(plan, parachain, para_id)
register_para_slot.onboard_genesis_state_and_wasm(plan, para_id, parachain, relay_chain_ip)

def run_testnet_node_with_entrypoint(plan, args, image, chain_name, execute_command):
service_config = ServiceConfig(
image = image,
ports = {
"ws": PortSpec(9944, transport_protocol = "TCP"),
},
files = {
"/app": "configs",
},
entrypoint = execute_command,
)

plan.add_service(name = "{0}".format(chain_name), config = service_config)

def run_testnet_node_with_command(plan, args, image, chain_name, execute_command):
service_config = ServiceConfig(
image = image,
ports = {
"ws": PortSpec(9944, transport_protocol = "TCP"),
},
files = {
"/app": "configs",
},
cmd = execute_command,
)
def run_testnet_mainnet(plan, args, parachain):
if args["chain-type"] == "testnet":
main_chain = "rococo"
parachain_details = parachain_list.parachain_images[parachain]
image = parachain_details["image"]
base = parachain_details["base"][1]

plan.add_service(name = "{0}".format(chain_name), config = service_config)
if parachain in constant.DIFFERENT_IMAGES_FOR_TESTNET:
image = constant.DIFFERENT_IMAGES_FOR_TESTNET[parachain]

def run_testnet(plan, args, parachain):
parachain_details = parachain_list.testnet_chains[parachain]
image = parachain_details["image"]
command = parachain_details["command"]
else:
main_chain = "polkadot"
parachain_details = parachain_list.parachain_images[parachain]
image = parachain_details["image"]
base = parachain_details["base"][2]

if parachain in constant.TEST_CHAIN:
run_testnet_node_with_entrypoint(plan, args, image, parachain, command)
if parachain in constant.DIFFERENT_IMAGES_FOR_MAINNET:
image = constant.DIFFERENT_IMAGES_FOR_MAINNET[parachain]

if parachain in constant.NO_WS_PORT:
common_command = [
"--chain={0}".format(base),
"--port=30333",
"--rpc-port=9944",
"--rpc-cors=all",
"--rpc-external",
"--rpc-methods=unsafe",
"--unsafe-rpc-external",
]
else:
run_testnet_node_with_command(plan, args, image, parachain, command)
common_command = [
"--chain={0}".format(base),
"--port=30333",
"--ws-port=9944",
"--rpc-port=9933",
"--rpc-cors=all",
"--rpc-external",
"--ws-external",
"--rpc-methods=unsafe",
"--unsafe-rpc-external",
"--unsafe-ws-external",
]
parachain_info = {parachain: {}}
para_nodes = args["para"][parachain]["nodes"]
for node in para_nodes:
command = common_command
command = command + ["--name={0}".format(node["name"])]
if node["node-type"] == "collator":
command = command + ["--collator"]

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

if parachain 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}".format(parachain, node["name"]), command)
parachain_info[parachain]["parachain_" + node["name"]] = node_details

else:
node_details = node_setup.run_testnet_node_with_command(plan, image, "{0}-{1}".format(parachain, node["name"]), command)
parachain_info[parachain]["parachain_" + node["name"]] = node_details

return parachain_info
Loading