From ca901a29bc586e2e93b0cb5316811539d4631a42 Mon Sep 17 00:00:00 2001 From: Adw8 Date: Wed, 4 Sep 2024 12:42:35 +0530 Subject: [PATCH] Add README for running bridge --- README.md | 40 ++++++++ nitro-bridge-setup/README.md | 92 +++++++++++++++++++ nitro-bridge-setup/bridge-vars-example.yml | 7 +- nitro-bridge-setup/run-nitro-bridge.yml | 30 ++++-- nitro-bridge-setup/setup-vars.yml | 3 + .../templates/specs/bridge-nitro-spec.yml.j2 | 22 ++--- .../specs/nitro-contracts-spec.yml.j2 | 6 +- 7 files changed, 175 insertions(+), 25 deletions(-) create mode 100644 nitro-bridge-setup/README.md create mode 100644 nitro-bridge-setup/setup-vars.yml diff --git a/README.md b/README.md index 501b504..2bb8e4f 100644 --- a/README.md +++ b/README.md @@ -1 +1,41 @@ # testnet-ops + +## Installation + +- Install [Ansible](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#installing-and-upgrading-ansible-with-pip) + +- Add location of the directory containing the ansible binary to your `PATH` + +- Set Locale Encoding to `UTF-8` + + Ansible requires the locale encoding to be `UTF-8`. You can either use the `LANG` prefix when running Ansible commands or set the system-wide locale. + + - Option 1: Use `LANG` Prefix in Commands + + If you prefer not to change the system-wide locale, you can use the `LANG` prefix when running Ansible commands: + + ```bash + LANG=en_US.UTF-8 ansible-playbook your_playbook.yml + ``` + + - Option 2: Set System-Wide Locale + + - Edit the `/etc/default/locale` file: + + ```bash + sudo nano /etc/default/locale + ``` + + - Set the `LANG` variable to en_US.UTF-8: + + ```Copy code + LANG="en_US.UTF-8" + ``` + + - Reboot your system or log out and log back in to apply the changes. + + - Reference: + +## Playbooks + +- [nitro-bridge-setup](./nitro-bridge-setup/README.md) diff --git a/nitro-bridge-setup/README.md b/nitro-bridge-setup/README.md new file mode 100644 index 0000000..8f530a0 --- /dev/null +++ b/nitro-bridge-setup/README.md @@ -0,0 +1,92 @@ +# nitro-bridge-setup + +## Setup Ansible + +To get started, follow the [installation](../README.md#installation) guide to setup ansible on your machine + +## Run nitro bridge + +The following commands have to be executed in [`nitro-bridge-setup`](./) directory + +- Copy the `bridge-vars-example.yml` vars file + + ```bash + cp bridge-vars-example.yml bridge-vars.yml + ``` + +- Edit [`bridge-vars.yml`](./bridge-vars.yml) and fill in the following values + + ```bash + # L1 WS endpoint + nitro_l1_chain_url: "" + + # L2 WS endpoint + nitro_l2_chain_url: "" + + # Private key for the bridge's nitro address + nitro_sc_pk: "" + + # Private key for a funded account on L1 + # This account should have Laconic tokens for funding Nitro channels + nitro_chain_pk: "" + + # L1 chain ID (Sepolia: 11155111) + geth_chain_id: "11155111" + + # L1 RPC endpoint + geth_url: "" + + # L2 RPC endpoint + optimism_url: "" + + # Private key for a funded account on L1 to use for contracts deployment on L1 + geth_deployer_pk: '' + + # Private key for a funded account on L2 to use for contracts deployment on L2 + # Use the same account for L1 and L2 deployments + optimism_deployer_pk: '' + ``` + +- To run the nitro bridge, execute the `run-nitro-bridge.yml` Ansible playbook by running the following command. + + NOTE: By default, deployments are created in the `nitro-nodes-setup/out` directory. To change this location, 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-bridge.yml --extra-vars='{ "target_host": "localhost"}' --user $USER -kK + ``` + + - For skipping container build, run with `"skip_container_build" : true` in the `--extra-vars` parameter: + + ```bash + LANG=en_US.utf8 ansible-playbook -i localhost, --connection=local run-nitro-bridge.yml --extra-vars='{ "target_host": "localhost", "skip_container_build": true }' --user $USER -kK + ``` + +## Check Deployment Status + +- Run the following command in the directory where the bridge-deployment is created: + + - Follow optimism contracts deployment logs: + + ```bash + # Check the l2 nitro contract deployments + laconic-so deployment --dir bridge-deployment logs l2-nitro-contracts -f + + # Check the logs, ensure that the node is running + laconic-so deployment --dir bridge-deployment logs nitro-bridge -f + ``` + +## Get Contract Addresses + +- Run the following commands in the directory where the deployments are created: + + - Get addresses of L1 nitro contracts: + + ```bash + laconic-so deployment --dir nitro-contracts-deployment exec nitro-contracts "cat /app/deployment/nitro-addresses.json" + ``` + + - Get addresses of L2 nitro contracts: + + ```bash + laconic-so deployment --dir bridge-deployment exec nitro-bridge "cat /app/deployment/nitro-addresses.json" + ``` diff --git a/nitro-bridge-setup/bridge-vars-example.yml b/nitro-bridge-setup/bridge-vars-example.yml index ae845d2..12305c9 100644 --- a/nitro-bridge-setup/bridge-vars-example.yml +++ b/nitro-bridge-setup/bridge-vars-example.yml @@ -1,10 +1,9 @@ -nitro_directory: './out' -l1_nitro_chain_url: '' -l2_nitro_chain_url: '' +nitro_l1_chain_url: '' +nitro_l2_chain_url: '' nitro_chain_pk: '' nitro_sc_pk: '' +geth_chain_id: '' geth_url: '' optimism_url: '' geth_deployer_pk: '' optimism_deployer_pk: '' -geth_chain_id: '' diff --git a/nitro-bridge-setup/run-nitro-bridge.yml b/nitro-bridge-setup/run-nitro-bridge.yml index 22f2cab..0118512 100644 --- a/nitro-bridge-setup/run-nitro-bridge.yml +++ b/nitro-bridge-setup/run-nitro-bridge.yml @@ -2,16 +2,32 @@ hosts: "{{ target_host }}" vars_files: + - setup-vars.yml - bridge-vars.yml environment: PATH: "{{ ansible_env.PATH }}:/home/{{ansible_user}}/bin" tasks: + - name: Create directory for nitro bridge deployment + file: + path: "{{ nitro_directory }}" + state: directory + become: 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: Change owner of nitro-directory + file: + path: "{{ nitro_directory }}" + owner: "{{ansible_user}}" + group: "{{ansible_user}}" + state: directory + recurse: yes + become: yes + - name: Clone repositories required for nitro-stack command: laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stacks/bridge setup-repositories --git-ssh --pull ignore_errors: yes @@ -20,7 +36,7 @@ command: laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stacks/bridge build-containers --force-rebuild when: not skip_container_build - - name: Copy over spec file for nitro contracts deployment + - name: Generate spec file for nitro contracts deployment template: src: "./templates/specs/nitro-contracts-spec.yml.j2" dest: "{{ nitro_directory }}/nitro-contracts-spec.yml" @@ -29,6 +45,7 @@ stat: path: "{{ nitro_directory }}/nitro-contracts-deployment" register: nitro_contracts_deployment + become: yes - name: Create a deployment for nitro contracts command: laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stacks/nitro-contracts deploy create --spec-file nitro-contracts-spec.yml --deployment-dir nitro-contracts-deployment @@ -78,16 +95,17 @@ - debug: msg: "L1_ASSET_ADDRESS: {{ l1_asset_address.stdout }}" - - name: Copy over spec file for bridge deployment - template: - src: "./templates/specs/bridge-nitro-spec.yml.j2" - dest: "{{ nitro_directory }}/bridge-nitro-spec.yml" - - name: Check if deployment exists for bridge node stat: path: "{{ nitro_directory }}/bridge-deployment" register: bridge_deployment + - name: Generate spec file for bridge deployment + template: + src: "./templates/specs/bridge-nitro-spec.yml.j2" + dest: "{{ nitro_directory }}/bridge-nitro-spec.yml" + when: not bridge_deployment.stat.exists + - name: Create a deployment for the bridge node command: laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stacks/bridge deploy create --spec-file bridge-nitro-spec.yml --deployment-dir bridge-deployment args: diff --git a/nitro-bridge-setup/setup-vars.yml b/nitro-bridge-setup/setup-vars.yml new file mode 100644 index 0000000..7762444 --- /dev/null +++ b/nitro-bridge-setup/setup-vars.yml @@ -0,0 +1,3 @@ +target_host: "localhost" +nitro_directory: ./out +skip_container_build: false diff --git a/nitro-bridge-setup/templates/specs/bridge-nitro-spec.yml.j2 b/nitro-bridge-setup/templates/specs/bridge-nitro-spec.yml.j2 index 8c65473..1634a4b 100644 --- a/nitro-bridge-setup/templates/specs/bridge-nitro-spec.yml.j2 +++ b/nitro-bridge-setup/templates/specs/bridge-nitro-spec.yml.j2 @@ -1,22 +1,20 @@ stack: /home/{{ ansible_user }}/cerc/nitro-stack/stack-orchestrator/stacks/bridge deploy-to: compose config: - NITRO_L1_CHAIN_URL: {{ l1_nitro_chain_url }} - NITRO_L2_CHAIN_URL: {{ l2_nitro_chain_url }} - NITRO_CHAIN_PK: '{{ nitro_chain_pk }}' - NITRO_SC_PK: '{{ nitro_sc_pk }}' - GETH_CHAIN_ID: '{{ geth_chain_id }}' + NITRO_L1_CHAIN_URL: {{ nitro_l1_chain_url }} + NITRO_L2_CHAIN_URL: {{ nitro_l2_chain_url }} + NITRO_CHAIN_PK: {{ nitro_chain_pk }} + NITRO_SC_PK: {{ nitro_sc_pk }} GETH_URL: {{ geth_url }} OPTIMISM_URL: {{ optimism_url }} - GETH_DEPLOYER_PK: '{{ geth_deployer_pk }}' - OPTIMISM_DEPLOYER_PK: '{{ optimism_deployer_pk }}' + OPTIMISM_DEPLOYER_PK: {{ optimism_deployer_pk }} TOKEN_NAME: LaconicNetworkToken TOKEN_SYMBOL: LNT - INITIAL_TOKEN_SUPPLY: '129600' - NA_ADDRESS: '{{ na_address.stdout }}' - VPA_ADDRESS: '{{ vpa_address.stdout }}' - CA_ADDRESS: '{{ ca_address.stdout }}' - L1_ASSET_ADDRESS: '{{ l1_asset_address.stdout }}' + INITIAL_TOKEN_SUPPLY: 129600 + NA_ADDRESS: {{ na_address.stdout }} + VPA_ADDRESS: {{ vpa_address.stdout }} + CA_ADDRESS: {{ ca_address.stdout }} + L1_ASSET_ADDRESS: {{ l1_asset_address.stdout }} network: ports: nitro-bridge: diff --git a/nitro-bridge-setup/templates/specs/nitro-contracts-spec.yml.j2 b/nitro-bridge-setup/templates/specs/nitro-contracts-spec.yml.j2 index 1da1fa3..28c92ad 100644 --- a/nitro-bridge-setup/templates/specs/nitro-contracts-spec.yml.j2 +++ b/nitro-bridge-setup/templates/specs/nitro-contracts-spec.yml.j2 @@ -2,11 +2,11 @@ stack: /home/{{ ansible_user }}/cerc/nitro-stack/stack-orchestrator/stacks/nitro deploy-to: compose config: GETH_URL: {{ geth_url }} - GETH_CHAIN_ID: '{{ geth_chain_id }}' - GETH_DEPLOYER_PK: '{{ geth_deployer_pk }}' + GETH_CHAIN_ID: {{ geth_chain_id }} + GETH_DEPLOYER_PK: {{ geth_deployer_pk }} TOKEN_NAME: LaconicNetworkToken TOKEN_SYMBOL: LNT - INITIAL_TOKEN_SUPPLY: '129600' + INITIAL_TOKEN_SUPPLY: 129600 network: ports: {} volumes: