# Node Setup Manual

## Recommended Hardware Specs

Operating a node for a personal RPC can be done usin most modern computers. Even modest hardware should be fine for this purpose.

Operating a **validator:**

* Modern cpu with at least 8 cores / threads
* ram: 32 gb + (16gb swap space recommended)
* storage: 1000gb+ @ NVME gen4
* network: 500mb/s DL, 100mb/s UL (the faster the better)

### Software Prerequisites

{% tabs %}
{% tab title="Linux" %}
jq, yq, sed, curl, wget, make, and **Go** are required for running the various commands and config scripts and commands in this guide:

```bash
sudo apt install jq yq sed curl wget build-essential
```

Install go if you want to build binaries from the layer repo:

* `Go version 1.22` : Use the default install instructions [here](https://go.dev/doc/install).
  {% endtab %}

{% tab title="MacOS" %}
jq, yq, sed, curl, wget, make, and **Go** are required for running the various commands and config scripts and commands in this guide:

```bash
brew install jq yq sed wget && xcode-select --install
```

* `Go ≥ 1.22` : Use the default install instructions [here](https://go.dev/doc/install).
  {% endtab %}
  {% endtabs %}

{% hint style="success" %}

* Commands shown should just work while logged in as a user (using root is not recommended).
* **I**f you are using an older Mac with an intel chip, the linux versions (amd64) in step 1 below may be used. (just remember to use the mac commands!)
* If on raspberry pi or similar, use the binary downloads for "**arm64**".
  {% endhint %}

## Choose How you will Sync your Node

There are two options for starting a new tellor-1 node:

* **State sync**: Your node is configured with seeds and peers from which it will try to download recent chain state snapshots. This sync method is faster, but you will not be able to query block info (like transactions) for any blocks that were produced before the day of your sync. For a new setup state sync, the setup script works great!
* **Genesis sync**: Your node will start with the genesis binary and sync the entire chain. A different binary will be needed for each upgrade since genesis. This sync method can take a long time depending on how long tellor-1 has been live.

## 1. Download and Organize the `layerd` Binary(s)

{% hint style="info" %}
**As you progress through the steps, be sure to select the tabs that work for your setup! You will get errors if you use the linux commands on mac and vice-versa.**
{% endhint %}

First, download the binary from the [Tellor Github](https://github.com/tellor-io/layer/tags).

{% tabs %}
{% tab title="Linux" %}

```sh
mkdir -p ~/layer/binaries && cd ~/layer/binaries && mkdir v6.1.5 && cd v6.1.5 && wget https://github.com/tellor-io/layer/releases/download/v6.1.5/layer_Linux_x86_64.tar.gz && tar -xvzf layer_Linux_x86_64.tar.gz
```

{% endtab %}

{% tab title="Linux ARM64" %}

```sh
mkdir -p ~/layer/binaries && cd ~/layer/binaries && mkdir v6.1.5 && cd v6.1.5 && wget https://github.com/tellor-io/layer/releases/download/v6.1.5/layer_Linux_arm64.tar.gz && tar -xvzf layer_Linux_arm64.tar.gz
```

{% endtab %}

{% tab title="MacOS" %}

```sh
mkdir -p ~/layer/binaries && cd ~/layer/binaries && mkdir v6.1.5&& cd v6.1.5 && wget https://github.com/tellor-io/layer/releases/download/v6.1.5/layer_Darwin_arm64.tar.gz && tar -xvzf layer_Darwin_arm64.tar.gz
```

{% endtab %}
{% endtabs %}

Initialize .layer folder in your home directory:

```sh
./layerd init layer --chain-id tellor-1
```

Download the binaries from the [Tellor Github](https://github.com/tellor-io/layer/tags).

{% tabs %}
{% tab title="Linux" %}
{% code overflow="wrap" %}

```sh
# genesis binary v4.0.3
mkdir -p ~/layer/binaries && cd ~/layer/binaries && mkdir v4.0.3 && cd v4.0.3 && wget https://github.com/tellor-io/layer/releases/download/v4.0.3/layer_Linux_x86_64.tar.gz && tar -xvzf layer_Linux_x86_64.tar.gz
```

{% endcode %}
{% endtab %}

{% tab title="MacOS" %}
{% code overflow="wrap" %}

```sh
# genesis binary v4.0.3
mkdir -p ~/layer/binaries && cd ~/layer/binaries && mkdir v4.0.3 && cd v4.0.3 && wget https://github.com/tellor-io/layer/releases/download/v4.0.3/layer_Darwin_arm64.tar.gz && tar -xvzf layer_Darwin_arm64.tar.gz
```

{% endcode %}
{% endtab %}
{% endtabs %}

Initialize the chain config files:

```sh
# change directory to ~/layer/binaries/v4.0.0
cd ~/layer/binaries/v4.0.3

# initialize chain configs
./layerd init layer --chain-id tellor-1
```

## 2. Set System Variables

A Layer node uses the following variables:

* <mark style="color:green;">**TOKEN\_BRIDGE\_CONTRACT**</mark>: the token bridge contract address.
* <mark style="color:green;">**ETH\_RPC\_URL**</mark>: A reliable Ethereum RPC URL.
* <mark style="color:green;">**ETH\_RPC\_URL\_PRIMARY**</mark>: Ethereum RPC url for the reporter daemon (can be the same).
* <mark style="color:green;">**ETH\_RPC\_URL\_FALLBACK**</mark>: A second RPC url for calling the bridge contract if the primary RPC fails to respond.

Set the environment variables so that they are set in new terminal windows by default. Open your .bashrc or .zshrc file with a text editor like nano:

{% tabs %}
{% tab title="Linux" %}

```
nano ~/.bashrc
```

{% endtab %}

{% tab title="MacOS" %}

```
nano ~/.zshrc
```

{% endtab %}
{% endtabs %}

Add these lines to the bottom of the file. Remember to replace the example `ETH_RPC_URL` with your actual Ethereum RPC url, and if you're going to run a reporter, replace the `REPORTERS_VALIDATOR_ADDRESS` with your own as well.

```bash
export ETH_RPC_URL="wss://a.good.ethereum.rpc.url"
export ETH_RPC_URL_PRIMARY="wss://a.good.ethereum.rpc.url"
export ETH_RPC_URL_FALLBACK="https://another.ethereum.rpc.url"
export TOKEN_BRIDGE_CONTRACT="0x6ec401744008f4B018Ed9A36f76e6629799Ee50E"
```

Exit nano with `ctrl^x` then enter `y` to save the changes.

Load the new variables:

{% tabs %}
{% tab title="Linux" %}

```
source ~/.bashrc
```

{% endtab %}

{% tab title="MacOS" %}

```
source ~/.zshrc
```

{% endtab %}
{% endtabs %}

## 3. Edit Chain Configuration for Tellor.

We need to open up the tellor layer config files and change some variables. You can use any local text editor like code, vim, or nano.

***Note: All other variables can be safely left as is.***

In `~/.layer/config/app.toml`:

```sh
# The minimum gas prices a validator is willing to accept for processing a
# transaction. A transaction's fees must meet the minimum of any denomination
# specified in this config (e.g. 0.25token1,0.0001token2).
minimum-gas-prices = "0loya"
# ...
# Address defines the API server to listen on.
address = "tcp://0.0.0.0:1317"
#...
```

In `~/.layer/config/client.toml`:

```sh
#...
# The network chain ID
chain-id = "tellor-1"
# The keyring's backend, where the keys are stored (os|file|kwallet|pass|test|memory)
keyring-backend = "test"
#...
```

In `~/.layer/config/config.toml`:

```sh
#...
# TCP or UNIX socket address for the RPC server to listen on (optional)
laddr = "tcp://0.0.0.0:26657"
#...
# Use '["*"]' to allow any origin
cors_allowed_origins = ["*"]
#...
# Comma separated list of nodes to keep persistent connections to
persistent_peers = "5a9db46eceb055c9238833aa54e15a2a32a09c9a@54.67.36.145:26656,f2644778a8a2ca3b55ec65f1b7799d32d4a7098e@54.149.160.93:26656,2904aa32501548e127d3198c8f5181fb4d67bbe6@18.116.23.104:26656,7fd4d34f3b19c41218027d3b91c90d073ab2ba66@54.221.149.61:26656,2b8af463a1f0e84aec6e4dbf3126edf3225df85e@13.52.231.70:26656,9358c72aa8be31ce151ef591e6ecf08d25812993@18.143.181.83:26656,cbb94e01df344fdfdee1fdf2f9bb481712e7ef8d@34.228.44.252:26656"
#...
# How long we wait after committing a block, before starting on the new
# height (this gives us a chance to receive some more precommits, even
# though we already have +2/3).
timeout_commit = "1s"
#...
```

### 4. Sync the Node

*<mark style="color:green;">**Before starting your node**</mark><mark style="color:green;">,</mark> it's a good idea to think about how you want to run it so that the process does not get killed accidentally. This is not obvious for beginners. Try* [*GNU screen*](https://tellor.io/blog/how-to-manage-cli-applications-on-hosted-vms-with-screen/) *or tmux. More advanced setups can be achieved using*[ *systemd services*](https://docs.tellor.io/layer-docs/running-tellor/node-setup/example-.service-files)*.*

Choose the tab depending on whether or not you are doing a genesis sync, or a state sync:

{% tabs %}
{% tab title="State Sync" %}
**We need to make a few more config edits to make sure your state sync goes smoothly.**

1. To find a good **trusted height** to use for a snapshot sync, we need to find the height of a snapshot available from `https://mainnet.tellorlayer.com/rpc/` . Copy and paste this entire block of commands into a terminal and hit enter:

```sh
export LATEST_HEIGHT=$(curl -s https://mainnet.tellorlayer.com/rpc/block | jq -r .result.block.header.height); \
export TRUSTED_HEIGHT=$((LATEST_HEIGHT - 35000)); \
export TRUSTED_HASH=$(curl -s "https://mainnet.tellorlayer.com/rpc/block?height=$TRUSTED_HEIGHT" | jq -r .result.block_id.hash); \
echo $TRUSTED_HEIGHT $TRUSTED_HASH

```

The output should be something like:

```sh
trusted height: 3785000
Trusted hash: DD27874AB1F5F4DFC5D7818E7CFBF8A8ECEDA745FFA78DF24D799B2B201418B9
```

2. Edit config.toml:

Open your config file:

```sh
nano ~/.layer/config/config.toml
```

Scroll or search (`ctrl^w`) the file and edit the state sync variables shown here to match the trusted height and trusted hash you found above:

```toml
# [statesync]
# ...
enable = true
#...
rpc_servers = "https://mainnet.tellorlayer.com/rpc/,https://mainnet.tellorlayer.com/rpc/"
trust_height = 3785000
trust_hash = "DD27874AB1F5F4DFC5D7818E7CFBF8A8ECEDA745FFA78DF24D799B2B201418B9"
trust_period = "168h0m0s"
```

Be sure to replace the `trust_height` and `trust_hash` with the block number and hash from the curl command above.

Exit nano with `ctrl^x` then enter `y` to save the changes.

3. Start your node:

{% code overflow="wrap" %}

```bash
./layerd start --home ~/.layer --key-name ACCOUNT_NAME --keyring-backend test --api.enable --api.swagger
```

{% endcode %}

The node should start up quickly and begin downloading a state snapshot from peers.

{% hint style="info" %}
Some errors related to peer connections can be expected even if the snapshot sync is working properly. (e.g. "we need more peers", or "Failed to reconnect")
{% endhint %}
{% endtab %}

{% tab title="Genesis Sync" %}
**Start your layer node with the command:**

```bash
./layerd start --key-name YOUR_ACCOUNT_NAME
```

You should now see your log quickly downloading blocks!

**Upgrades**

Your node will stop syncing at the following block height(s) for each binary upgrade:

`1534900 for upgrade v5.0.0`

`3891401 for upgrade v5.1.0`

`6699035 for upgrade v5.1.1`

`8593590 for upgrade v5.1.2`

`9908000 for upgrade v6.0.0`

`13280690 for upgrade v6.1.0`

... and so on!

When the sync stops for an upgrade at the heights shown above, you will need to kill the `layerd` process and start it back up again on the corresponding upgraded binary.\
\
Note: commands shown are for amd64 (linux).

{% code overflow="wrap" %}

```sh
# At height 1534900 the node will stop syncing:
# Download the v5.0.0 binary 
mkdir -p ~/layer/binaries && cd ~/layer/binaries && mkdir v5.0.0 && cd v5.0.0 && wget https://github.com/tellor-io/layer/releases/download/v5.0.0/layer_Linux_x86_64.tar.gz && tar -xvzf layer_Linux_x86_64.tar.gz
# change directory
cd ~/layer/binaries/v5.0.0

# TO RESUME SYNCING:
./layerd start --home ~/.layer --key-name ACCOUNT_NAME --keyring-backend test --api.enable --api.swagger

# At height 3891401 the node will stop syncing:
# Download the v5.1.0 binary 
mkdir -p ~/layer/binaries && cd ~/layer/binaries && mkdir v5.1.0 && cd v5.1.0 && wget https://github.com/tellor-io/layer/releases/download/v5.1.0/layer_Linux_x86_64.tar.gz && tar -xvzf layer_Linux_x86_64.tar.gz
# change directory
cd ~/layer/binaries/v5.1.0


# At height 6699035 the node will stop syncing:
# Download the v5.1.1 binary 
mkdir -p ~/layer/binaries && cd ~/layer/binaries && mkdir v5.1.1 && cd v5.1.1 && wget https://github.com/tellor-io/layer/releases/download/v5.1.1/layer_Linux_x86_64.tar.gz && tar -xvzf layer_Linux_x86_64.tar.gz
# change directory
cd ~/layer/binaries/v5.1.1
# resume syncing

# At height 8593590 the node will stop syncing:
# Download the v5.1.2 binary 
mkdir -p ~/layer/binaries && cd ~/layer/binaries && mkdir v5.1.2 && cd v5.1.2 && wget https://github.com/tellor-io/layer/releases/download/v5.1.2/layer_Linux_x86_64.tar.gz && tar -xvzf layer_Linux_x86_64.tar.gz
# change directory
cd ~/layer/binaries/v5.1.2
# resume syncing..

# At height 9908000 the nod.e will stop syncing:
# Download the v6.0.0 binary 
mkdir -p ~/layer/binaries && cd ~/layer/binaries && mkdir v6.0.0 && cd v6.0.0 && wget https://github.com/tellor-io/layer/releases/download/v6.0.0/layer_Linux_x86_64.tar.gz && tar -xvzf layer_Linux_x86_64.tar.gz
# change directory
cd ~/layer/binaries/v6.0.0
# resume syncing

# At height 13280690 the node will stop syncing:
# Download the v6.1.0-fix binary 
mkdir -p ~/layer/binaries && cd ~/layer/binaries && mkdir v6.1.0-fix && cd v6.1.0-fix && wget https://github.com/tellor-io/layer/releases/download/v6.1.0-fix/layer_Linux_x86_64.tar.gz && tar -xvzf layer_Linux_x86_64.tar.gz
# change directory
cd ~/layer/binaries/v6.1.0-fix
# resume syncing

# At height 13590000 the node will stop syncing:
# Download the v6.1.1 binary 
mkdir -p ~/layer/binaries && cd ~/layer/binaries && mkdir v6.1.1 && cd v6.1.1 && wget https://github.com/tellor-io/layer/releases/download/v6.1.1/layer_Linux_x86_64.tar.gz && tar -xvzf layer_Linux_x86_64.tar.gz
# change directory
cd ~/layer/binaries/v6.1.1
# resume syncing...

# the node will stop syncing at v6.1.3 upgrade height
# Download the v6.1.3 binary 
mkdir -p ~/layer/binaries && cd ~/layer/binaries && mkdir v6.1.3 && cd v6.1.3 && wget https://github.com/tellor-io/layer/releases/download/v6.1.3/layer_Linux_x86_64.tar.gz && tar -xvzf layer_Linux_x86_64.tar.gz
# change directory
cd ~/layer/binaries/v6.1.3
# resume syncing...

# the node will stop syncing at v6.1.4 upgrade height
# Download the v6.1.4 binary 
mkdir -p ~/layer/binaries && cd ~/layer/binaries && mkdir v6.1.4 && cd v6.1.4 && wget https://github.com/tellor-io/layer/releases/download/v6.1.4/layer_Linux_x86_64.tar.gz && tar -xvzf layer_Linux_x86_64.tar.gz
# change directory
cd ~/layer/binaries/v6.1.4
# resume syncing...

# the node will stop syncing at v6.1.5 upgrade height
# Download the v6.1.5 binary 
mkdir -p ~/layer/binaries && cd ~/layer/binaries && mkdir v6.1.5 && cd v6.1.5 && wget https://github.com/tellor-io/layer/releases/download/v6.1.5/layer_Linux_x86_64.tar.gz && tar -xvzf layer_Linux_x86_64.tar.gz
# change directory
cd ~/layer/binaries/v6.1.5
# resume syncing...
```

{% endcode %}
{% endtab %}
{% endtabs %}

To check if the node is fully synced, open a separate terminal window and run:

```sh
./layerd status
```

You should see a JSON formatted list of information about your running node. If you see `catching_up":false` that means that you're node is fully synced and ready to use!
