# Setup Guide (On Pillar)

{% hint style="warning" %}
This setup guide is for operators looking to setup the Orchestrator binary on the same server as their Pillar. If you're looking to setup on a remote server (not on the Pillar), then please follow the following: Setup Guide (Remote).
{% endhint %}

### Table of Contents

1. [Prerequisites](#prerequisites)
2. [Opening Required Firewall Ports](#id-2-opening-required-firewall-ports)
3. [Obtaining an Ethereum Node from Alchemy](#id-3-obtaining-an-ethereum-node-from-alchemy)
4. [Server Setup and Configuration](#server-setup-and-configuration)
   * [Accessing the Server](#accessing-the-server)
   * [Updating the System](#updating-the-system)
   * [Installing Required Packages](#installing-required-packages)
5. [Installing the Orchestrator](#id-5-installing-the-orchestrator)
6. [Setting Up Orchestrator as a Service](#id-6-setting-up-orchestrator-as-a-service)
7. [Fusing QSR Tokens](#id-7-fusing-qsr-tokens)
8. [Useful Commands](#id-8-useful-commands)

***

### 1) Prerequisites

Before proceeding, ensure you have the following:

* **Basic Knowledge**: Familiarity with command-line interfaces and server management.
* **Access Credentials**: SSH access to your chosen server with sudo privileges.
* **BNB and Ethereum Nodes:** Access to a BNB and Ethereum node provider like [Alchemy](https://www.alchemy.com/) to obtain  WebSocket (WSS) endpoints.
* **Producer Passphrase:** The passphrase for your Producer Key File, retrievable via the znn-controller.
* **QSR Tokens:** At least 120 QSR tokens fused to the Pillar Producer Address.

***

### 2) Opening Required Firewall Ports

To facilitate communication and health checks, ensure the following ports are open on your server’s firewall:

1\. Port 55055 (TCP): Open for gossip communication between nodes.

2\. Port 55000 (TCP): Open for API health checks.

Steps to Open Ports:

Assuming you’re using ufw (Uncomplicated Firewall) on Ubuntu:

```bash
sudo ufw allow 55055/tcp
sudo ufw allow 55000/tcp
sudo ufw reload
```

Note: If you’re using a different firewall management tool, adjust the commands accordingly.

***

### 3) Obtaining a Binance Smart Chain and Ethereum Node from Alchemy

To interact with the Binance Smart Chain and Ethereum network, you need access to a Binance Smart Chain and Ethereum node. Alchemy provides reliable node services.

Steps to Obtain the WSS Endpoint

1. Sign Up/Login to Alchemy:
   1. Visit [Alchemy](https://www.alchemy.com/) and create an account or log in.<br>
2. Create a New App:
   1. Navigate to the dashboard and create a new app.
   2. Select the desired network (e.g., Mainnet, Ropsten).<br>
3. Retrieve the WSS Endpoint:
   1. Once the app is created, go to the app’s dashboard.
   2. Locate the WebSocket endpoint URL.<br>
4. Example Endpoint:

```
wss://eth-mainnet.alchemyapi.io/v2/your-api-key
```

***

### 4) Server Setup and Configuration

#### Accessing the Server

1. **Obtain SSH Credentials**: \
   After setting up your server with your chosen provider, retrieve the SSH IP address, username, and password/key.<br>
2. **Connect via SSH**:<br>

   ```bash
   ssh username@your_server_ip
   ```

   Replace `username` with your server's username (commonly `root`) and `your_server_ip` with your server's IP address.<br>
3. **Switch to Root User**:<br>

   ```bash
   sudo -i
   ```

   This command grants you root privileges for the installation process.

#### Updating the System

Ensure your server's package lists and installed packages are up to date by running the command individually:

```bash
apt update
apt upgrade -y
```

* **`apt update`**: Updates the package index.
* **`apt upgrade -y`**: Upgrades all installed packages to their latest versions.

#### Installing Required Packages

Install `unzip` and other necessary utilities:

```bash
apt install -y unzip wget
```

* **`unzip`**: Required for extracting the Zenon controller ZIP file.
* **`wget`**: Facilitates downloading files from the internet.

***

### 5) Installing the Orchestrator

This section covers downloading the Orchestrator binary, setting up the configuration file, and preparing the orchestrator for deployment.

1. #### Download the Orchestrator Binary

First, download the latest Orchestrator binary. Ensure you're using the most recent release by checking the [OrchestratorGitHub Releases](https://github.com/HyperCore-Team/orchestrator/releases).

**Download Command**:

```bash
wget https://github.com/HyperCore-Team/orchestrator/releases/download/v0.0.9a-alphanet/orchestrator-linux-amd64.zip
```

**Note**: Replace the URL with the latest release if a newer version is available.

#### 2. Extract the Orchestrator Binary

Unzip the downloaded file:

```bash
unzip orchestrator-linux-amd64.zip
```

#### 3. Setup the Config.json File

**Move the Binary and Create the Configuration Directory**

1. **Copy the Binary to `/usr/local/bin/`**:

   ```bash
   cp orchestrator-linux-amd64 /usr/local/bin/
   ```
2. **Run the Orchestrator Binary to Initialize**:

   <pre class="language-bash"><code class="lang-bash"><strong>/usr/local/bin/orchestrator-linux-amd64
   </strong></code></pre>

   * **Expected Outcome**: The process will fail initially but will create a working directory at `/root/.orchestrator/`.

#### 4. Configure the Config.json File

Edit the `config.json` file to suit your environment:

```bash
nano /root/.orchestrator/config.json
```

**Configuration Steps**:

1. **Update WebSocket URLs**:
   * **BNB:** Replace with your Alchemy BNB WSS endpoint.
   * **Ethereum**: Replace with your Alchemy Ethereum WSS endpoint.
2. **Provide Producer Key File Passphrase**:
   * Retrieve by running the `znn-controller` and selecting the 2) `Status` option.
3. **Maintain Unique `EvmAddress`**:
   * Do not change or remove the `EvmAddress` once created.
4. **Add Bootstrap Address**:

   ```json
   "Bootstrap": "/dns/bootstrap.zenon.community/tcp/55055/p2p/12D3KooWBVQYaz3yuJor8oW7bUqoAGDZDpFBGbGerL3SprHn57pQ"
   ```
5. **Sample `config.json` Structure**:

   ```json
   {
       "DataPath": "/root/.orchestrator",
       "EventsPath": "",
       "QueuesPath": "",
       "GlobalState": 0,
       "EvmAddress": "",
       "Networks": {
           "BNB Chain": {  <= UPDATE THIS
               "Urls": [
                   "ws://127.0.0.1:8545" <= UPDATE THIS
               ],
               "FilterQuerySize": 1500
           },
           "Ethereum": {
               "Urls": [
                   "wss://eth-mainnet.alchemyapi.io/v2/your-api-key"  <= UPDATE THIS
               ],
               "FilterQuerySize": 2000
           },
           "Zenon": {
               "Urls": [
                   "ws://127.0.0.1:35998"
               ],
               "FilterQuerySize": 0
           }
       },
       "TssConfig": {
           "Port": 55055,
           "PublicKey": "",
           "DecompressedPublicKey": "",
           "LocalPubKeys": null,
           "Bootstrap": "/dns/bootstrap.zenon.community/tcp/55055/p2p/12D3KooWBVQYaz3yuJor8oW7bUqoAGDZDpFBGbGerL3SprHn57pQ",
           "PubKeyWhitelist": {},
           "BaseDir": "/root/.orchestrator/tss",
           "BaseConfig": {
               "PartyTimeout": 60000000000,
               "KeyGenTimeout": 900000000000,
               "KeySignTimeout": 60000000000,
               "KeyRegroupTimeout": 60,
               "PreParamTimeout": 600000000000,
               "EnableMonitor": false
           }
       },
       "ProducerKeyFileName": "producer",
       "ProducerKeyFilePassphrase": "YOUR_PASSPHRASE",  <= UPDATE THIS
       "ProducerIndex": 0
   }
   ```

#### 5. Copy the Producer File

Assuming you are running the Orchestrator on the pillar, copy the producer file to the Orchestrator's data path:

```bash
cp /root/.znn/wallet/producer /root/.orchestrator/producer
```

**Note**: Ensure the path to the producer file is correct. Adjust the command if your producer file is located elsewhere.

***

### 6) Setting Up Orchestrator as a Service

To ensure that the Orchestrator runs continuously and starts on boot, set it up as a systemd service.

#### 1. Create a systemd Service File

Open a new service file for the Orchestrator:

```bash
nano /etc/systemd/system/orchestrator.service
```

#### 2. Add Service Configuration

Copy and paste the following content into the service file:

```ini
iniCopy code[Unit]
Description=Orchestrator Service
After=network.target
StartLimitIntervalSec=300s
StartLimitBurst=10

[Service]
User=root
Group=root
ExecStart=/usr/local/bin/orchestrator-linux-amd64
ExecStop=/usr/bin/pkill -9 orchestrator-linux-amd64
Restart=on-failure
RestartSec=60
TimeoutStopSec=10s
TimeoutStartSec=10s
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=orchestrator

[Install]
WantedBy=multi-user.target
```

#### 3. Activate and Start the Orchestrator Service

Reload systemd to recognize the new service:

```bash
systemctl daemon-reload
```

Enable the service to start on boot:

```bash
systemctl enable orchestrator
```

Start the Orchestrator service:

```bash
systemctl start orchestrator
```

#### 4. Verify the Orchestrator Service Status

Check if the Orchestrator service is running correctly:

```bash
systemctl status orchestrator
```

**Expected Output**:

```yaml
● orchestrator.service - Orchestrator Service
   Loaded: loaded (/etc/systemd/system/orchestrator.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2024-04-27 10:00:00 UTC; 5s ago
 Main PID: 12345 (orchestrator-)
    Tasks: 10 (limit: 4704)
   CGroup: /system.slice/orchestrator.service
           └─12345 /usr/local/bin/orchestrator-linux-amd64
```

**Note**: The `Active: active (running)` status indicates that the service is running correctly.

***

### 7) Fusing QSR Tokens

To fully deploy your Orchestrator with the Zenon Network, ensure that you have fused at least **120 QSR** tokens to the Pillar Producer Address.

#### Steps to Fuse QSR Tokens

1. **Access Your Pillar Producer Address**:
   * Use your Syrius wallet or another compatible wallet to access your producer address.
2. **Fuse QSR Tokens**:
   * Follow the wallet's instructions to fuse QSR tokens.
   * Ensure you have at least 120 QSR fused to meet the network's requirements.

***

### 8) Useful Commands


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.zenon.org/hypercore/technical/roles/orchestrator/setup-guide-on-pillar.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
