From 4eb8ac88a756b777d0f5f7ce84585aca98377455 Mon Sep 17 00:00:00 2001 From: Adw8 Date: Tue, 3 Sep 2024 14:46:34 +0530 Subject: [PATCH] Add playbooks to setup and run nitro node --- nitro-node-setup/README.md | 65 +++++++++++ nitro-node-setup/nitro-vars-example.yml | 12 ++ nitro-node-setup/run-nitro-node.yml | 105 ++++++++++++++++++ nitro-node-setup/setup-vars.yml | 3 + .../templates/configs/l1-nitro-config.env.j2 | 8 ++ .../templates/configs/l2-nitro-config.env.j2 | 10 ++ .../templates/specs/l1-nitro-spec.yml.j2 | 11 ++ .../templates/specs/l2-nitro-spec.yml.j2 | 11 ++ 8 files changed, 225 insertions(+) create mode 100644 nitro-node-setup/README.md create mode 100644 nitro-node-setup/nitro-vars-example.yml create mode 100644 nitro-node-setup/run-nitro-node.yml create mode 100644 nitro-node-setup/setup-vars.yml create mode 100644 nitro-node-setup/templates/configs/l1-nitro-config.env.j2 create mode 100644 nitro-node-setup/templates/configs/l2-nitro-config.env.j2 create mode 100644 nitro-node-setup/templates/specs/l1-nitro-spec.yml.j2 create mode 100644 nitro-node-setup/templates/specs/l2-nitro-spec.yml.j2 diff --git a/nitro-node-setup/README.md b/nitro-node-setup/README.md new file mode 100644 index 0000000..c21f9ec --- /dev/null +++ b/nitro-node-setup/README.md @@ -0,0 +1,65 @@ +# nitro-node-setup + +## Setup Ansible + +To get started, follow the [installation](../../README.md#installation) guide to setup ansible on your machine + +## Run a nitro node + +The following commands have to be executed in [`nitro-node-setup`](./) directory + +- Copy the `nitro-vars-example.yml` vars file + + ```bash + cp nitro-vars-example.yml nitro-vars.yml + ``` + +- Edit [`nitro-vars.yml`](./nitro-vars.yml) and fill in the following values + + ```bash + # URL endpoint of the L1 chain + l1_nitro_chain_url: "" + + # URL endpoint of the L2 chain + l2_nitro_chain_url: "" + + # Private key for your nitro address + nitro_sc_pk: "" + + # Private key of the account on chain that is used for funding channels in Nitro node + nitro_chain_pk: "" + + # Contract address of NitroAdjudicator + na_address: "" + + # Contract address of VirtualPaymentApp + vpa_address: "" + + # Contract address of ConsensusApp + ca_address: "" + + # Address of the bridge node + bridge_contract_address: "" + + # Multi address of the bridge node + nitro_bridge_multiaddr "" + + # Multi address of your nitro node + nitro_node_multiaddr: "" + ``` + +- To run a nitro node, execute the `run-nitro-node.yml` Ansible playbook by running the following command. + + NOTE: By default, deployments are created in the `nitro-node-setup/out` directory. If you need to change this location, you can update the `nitro_directory` variable in the [setup-vars.yml](./setup-vars.yml) file. + + ```bash + LANG=en_US.utf8 ansible-playbook -i localhost, --connection=local run-nitro-node.yml --extra-vars='{ "target_host": "localhost"}' --user $USER + ``` + + - If you want to skip building the containers, set `"skip_container_build" : true` in the `--extra-vars` parameter: + + ```bash + LANG=en_US.utf8 ansible-playbook -i localhost, --connection=local run-nitro-node.yml --extra-vars='{ "target_host": "localhost", "skip_container_build": true }' --user $USER + ``` + +- Follow steps from [Demo](https://git.vdb.to/cerc-io/nitro-stack/src/branch/main/nitro-bridge-demo.md#demo) to create mirror channels on L2, create virtual channel and make payments diff --git a/nitro-node-setup/nitro-vars-example.yml b/nitro-node-setup/nitro-vars-example.yml new file mode 100644 index 0000000..addf6b0 --- /dev/null +++ b/nitro-node-setup/nitro-vars-example.yml @@ -0,0 +1,12 @@ +l1_nitro_chain_url: "" +l2_nitro_chain_url: "" +nitro_sc_pk: "" +nitro_chain_pk: "" +na_address: "" +vpa_address: "" +ca_address: "" +bridge_contract_address: "" +nitro_bridge_ip: "" +nitro_node_ip: "" +nitro_bridge_multiaddr: "" +nitro_node_multiaddr: "" diff --git a/nitro-node-setup/run-nitro-node.yml b/nitro-node-setup/run-nitro-node.yml new file mode 100644 index 0000000..8fc48a8 --- /dev/null +++ b/nitro-node-setup/run-nitro-node.yml @@ -0,0 +1,105 @@ +- name: Setup and run a nitro node + hosts: "{{ target_host }}" + + vars_files: + - setup-vars.yml + - nitro-vars.yml + + environment: + PATH: "{{ ansible_env.PATH }}:/home/{{ansible_user}}/bin" + + tasks: + - name: Create directory for nitro-stack + file: + path: "{{ nitro_directory }}" + state: directory + + - name: Change owner of nitro-directory + file: + path: "{{ nitro_directory }}" + owner: "{{ansible_user}}" + group: "{{ansible_user}}" + state: directory + recurse: yes + + - name: Clone go-nitro stack repo + command: laconic-so fetch-stack git.vdb.to/cerc-io/nitro-stack --git-ssh --pull + ignore_errors: yes + + - name: Clone repositories required for nitro-stack + command: laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stacks/nitro-node setup-repositories --git-ssh --pull + ignore_errors: yes + + - name: Build containers + command: laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stacks/nitro-node build-containers --force-rebuild + when: not skip_container_build + + - name: Copy over spec file for L1 nitro node + template: + src: "./templates/specs/l1-nitro-spec.yml.j2" + dest: "{{ nitro_directory }}/l1-nitro-spec.yml" + + - name: Copy over spec file for L2 nitro node + template: + src: "./templates/specs/l2-nitro-spec.yml.j2" + dest: "{{ nitro_directory }}/l2-nitro-spec.yml" + + - name: Check if deployment exists for L1 nitro node + stat: + path: "{{ nitro_directory }}/l1-nitro-deployment" + register: l1_deployment + + - name: Create a deployment for L1 nitro node + command: laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stacks/nitro-node deploy create --spec-file l1-nitro-spec.yml --deployment-dir l1-nitro-deployment + args: + chdir: "{{ nitro_directory }}" + when: not l1_deployment.stat.exists + + - name: Check if deployment exists for L2 nitro node + stat: + path: "{{ nitro_directory }}/l2-nitro-deployment" + register: l2_deployment + + - name: Create a deployment for L2 nitro node + command: laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stacks/nitro-node deploy create --spec-file l2-nitro-spec.yml --deployment-dir l2-nitro-deployment + args: + chdir: "{{ nitro_directory }}" + when: not l2_deployment.stat.exists + + - name: Check if the config.env file is empty for L1 deployment + shell: "[ -s {{ nitro_directory }}/l1-nitro-deployment/config.env ] && echo 'File is not empty' || echo 'File is empty'" + register: file_check_result + + - name: Display the result of the file check + debug: + msg: "{{ file_check_result.stdout }}" + + - name: Copy config.env for L1 nitro deployment if it is empty + template: + src: "./templates/configs/l1-nitro-config.env.j2" + dest: "{{ nitro_directory }}/l1-nitro-deployment/config.env" + when: file_check_result.stdout == 'File is empty' + + - name: Check if the config.env file is empty for L2 deployment + shell: "[ -s {{ nitro_directory }}/l2-nitro-deployment/config.env ] && echo 'File is not empty' || echo 'File is empty'" + register: file_check_result + + - name: Display the result of the file check + debug: + msg: "{{ file_check_result.stdout }}" + + - name: Copy config.env for L2 nitro deployment if it is empty + template: + src: "./templates/configs/l2-nitro-config.env.j2" + dest: "{{ nitro_directory }}/l2-nitro-deployment/config.env" + when: file_check_result.stdout == 'File is empty' + + - name: Start deployment for L1 nitro node + command: laconic-so deployment --dir l1-nitro-deployment start + args: + chdir: "{{ nitro_directory }}" + + - name: Start deployment for L2 nitro node + command: laconic-so deployment --dir l2-nitro-deployment start + args: + chdir: "{{ nitro_directory }}" diff --git a/nitro-node-setup/setup-vars.yml b/nitro-node-setup/setup-vars.yml new file mode 100644 index 0000000..7762444 --- /dev/null +++ b/nitro-node-setup/setup-vars.yml @@ -0,0 +1,3 @@ +target_host: "localhost" +nitro_directory: ./out +skip_container_build: false diff --git a/nitro-node-setup/templates/configs/l1-nitro-config.env.j2 b/nitro-node-setup/templates/configs/l1-nitro-config.env.j2 new file mode 100644 index 0000000..7ad1a3a --- /dev/null +++ b/nitro-node-setup/templates/configs/l1-nitro-config.env.j2 @@ -0,0 +1,8 @@ +NITRO_CHAIN_URL={{ l1_nitro_chain_url }} +NITRO_SC_PK={{ nitro_sc_pk }} +NITRO_CHAIN_PK={{ nitro_chain_pk }} +NA_ADDRESS={{ na_address }} +VPA_ADDRESS={{ vpa_address }} +CA_ADDRESS={{ ca_address }} +NITRO_BOOTPEERS={{ nitro_bridge_multiaddr }} +NITRO_EXT_MULTIADDR={{ nitro_node_multiaddr }} diff --git a/nitro-node-setup/templates/configs/l2-nitro-config.env.j2 b/nitro-node-setup/templates/configs/l2-nitro-config.env.j2 new file mode 100644 index 0000000..7290137 --- /dev/null +++ b/nitro-node-setup/templates/configs/l2-nitro-config.env.j2 @@ -0,0 +1,10 @@ +NITRO_CHAIN_URL={{ l2_nitro_chain_url }} +NITRO_SC_PK={{ nitro_sc_pk }} +NITRO_CHAIN_PK={{ nitro_chain_pk }} +NA_ADDRESS={{ na_address }} +VPA_ADDRESS={{ vpa_address }} +CA_ADDRESS={{ ca_address }} +BRIDGE_ADDRESS={{ bridge_contract_address }} +NITRO_BOOTPEERS={{ nitro_bridge_multiaddr }} +NITRO_EXT_MULTIADDR={{ nitro_node_multiaddr }} +NITRO_L2=true diff --git a/nitro-node-setup/templates/specs/l1-nitro-spec.yml.j2 b/nitro-node-setup/templates/specs/l1-nitro-spec.yml.j2 new file mode 100644 index 0000000..73ec889 --- /dev/null +++ b/nitro-node-setup/templates/specs/l1-nitro-spec.yml.j2 @@ -0,0 +1,11 @@ +stack: /home/{{ansible_user}}/cerc/nitro-stack/stack-orchestrator/stacks/nitro-node +deploy-to: compose +network: + ports: + nitro-node: + - 3007:3005 + - 4007:4005 +volumes: + nitro_node_data: ./data/nitro_node_data + nitro_node_tls: ./data/nitro_node_tls + nitro_node_caroot: ./data/nitro_node_caroot diff --git a/nitro-node-setup/templates/specs/l2-nitro-spec.yml.j2 b/nitro-node-setup/templates/specs/l2-nitro-spec.yml.j2 new file mode 100644 index 0000000..4d0a0c6 --- /dev/null +++ b/nitro-node-setup/templates/specs/l2-nitro-spec.yml.j2 @@ -0,0 +1,11 @@ +stack: /home/{{ansible_user}}/cerc/nitro-stack/stack-orchestrator/stacks/nitro-node +deploy-to: compose +network: + ports: + nitro-node: + - 3009:3005 + - 4009:4005 +volumes: + nitro_node_data: ./data/nitro_node_data + nitro_node_tls: ./data/nitro_node_tls + nitro_node_caroot: ./data/nitro_node_caroot