Skip to content

Commit

Permalink
Merge branch 'main' into test/add-workflow-local-test-main
Browse files Browse the repository at this point in the history
  • Loading branch information
hemz10 authored Nov 21, 2023
2 parents 02233a0 + 580c075 commit 4cd9c9d
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 23 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/smoke.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: smoke-test
on:
workflow_dispatch:

jobs:
smoke-test:
name: smoke test on all parachains
runs-on: "ubuntu-latest"

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Installing Kurtosis CLI if not found in cache
run: |
if [ ! -f "/usr/bin/kurtosis" ]; then
echo "deb [trusted=yes] https://apt.fury.io/kurtosis-tech/ /" | sudo tee /etc/apt/sources.list.d/kurtosis.list
sudo apt update
sudo apt install kurtosis-cli
which kurtosis
fi
- name: Cache Kurtosis CLI
uses: actions/cache@v2
with:
path: |
/usr/bin/kurtosis
key: kurtosis-${{ runner.os }}
restore-keys: |
kurtosis-
- name: Starting the Kurtosis engine
run: kurtosis engine start

# - name: Run parachain
# run: |
# kurtosis run . --args-file ./local.json --enclave polkadot
4 changes: 2 additions & 2 deletions local.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"chain-type": "testnet",
"relaychain": {
"name": "polkadot",
"name": "kusama",
"nodes": [
{
"name": "alice",
Expand All @@ -17,7 +17,7 @@
},

"para": {
"bifrost": {
"acala": {
"nodes": [
{
"name": "alice",
Expand Down
11 changes: 9 additions & 2 deletions main.star
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
parachain = import_module("./parachain/parachain.star")
relay_chain = import_module("./relaychain/relay-chain.star")
package = import_module("./package_io/build-spec.star")

def run(plan, args):
plan.upload_files(src = "./parachain/static_files/configs", name = "configs")
service_details = {"relaychains": {}, "parachains": {}}
service_details = {"relaychains": {}, "parachains": {}, "prometheus": {}}

if args["chain-type"] == "local":
relay_chain_details = relay_chain.start_relay_chains_local(plan, args)
service_details["relaychains"] = relay_chain_details

parachain.start_nodes(plan, args, relay_chain_details["relay_service_alice"].ip_address)
parchain_details = parachain.start_nodes(plan, args, relay_chain_details["relay_service_alice"].ip_address)
service_details["parachains"] = parchain_details

else:
if len(args["relaychain"]) != 0:
Expand All @@ -18,4 +21,8 @@ def run(plan, args):
parachain_info = parachain.run_testnet_mainnet(plan, args, paras)
service_details["parachains"] = parachain_info

ip = "{0}:{1}".format(relay_chain_details["relay_service_alice"].ip_address, relay_chain_details["relay_service_alice"].ports["prometheus"].number)
prometheus = package.prometheus(plan, args, ip)
service_details["prometheus"] = prometheus

return service_details
35 changes: 35 additions & 0 deletions package_io/build-spec.star
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,38 @@ def create_edit_and_build_spec(plan, service_name, image, chain_name, command, b
plan.remove_service(service_name)

return service

relay_chain = import_module("./constant.star")

def prometheus(plan, args, ip):
create_service_for_build_spec(plan, "prometheus-curl", "badouralix/curl-jq", None)
command = ["sh", "-c", "cp /app/prometheus.yml /tmp/ && sed -i 's/172.16.0.3:9615/{0}/' /tmp/prometheus.yml && /bin/prometheus --config.file=/tmp/prometheus.yml".format(ip)]
prometheus = prometheus_grafana_service(plan, "prometheus", "prom/prometheus:latest", 9090, ip, command, None)
command = ["/run.sh"]
prometheus_grafana_service(plan, "grafana", "grafana/grafana-dev:10.3.0-147071", 3000, ip, command, None)

return prometheus

def prometheus_grafana_service(plan, service_name, image, port, ip, command, build_file = None):
files = {
"/app": "configs",
}
if build_file != None:
files["/build"] = build_file

service = plan.add_service(
name = service_name,
config = ServiceConfig(
image = image,
files = files,
ports = {
"polkadot": PortSpec(port, transport_protocol = "TCP"),
},
public_ports = {
"polkadot": PortSpec(port, transport_protocol = "TCP"),
},
entrypoint = command,
),
)

return service
25 changes: 17 additions & 8 deletions parachain/parachain.star
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def spawn_parachain(plan, chain_name, image, command, build_file):
files["/build"] = build_file

parachain_node = plan.add_service(
name = "start-{}-node".format(chain_name),
name = "start-{}-local-node".format(chain_name),
config = ServiceConfig(
image = image,
files = files,
Expand All @@ -25,7 +25,7 @@ def spawn_parachain(plan, chain_name, image, command, build_file):

return parachain_node

def start_local_parachain_node(plan, parachain, para_id):
def start_local_parachain_node(plan, args, parachain, para_id):
parachain_details = parachain_list.parachain_images[parachain]
image = parachain_details["image"]
binary = parachain_details["entrypoint"]
Expand All @@ -38,16 +38,25 @@ def start_local_parachain_node(plan, parachain, para_id):
"-c",
"{0} --chain=/build/{1}-raw.json --ws-external --rpc-external --rpc-cors=all --name={1} --collator --rpc-methods=unsafe --force-authoring --execution=wasm --alice -- --chain=/app/raw-polkadot.json --execution=wasm".format(binary, chain_name),
]
parachain_details = {}
for node in args["para"][parachain]["nodes"]:
parachain_detail = spawn_parachain(plan, "{}-{}".format(chain_name, node["name"]), image, exec_comexec_commandmand, build_file = raw_service.name)
parachain_details[node["name"]] = parachain_detail

spawn_parachain(plan, chain_name, image, exec_comexec_commandmand, build_file = raw_service.name)
plan.print(parachain_details)
return parachain_details

def start_nodes(plan, args, relay_chain_ip):
parachains = args["para"]
parachain_details = {}
for parachain in parachains:
parachain_details[parachain] = {}
para_id = register_para_slot.register_para_id(plan, relay_chain_ip)
start_local_parachain_node(plan, parachain, para_id)
parachain_details[parachain] = start_local_parachain_node(plan, args, parachain, para_id)
register_para_slot.onboard_genesis_state_and_wasm(plan, para_id, parachain, relay_chain_ip)

return parachain_details

def run_testnet_mainnet(plan, args, parachain):
if args["chain-type"] == "testnet":
main_chain = "rococo"
Expand Down Expand Up @@ -100,19 +109,19 @@ def run_testnet_mainnet(plan, args, parachain):

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

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

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

else:
node_details = node_setup.run_testnet_node_with_command(plan, image, "{0}-{1}".format(parachain, node["name"]), command)
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

return parachain_info
14 changes: 14 additions & 0 deletions parachain/static_files/configs/prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
global:
scrape_interval: 15s
evaluation_interval: 15s


scrape_configs:
- job_name: "prometheus"
scrape_interval: 5s
static_configs:
- targets: ["localhost:9090"]
- job_name: "substrate_node"
scrape_interval: 5s
static_configs:
- targets: ["172.16.0.3:9615"]
6 changes: 0 additions & 6 deletions parachain/static_files/javascript/onboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const fs = require("fs");
const run = async () => {
try {
console.log("Parsing Args ...");
// 0 & 1 are command context
const endpoint = process.argv[2];
const seed = process.argv[3];
const id = process.argv[4];
Expand Down Expand Up @@ -42,14 +41,9 @@ const run = async () => {
parachain: true,
};

console.log(paraGenesisArgs);
let genesis = api.createType("ParaGenesisArgs", paraGenesisArgs);

const nonce = Number((await api.query.system.account(alice.address)).nonce);

console.log(
`--- Submitting extrinsic to register parachain ${id}. (nonce: ${nonce}) ---`
);
const sudoCall = await api.tx.sudo
.sudo(api.tx.parasSudoWrapper.sudoScheduleParaInitialize(id, genesis))
.signAndSend(alice, { nonce: nonce, era: 0 }, (result) => {
Expand Down
14 changes: 9 additions & 5 deletions relaychain/relay-chain.star
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ def spawn_multiple_relay(plan, count):
def start_relay_chains_local(plan, args):
relay_nodes = args["relaychain"]["nodes"]
relay_detail = {}
prometheus_port = 9615
for node in relay_nodes:
service_details = start_relay_chain_local(plan, node["name"], node["port"])
service_details = start_relay_chain_local(plan, node["name"], node["port"], prometheus_port)
relay_detail["relay_service_" + node["name"]] = service_details
prometheus_port = prometheus_port + 1
return relay_detail

def start_relay_chain_local(plan, name, port):
exec_command = ["bin/sh", "-c", "polkadot --base-path=/data --chain=/app/raw-polkadot.json --validator --rpc-external --rpc-cors=all --name=alice --{0} --rpc-methods=unsafe --execution=wasm".format(name)]
def start_relay_chain_local(plan, name, port, prometheus_port):
exec_command = ["bin/sh", "-c", "polkadot --base-path=/data --chain=/app/raw-polkadot.json --validator --rpc-external --rpc-cors=all --name=alice --{0} --rpc-methods=unsafe --execution=wasm --prometheus-external".format(name)]
service_details = plan.add_service(
name = "polkadot-{0}".format(name),
config = ServiceConfig(
Expand All @@ -60,10 +62,12 @@ def start_relay_chain_local(plan, name, port):
"/app": "configs",
},
ports = {
"polkadot": PortSpec(9944, transport_protocol = "TCP"),
"ws": PortSpec(9944, transport_protocol = "TCP"),
"prometheus": PortSpec(9615, transport_protocol = "TCP"),
},
public_ports = {
"polkadot": PortSpec(port, transport_protocol = "TCP"),
"ws": PortSpec(port, transport_protocol = "TCP"),
"prometheus": PortSpec(prometheus_port, transport_protocol = "TCP"),
},
entrypoint = exec_command,
),
Expand Down

0 comments on commit 4cd9c9d

Please sign in to comment.