Skip to content

Commit

Permalink
[Feature] External Relay Chain Support (#39)
Browse files Browse the repository at this point in the history
* Add --relay-chain-rpc-urls feature
* Add Molecule test

---------

Co-authored-by: Bulat Saifullin <bulat@parity.io>
  • Loading branch information
lazam and BulatSaif committed Jul 13, 2023
1 parent 78aa24b commit 7204ca1
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 5 deletions.
4 changes: 4 additions & 0 deletions roles/node/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ node_parachain_chainspec: ""
# It has to be a link to wasm runtime. It will be used by the "--wasm-runtime-overrides" CLI flag
node_parachain_wasm_runtime: ""

### Experimental Feature
# Remote Relay Chain via RPC
node_parachain_relay_chain_rpc_urls: []

### Keys
## p2p key
# If it's empty, the node will generate default key file
Expand Down
15 changes: 15 additions & 0 deletions roles/node/molecule/parachain_remote_rc/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
- name: Converge
hosts: all
gather_facts: true
tasks:
- name: "parachain"
ansible.builtin.include_role:
name: "node"
vars:
node_app_name: "parachain-shell"
node_parachain_chain: "shell"
node_parachain_role: "collator"
node_parachain_chain_backup_restoring_type: "none"
node_parachain_relay_chain_rpc_urls: ["ws://127.0.0.1:9944"]
node_prometheus_file_exporter_path: "/tmp/substrate-pc.prom"
11 changes: 11 additions & 0 deletions roles/node/molecule/parachain_remote_rc/group_vars/all.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Molecule
ansible_user: root

# Common
node_app_name: "dummy"
node_binary_version: v0.9.430
node_legacy_rpc_flags: false
node_parachain_rpc_port: 9954
node_binary: https://github.com/paritytech/cumulus/releases/download/{{ node_binary_version }}/polkadot-parachain
node_binary_signature: https://github.com/paritytech/cumulus/releases/download/{{ node_binary_version }}/polkadot-parachain.asc
#node_binary_deployment: false
29 changes: 29 additions & 0 deletions roles/node/molecule/parachain_remote_rc/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
dependency:
name: galaxy
driver:
name: ${DRIVER:-docker}
platforms:
- name: molecule-instance-node-parachain-remote-rc
source:
alias: debian/bullseye/amd64
# DOCKER
image: "paritytech/debian11:latest"
command: ${MOLECULE_DOCKER_COMMAND:-""}
privileged: true
pre_build_image: true
provisioner:
name: ansible
options:
D: True
config_options:
defaults:
callbacks_enabled: timer
verifier:
name: ansible
options:
D: True
lint: |
set -e
yamllint .
ansible-lint
29 changes: 29 additions & 0 deletions roles/node/molecule/parachain_remote_rc/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
- name: Prepare
hosts: all
gather_facts: false
pre_tasks:
- name: Install Python
ansible.builtin.raw: apt -y update && apt install -y python3
changed_when: false
- name: Install required packages
ansible.builtin.apt:
name:
- gpg
update_cache: no
changed_when: false
tasks:
- name: "relaychain"
ansible.builtin.include_role:
name: "node"
vars:
node_app_name: "relaychain-shell"
node_data_root_path: "/opt/{{ node_app_name }}"
node_chain: "rococo-dev"
node_custom_options: [ '--alice' ]
node_binary_version: v0.9.43
node_legacy_rpc_flags: false
node_binary: https://github.com/paritytech/polkadot/releases/download/{{ node_binary_version }}/polkadot
node_binary_signature: https://github.com/paritytech/polkadot/releases/download/{{ node_binary_version }}/polkadot.asc
node_rpc_port: 9944
node_chain_backup_restoring_type: "none"
node_prometheus_file_exporter_path: "/tmp/substrate-rc.prom"
34 changes: 34 additions & 0 deletions roles/node/molecule/parachain_remote_rc/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
- name: Verify
hosts: all
gather_facts: false
tasks:
- name: Collect service facts
ansible.builtin.service_facts:

- name: Print service facts
ansible.builtin.debug:
var: ansible_facts.services['parachain-shell.service']

- name: check service
ansible.builtin.assert:
that: ansible_facts.services['parachain-shell.service'].state == 'running'

- name: Get parachain system_health
ansible.builtin.uri:
url: "http://127.0.0.1:{{ node_parachain_rpc_port }}"
method: POST
body:
{"id":1, "jsonrpc":"2.0", "method":"system_health", "params":[]}
body_format: json
headers:
Content-Type: 'application/json'
use_proxy: false
until: _parachain_system_health_result.status is defined and _parachain_system_health_result.status == 200
retries: 3
delay: 10
register: _parachain_system_health_result

- name: Print system_health
ansible.builtin.debug:
msg: "Parachain: {{ _parachain_system_health_result.json }}"
4 changes: 2 additions & 2 deletions roles/node/tasks/001-health-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

- name: Health check | Run health check
ansible.builtin.uri:
url: "http://127.0.0.1:{{ node_rpc_port }}"
url: "http://127.0.0.1:{{ ( node_parachain_relay_chain_rpc_urls | length != 0 ) | ternary(node_parachain_rpc_port, node_rpc_port) }}"
method: "POST"
body_format: "json"
body:
Expand All @@ -46,7 +46,7 @@
- name: Health check | Check the current version using API
ansible.builtin.uri:
url: "http://127.0.0.1:{{ node_rpc_port }}"
url: "http://127.0.0.1:{{ ( node_parachain_relay_chain_rpc_urls | length != 0 ) | ternary(node_parachain_rpc_port, node_rpc_port) }}"
method: "POST"
body_format: "json"
body:
Expand Down
5 changes: 4 additions & 1 deletion roles/node/tasks/100-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
- name: Test | Check node_chain
ansible.builtin.fail:
msg: "The 'node_chain' variable can't be empty!"
when: node_chain == '' and node_chainspec == ''
when:
- node_chain == ''
- node_chainspec == ''
- node_parachain_relay_chain_rpc_urls == []

- name: Test | Check node_parachain_chain
ansible.builtin.fail:
Expand Down
8 changes: 8 additions & 0 deletions roles/node/templates/env.j2
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ COMMON="\
--detailed-log-output
{%- endif %}"

{% if ( node_parachain_relay_chain_rpc_urls | length ) == 0 %}
RC_NAME="{% if node_parachain_has_name_fix %}--name {{ node_public_name }}{% endif %}"

RC_KEY="
Expand Down Expand Up @@ -99,6 +100,7 @@ RC_CUSTOM_OPTIONS="\
{{ option }}{% if not loop.last %} \
{% endif %}
{%- endfor %}"
{%- endif %}

{% if node_log_trace_enable or node_parachain_log_trace_enable %}
RUST_BACKTRACE=1
Expand Down Expand Up @@ -135,6 +137,12 @@ PC_CHAIN="
--chain {{ node_parachain_chain }}
{%- endif %}"

PC_REMOTE_RC_URLS="
{%- if ( node_parachain_relay_chain_rpc_urls | length ) != 0 %}
--relay-chain-rpc-urls {% for url in node_parachain_relay_chain_rpc_urls %}'{{ url }}'{% if not loop.last %} {% endif %}{% endfor %}
{%- endif %}"


PC_ADDR="\
--listen-addr=/ip4/{{ node_parachain_p2p_bind_addr }}/tcp/{{ node_parachain_p2p_port }}
{%- if node_enable_public_ip_detection %} \
Expand Down
6 changes: 5 additions & 1 deletion roles/node/templates/node.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ MemoryHigh={{ node_memory_high }}
MemoryMax={{ node_memory_max }}
ExecStart={{ _node_binary_file }} \
$COMMON \
{% if node_parachain_role != '' %}
{% if node_parachain_role != '' and node_parachain_relay_chain_rpc_urls != [] %}
$PC_NAME $PC_ROLE_SPECIFIC $PC_KEY $PC_CHAIN $PC_REMOTE_RC_URLS $PC_ADDR $PC_CONNECTIONS $PC_DB $PC_TELEMETRY $PC_PRUNING $PC_LOGS $PC_METRICS $PC_WS $PC_RPC $PC_WASM_RUNTIME $PC_CUSTOM_OPTIONS
{% elif node_parachain_role != '' %}
$PC_NAME $PC_ROLE_SPECIFIC $PC_KEY $PC_CHAIN $PC_ADDR $PC_CONNECTIONS $PC_DB $PC_TELEMETRY $PC_PRUNING $PC_LOGS $PC_METRICS $PC_WS $PC_RPC $PC_WASM_RUNTIME $PC_CUSTOM_OPTIONS \
-- \
{% endif %}
{% if node_parachain_relay_chain_rpc_urls == [] %}
$RC_NAME $RC_ROLE_SPECIFIC $RC_KEY $RC_CHAIN $RC_ADDR $RC_CONNECTIONS $RC_DB $RC_TELEMETRY $RC_PRUNING $RC_LOGS $RC_METRICS $RC_WS $RC_RPC $RC_WASM_RUNTIME $RC_CUSTOM_OPTIONS
{% endif %}

{% if node_syslog_labels != '' %}
SyslogIdentifier={{ node_syslog_labels }}
Expand Down
1 change: 0 additions & 1 deletion roles/node/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,3 @@ _node_parachain_chain_backup_data:
node_parachain_chain +
('-paritydb' if node_parachain_paritydb_enable else '-rocksdb') + ('-prune' if node_parachain_pruning > 0 else '-archive') }}"
custom_http_url: "{{ node_parachain_chain_backup_http_url }}"

0 comments on commit 7204ca1

Please sign in to comment.