bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 19쪽 중 15쪽
SYNC_ENABLED=true` (included in the `docker run` below). The node determines a trust height from the default trusted RPC servers and restores recent state over P2P from StateSync peers.
{% hint style="warning" %}
Network StateSync is memory intensive — at the time of writing it requires roughly `80 GB` of RAM. Ensure your server is sized accordingly.
{% endhint %}
#### Option B — Snapshot restore
Download a current snapshot and extract it into `/opt/thornode/.thornode/data` before starting the container (leave `THOR_AUTO_STATE_SYNC_ENABLED` unset in this case). For snapshot sources and the recovery procedure, see the upstream [Thornode Snapshot Recovery and Storage Management](https://gitlab.com/thorchain/devops/node-launcher/-/blob/master/docs/Thornode-Snapshot-Recovery-and-Storage-Management.md) doc.
{% hint style="info" %}
That document is written for the Kubernetes/Helm `node-launcher` deployment (it uses `make` targets); for a standalone Docker node use it only as the source of the snapshot location and storage guidance, and place the extracted data under the mounted `.thornode/data` directory.
{% endhint %}
## Start
Use the image tag that matches the current network version (check `/thorchain/version` on a public node). At the time of writing this is `mainnet-3.18.1`.
Start the thornode container
```sh
docker run -d --restart=on-failure \
-v /opt/thornode/.thornode:/root/.thornode \
-e CHAIN_ID=thorchain-1 \
-e THOR_AUTO_STATE_SYNC_ENABLED=true \
-p 127.0.0.1:1317:1317 \
-p 127.0.0.1:27147:27147 \
-p 27146:27146 \
--name thornode \
registry.gitlab.com/thorchain/thornode:mainnet-3.18.1
```
{% hint style="info" %}
On `arm64` hosts add `--platform linux/amd64`. If you bootstrapped via a snapshot (Option B) instead of StateSync, remove the `-e THOR_AUTO_STATE_SYNC_ENABLED=true` line.
{% endhint %}
# Midgard - Linux
Setting up Midgard on Linux
{% hint style="info" %}
The steps shown here are tested on `Ubuntu 24.04`, different distributions may need adjustments to the commands.
All commands are meant to be run as root user, if not specified otherwise. Depending on the server installation, they may need to be run from a different user via `sudo`.
{% endhint %}
## Prerequisites
Install all needed packages for building and running midgard
```sh
apt install -y --no-install-recommends apt-transport-https gcc gnupg lsb-release postgresql postgresql-common wget
```
## Application user
Add the application user that is used to run the thornode daemon
```sh
useradd -m midgard -s /bin/bash
```
## Database
### Install TimescaleDB
Run the PostgreSQL package setup script
```sh
/usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
```
Add the TimescaleDB package
```sh
echo "deb https://packagecloud.io/timescale/timescaledb/ubuntu/ $(lsb_release -c -s) main" | sudo tee /etc/apt/sources.list.d/timescaledb.list
```
Install the TimescaleDB GPG key
```sh
wget --quiet -O - https://packagecloud.io/timescale/timescaledb/gpgkey | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/timescaledb.gpg
```
Update your local repository list and install TimescaleDB
```sh
apt update
sudo apt install timescaledb-2-postgresql-16 postgresql-client-16
```
Tune your PostgreSQL instance for TimescaleDB
```sh
timescaledb-tune
```
Restart PostgreSQL
```sh
systemctl restart postgresql
```
### Create midgard database
```sh
su - postgres
psql
CREATE USER midgard WITH ENCRYPTED PASSWORD 'password';
CREATE DATABASE midgard OWNER midgard;
exit
```
### Install TimescaleDB extension
Connect to the database
```sh
psql -d "postgres://midgard:password@localhost:5432/midgard"
```
Add TimescaleDB to the database
```sql
CREATE EXTENSION IF NOT EXISTS timescaledb;
```
Check that TimescaleDB is installed
```sql
\dx
```
```plaintext
List of installed extensions
Name | Version | Schema | Description
-------------+---------+------------+---------------------------------------------------------------------------------------
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
timescaledb | 2.16.1 | public | Enables scalable inserts and complex queries for time-series data (Community Edition)
(2 rows)
```
## Install
As `midgard` user run:
```sh
git clone --branch 2.24.4 https://gitlab.com/thorchain/midgard.git $HOME/build
cd $HOME/build
export ENV CGO_ENABLED=1
go install -v -installsuffix cgo ./cmd/blockstore/dump
go install -v -installsuffix cgo ./cmd/midgard
go install -v -installsuffix cgo ./cmd/trimdb
go install -v -installsuffix cgo ./cmd/statechecks
mkdir -p $HOME/{config,openapi/generated}
cp openapi/generated/doc.html $HOME/openapi/generated/
```
## Configuration
As `midgard` user run:
```sh
mkdir $HOME/config
```
{% hint style="warning" %}
Nine Realms infrastructure has been decommissioned. Refer to the upstream [node-launcher documentation](https://gitlab.com/thorchain/devops/node-launcher/-/tree/master/docs) for the current genesis file source, then place it at `$HOME/config/genesis.json`.
{% endhint %}
Add midgard config.
{% hint style="warning" %}
Nine Realms infrastructure has been decommissioned. The `blockstore.remote` field below is left empty — refer to the upstream [Thornode Snapshot Recovery and Storage Management](https://gitlab.com/thorchain/devops/node-launcher/-/blob/master/docs/Thornode-Snapshot-Recovery-and-Storage-Management.md) doc for the current value.
{% endhint %}
{% code title="/home/midgard/config/midgard.json" overflow="wrap" %}
```json
{
"listen_port": 8080,
"max_block_age": "60s",
"shutdown_timeout": "5s",
"thorchain": {
"last_chain_backoff": "7s",
"fetch_batch_size": 100,
"parallelism": 4,
"read_timeout": "60s",
"tendermint_url": "https://gateway.liquify.com/chain/thorchain_rpc/websocket",
"thornode_url": "https://gateway.liquify.com/chain/thorchain_api/thorchain",
"fork_infos": [
{
"chain_id": "thorchain-1",
"earliest_block_hash": "0B3C8F9E3EA7E9B1C10CAC5217ED771E0540671EFB9C5315BF01167266BCBEDF",
"earliest_block_height": 17562001
}
]
},
"timescale": {
"user_name": "midgard",
"password": "password",
"database": "midgard",
"sslmode": "disable",
"commit_batch_size": 100,
"max_open_conns": 100,
"no_auto_update_ddl": true,
"host": "localhost",
"port": 5432
},
"websockets": {
"enable": false,
"connection_limit": 100
},
"usdpools": [
"BNB.BUSD-BD1",
"BNB.BUSD-BAF",
"BNB.USDT-DC8",
"ETH.USDT-0X62E273709DA575835C7F6AEF4A31140CA5B1D190",
"ETH.USDT-0XDAC17F958D2EE523A2206206994597C13D831EC7",
"AVAX.USDC-0XB97EF9EF8734C71904D8002F8B6BC66DD9C48A6E",
"ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48"
],
"genesis": {
"local": "/home/midgard/config/genesis.json",
"initial_block_height": 17562001,
"initial_block_hash": "0B3C8F9E3EA7E9B1C10CAC5217ED771E0540671EFB9C5315BF01167266BCBEDF"
},
"blockstore": {
"local": "./tmp/blockstore",
"remote": ""
}
}
```
{% endcode %}
## Systemd
Create a service file to be able to manage the Midgard process via systemd
{% code title="/etc/systemd/system/midgard.service" overflow="wrap" %}
```toml
[Unit]
Description=Midgard Daemon
After=network-online.target
[Service]
User=midgard
WorkingDirectory=/home/midgard
ExecStart=/home/midgard/go/bin/midgard /home/midgard/config/midgard.json
Restart=on-abort
RestartSec=3
LimitNOFILE=65535
[Install]
WantedBy=multi-user.target
```
{% endcode %}
Reload systemd config
```sh
systemctl daemon-reload
```
## Start
Start the daemon
```sh
systemctl start midgard.service
```
# Midgard - Docker
Setting up Midgard with Docker
{% hint style="info" %}
The steps shown here are tested on `Ubuntu 24.04`, different distributions may need adjustments to the commands.
All commands are meant to be run as root user, if not specified otherwise. Depending on the server installation, they may need to be run from a different user via `sudo`.
{% endhint %}
## Prerequisites
Install all packages needed for running and configuring the Midgard container
```sh
apt install -y --no-install-recommends docker.io
```
## Configuration
### Work directories
Prepare work directories
```sh
mkdir -p /opt/timescale
mkdir -p /opt/midgard/{config,blockstore}
```
### Genesis
Download the genesis file.
{% hint style="warning" %}
Nine Realms infrastructure has been decommissioned. Refer to the upstream [node-launcher documentation](https://gitlab.com/thorchain/devops/node-launcher/-/tree/master/docs) for the current genesis file source.
{% endhint %}
Add midgard config.
{% hint style="warning" %}
Nine Realms infrastructure has been decommissioned. The `blockstore.remote` field below is left empty — refer to the upstream [Thornode Snapshot Recovery and Storage Management](https://gitlab.com/thorchain/devops/node-launcher/-/blob/master/docs/Thornode-Snapshot-Recovery-and-Storage-Management.md) doc for the current value.
{% endhint %}
{% code title="/opt/midgard/config/config.json" overflow="wrap" %}
```json
{
"listen_port": 8080,
"max_block_age": "60s",
"shutdown_timeout": "5s",
"thorchain": {
"last_chain_backoff": "7s",
"fetch_batch_size": 100,
"parallelism": 4,
"read_timeout": "60s",
"tendermint_url": "https://gateway.liquify.com/chain/thorchain_rpc/websocket",
"thornode_url": "https://gateway.liquify.com/chain/thorchain_api/thorchain",
"fork_infos": [
{
"chain_id": "thorchain-1",
"earliest_block_hash": "0B3C8F9E3EA7E9B1C10CAC5217ED771E0540671EFB9C5315BF01167266BCBEDF",
"earliest_block_height": 17562001
}
]
},
"timescale": {
"user_name": "midgard",
"password": "password",
"database": "midgard",
"sslmode": "disable",
"commit_batch_size": 100,
"max_open_conns": 100,
"no_auto_update_ddl": true,
"host": "localhost",
"port": 5432
},
"websockets": {
"enable": false,
"connection_limit": 100
},
"usdpools": [
"BNB.BUSD-BD1",
"BNB.BUSD-BAF",
"BNB.USDT-DC8",
"ETH.USDT-0X62E273709DA575835C7F6AEF4A31140CA5B1D190",
"ETH.USDT-0XDAC17F958D2EE523A2206206994597C13D831EC7",
"AVAX.USDC-0XB97EF9EF8734C71904D8002F8B6BC66DD9C48A6E",
"ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48"
],
"genesis": {
"local": "genesis.json",
"initial_block_height": 17562001,
"initial_block_hash": "0B3C8F9E3EA7E9B1C10CAC5217ED771E0540671EFB9C5315BF01167266BCBEDF"
},
"blockstore": {
"local": "/blockstore",
"remote": ""
}
}
```
{% endcode %}
## Start
Start the TimescaleDB database
```sh
docker run -d --restart=on-failure \
-v /opt/timescale:/var/lib/postgresql/data \
-e POSTGRES_DB=midgard \
-e POSTGRES_USER=midgard \
-e POSTGRES_PASSWORD=password \
-p 127.0.0.1:5432:5432 \
--name timescale \
timescale/timescaledb:2.13.0-pg15 \
postgres -c plan_cache_mode=force_custom_plan
```
Start Midgard
```sh
docker run -d --restart=on-failure \
-v /opt/midgard/config:/config \
-v /opt/midgard/blockstore:/blockstore \
-p 127.0.0.1:8080:8080 \
--name midgard --net host \
registry.gitlab.com/thorchain/midgard:2.24.4
```
# Proxy Setup
Make API/RPC available externally
One easy way to make thornodes and midgards API or RPC endpoints available ecternally is by using a reverse proxy, a webserver that accepts all HTTP(S) requests and forwards them to the specific application.
{% hint style="info" %}
The steps shown here are tested on `Ubuntu 24.04`, different distributions may need adjustments to the commands.
All commands are meant to be run as root user, if not specified otherwise. Depending on the server installation, they may need to be run from a different user via `sudo`.
{% endhint %}
## DNS records
The reverse proxy needs a way to distinguish between the endpoints that it needs to address. One way to do this is by using different DNS records for each service, for example: `api.yourdomain.com`, `rpc.yourdomain.com`, `midgard.yourdomain.com`
## Install prerequisites
```sh
apt install -y --no-install-recommends nginx
```
## Configuration
### Remove default page
The default page is not needed and can be removed:
```sh
rm -f /etc/nginx/sites-enabled/default
```
### Enable THORNode API endpoint
When using a self built version of THORNode, the API endpoint is disabled by default and needs to be enabled in the thornode app config.
{% code title="/home/thornode/.thornode/config/app.toml" overflow="wrap" %}
```toml
[api]
# Enable defines if the API server should be enabled.
enable = true
# Swagger defines if swagger documentation should automatically be registered.
swagger = false
# Address defines the API server to listen on.
address = "tcp://127.0.0.1:1317"
```
{% endcode %}
Thornode needs to be restarted, for the changes to take effect.
```sh
systemctl restart thornode.service
```
### Proxy configuration
Create the required proxy configurations
{% tabs %}
{% tab title="API" %}
{% code title="/etc/nginx/sites-enabled/thornode-api" overflow="wrap" %}
```nginx
server {
listen 80;
server_name api.yourdomain.com;
access_log /var/log/nginx/thornode-api_access.log;
error_log /var/log/nginx/thornode-api_error.log;
location / {
proxy_pass http://localhost:1317/;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
```
{% endcode %}
{% endtab %}
{% tab title="RPC" %}
{% code title="/etc/nginx/sites-enabled/thornode-rpc" overflow="wrap" %}
```nginx
server {
listen 80;
server_name rpc.yourdomain.com;
access_log /var/log/nginx/thornode-rpc_access.log;
error_log /var/log/nginx/thornode-rpc_error.log;
location / {
proxy_pass http://localhost:27147/;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
```
{% endcode %}
{% endtab %}
{% tab title="MIDGARD" %}
{% code title="/etc/nginx/sites-enabled/midgard" overflow="wrap" %}
```nginx
server {
listen 80;
server_name midgard.yourdomain.com;
access_log /var/log/nginx/midgard_access.log;
error_log /var/log/nginx/midgard_error.log;
location / {
proxy_pass http://localhost:8080/;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
```
{% endcode %}
{% endtab %}
{% endtabs %}
## Restart proxy service
```sh
systemctl restart nginx.service
```
# Alerting
Alert Channels & Monitoring Software
## Community Alert Channels
To listen for update announcements, join the following channels:
* **THORNode Announcements (Telegram)**: <https://t.me/thornode_ann>
* **THORChain Community Devs (Discord)**: <https://discord.gg/g6Z2whSvGF>
{% hint style="info" %}
Be sure to use a pseudonym in order to prevent doxxing yourself. Node operators should remain anonymous for the health of the network and your personal/node security.
{% endhint %}
[Also see the Prometheus Alerts guide.](https://gitlab.com/thorchain/devops/node-launcher/-/blob/master/docs/Alerting.md)
## Vǫrðr 👻
A monitoring application for THORNodes.
> A Vǫrðr or warden is a guardian spirit who will follow the soul of a living person from birth until death.
{% hint style="info" %}
Vǫrðr is a community developed monitoring app for THORNodes. It's fully open-source at <https://github.com/sourcapital/vordr>. This is 3rd party software outside of the scope of THORSec.
{% endhint %}
## Features
* All chains are monitored for `Health` and `Sync Status` every minute
* THORChain version is monitored every minute
* Kubernetes pod restarts are monitored every 5 minutes
* Kubernetes pod logs of all chains are aggregated
* Slash points are monitored every minute
* Jailing is monitored every minute
* Chain observations are monitored every minute
## Supported Chains
| Client | Chain |
| -------- | ------------------------------------------------------------------ |
| Bitcoin | Bitcoin (BTC), Litecoin (LTC), Bitcoin Cash (BCH), Dogecoin (DOGE) |
| Ethereum | Ethereum (ETH), Avalanche (AVAX) |
| Cosmos | Cosmos (ATOM), Binance (BSC), THORChain (RUNE) |
{% hint style="info" %}
See <https://github.com/sourcapital/vordr#kubernetes> on how to run Vǫrðr in the Kubernetes cluster.
{% endhint %}
# Leaving
How to leave THORChain
## Overview
Approximately every 2 1/2 days (43,200 blocks or [`CHURNINTERVAL`](https://gateway.liquify.com/chain/thorchain_api/thorchain/mimir)) the system will churn its vaults and nodes.
Outgoing nodes consist of:
1. Nodes wishing to leave, and/or
2. The most unreliable node(s), and/or
3. The oldest node
Note: Just less than 1/3 of the active network can be churned out in a single churn event. The network will always maintain supermajority plus one node for Byzantine Fault Tolerance (BFT) security.
Incoming:
1. The node(s) with the highest bond ([`NUMBEROFNEWNODESPERCHURN`](https://thornode.ninerealms.com/thorchain/mimir) nodes).
Churned out nodes will be put in standby, but their bond will not automatically be returned. They will be credited any earned rewards in their last session. If they do nothing, but keep their cluster online and up-to-date with the latest THORNode version, they will be eventually churn back in.
Alternatively, an "Active" node can leave the system voluntarily, in which case they are marked to churn out first.
{% hint style="warning" %}
It is assumed nodes that wish to LEAVE while on Standby will be away for a significant period of time, so by permanently jailing their address, it forces them to completely destroy and re-build before re-entering. This also ensures they are running the latest software.
{% endhint %}
## Unbonding
{% hint style="info" %}
You cannot unbond if you are "Ready" or "Active".
{% endhint %}
If a Node Operator wants to retrieve part of their bond & rewards (such as deciding to take profits), they can simply Unbond. This keeps their Node on standby, ready to be churned back in.
To unbond from the system, simply send an **UNBOND** transaction.
Example, this will draw out 10k in RUNE from the bond, as long as the remaining amount is higher than the minimum bond.
`UNBOND:<node address>:1000000000000`
{% hint style="info" %}
THORChain always treats assets in 1e8 'base format' ie, 1.0 RUNE = 100,000,000 units (tor). To get from one to the other, simply multiply by 100m.
{% endhint %}
{% hint style="info" %}
If using ASGARDEX to **BOND** or **UNBOND**, simply put the RUNE amount, e.g. "100" for 100 RUNE. It does the memo in 1e8 for you.
{% endhint %}
{% hint style="info" %}
You can get your node address by running `make status`
{% endhint %}
{% hint style="warning" %}
Only the address that originally bonded the funds can **UNBOND** or **LEAVE**.\
This ensures you can safely leave this system if you no longer have access to your node (but it is still running).
{% endhint %}
## Issues with Unbonding/Leaving
If you cannot unbond, check your node's status and ensure you are in Standby mode. Only nodes in Standby mode can unbond or leave.
## Leaving
1. If a node issues a LEAVE while Active, they are eligible to churn back in on the next churn
2. If a node issues a LEAVE while on Standby, the node is considered Disabled and will never churn back in.
To leave the system, send the following transaction from your original bond address to the Vault Address: `LEAVE:<ADDRESS>` with at least 1 RUNE.
**Example**:
`LEAVE:<node address>`
⏱ *Wait a few hours, verify on the /nodes endpoint that you are now `Disabled`* 👀 Then send another LEAVE:
`LEAVE:<node address>`
⏱ *Wait a few minutes, verify you have received your bond back* 👀 - `make status` should show `BOND 0.00` and your wallet should get the full Bond back.
{% hint style="info" %}
View your node's status on [Runescan](https://runescan.io) or the [THORNode API](https://gateway.liquify.com/chain/thorchain_api/thorchain/nodes).
{% endhint %}
*🔥 Commence destroying your node 🔥*
## Destroying
### Confirming you have left
You should complete this checklist before you do the next step:
1. Have you sent a 프로젝트로 돌아가기