# Setup Full Node

This document details how to join the Secret Network `secret-4` mainnet as a full node. Once your full node is running and synced to the last block, you can use it

## Requirements <a href="#requirements" id="requirements"></a>

{% hint style="danger" %}
Secret Network has strict Hardware Requirements, see [hardware-compliance](https://docs.scrt.network/secret-network-documentation/infrastructure/running-a-node-validator/setting-up-a-node-validator/hardware-setup/hardware-compliance "mention"). If your machine does not meet them, it will \*NOT\* work as a node.
{% endhint %}

* Ubuntu/Debian host, recommended is Ubuntu 20.04 LTS or 22.04 LTS.
* A public IP address, so that other nodes can connect to you.
* Open ports `TCP 26656 & 26657` *Note: If you're behind a router or firewall then you'll need to port forward on the network device.*
* Reading [Tendermint: Running in production](https://docs.tendermint.com/v0.34/tendermint-core/running-in-production.html)
* RPC address of an already active node. You can use any node that exposes RPC services, please see [mainnet-secret-4](https://docs.scrt.network/secret-network-documentation/development/resources-api-contract-addresses/connecting-to-the-network/mainnet-secret-4 "mention").

## Installation <a href="#installation" id="installation"></a>

### **Install SGX and `secretd`**

{% hint style="danger" %}
This guide assumes you've already installed the latest version of secretd and SGX.
{% endhint %}

For more information on how to install SGX, see instructions [here](https://docs.scrt.network/secret-network-documentation/infrastructure/running-a-node-validator/setting-up-a-node-validator/node-setup/install-sgx-1).&#x20;

If you need help with installing secretd, please take a look at [install-secretd](https://docs.scrt.network/secret-network-documentation/infrastructure/running-a-node-validator/setting-up-a-node-validator/testnet/install-secretd "mention").

### **Initialize Secret Network Configs**

Choose a **moniker** for yourself, and replace `<MONIKER>` with whatever name you like (could be some random string, or just how you like to name to node) below. This moniker is your public nickname of the node in the network.

```bash
secretd init <MONIKER> --chain-id secret-4
```

This will generate the following files in `~/.secretd/config/`

* `genesis.json`
* `node_key.json`
* `priv_validator_key.json`

### **Download `genesis.json`**

```bash
wget -O ~/.secretd/config/genesis.json "https://github.com/scrtlabs/SecretNetwork/releases/download/v1.2.0/genesis.json"
# verify genesis.json checksum
echo "759e1b6761c14fb448bf4b515ca297ab382855b20bae2af88a7bdd82eb1f44b9 $HOME/.secretd/config/genesis.json" | sha256sum --check
```

### **Initialize Secret Enclave**

Initialize `/opt/secret/.sgx_secrets`:

```bash
mkdir -p /opt/secret/.sgx_secrets
```

You can choose between two methods, [**automatic**](#initialize-secret-enclave---automatic-registration-experimental) **or** [**manual**](#initialize-secret-enclave---manual-registration):

#### **Initialize Secret Enclave - c**

{% hint style="danger" %}
WARNING: This method is experimental, and may not work. If it doesn't work, skip to [manual registration](#initialize-secret-enclave---manual-registration).
{% endhint %}

The following commands will create the necessary environment variables and attempt to automatically register the node.

```bash
export SCRT_ENCLAVE_DIR=/usr/lib
export SCRT_SGX_STORAGE=/opt/secret/.sgx_secrets
secretd auto-register
```

If this step was successful, you can skip straight to [Optimization](#optimization).

#### **Initialize Secret Enclave - Manual Registration**

```bash
secretd init-enclave
```

### Verify Enclave Initialization

The attestation certificate should have been created by the previous step

```bash
ls -lh /opt/secret/.sgx_secrets/attestation_combined.bin
```

Verify the certificate is valid. A 64-character registration key will be printed if it was successful.

```bash
PUBLIC_KEY=$(secretd dump /opt/secret/.sgx_secrets/pubkey.bin)
echo $PUBLIC_KEY
```

{% hint style="danger" %}
If registration was NOT succesfull consider checking out the [Registration troubleshoot](https://docs.scrt.network/secret-network-documentation/infrastructure/running-a-node-validator/setting-up-a-node-validator/hardware-setup/registration-troubleshooting) help or contact a fellow validator on our [discord](https://scrt.network/discord).
{% endhint %}

### **Configure `secretd`**

{% hint style="info" %}
The following steps should use `secretd` be ran on the full node itself. To run the steps with `secretd` on a local machine, [set up the CLI](https://docs.scrt.network/cli/install-cli.html) there.
{% endhint %}

Configure `secretd`. Initially you'll be using the bootstrap node, as you'll need to connect to a running node and your own node is not running yet.

```bash
secretd config set client chain-id secret-4
secretd config set client node https://rpc.mainnet.secretsaturn.net
secretd config set client output json
```

### **Fund Secret Wallet**

If you already have a wallet funded with `SCRT`, you can import the wallet by doing the following:

```bash
secretd keys add <key-alias> --recover
```

Otherwise, you will need to set up a key. Make sure you back up the mnemonic and the keyring password.

```bash
secretd keys add <key-alias>
```

This will output your address, a 45 character-string starting with `secret1...`.

### **Configure Node Attestation**

1. Register your node on-chain

```bash
secretd tx register auth /opt/secret/.sgx_secrets/attestation_combined.bin -y --gas 700000 --from <key-alias>
```

2\. Pull & check your node's encrypted seed from the network

```bash
SEED=$(secretd query register seed $PUBLIC_KEY | cut -c 3-)
echo $SEED
```

3\. Get additional network parameters

These are necessary to configure the node before it starts.

```bash
secretd query register secret-network-params
ls -lh ./io-master-key.txt ./node-master-key.txt
```

### **Configure Secret Node**

{% hint style="info" %}
From here on, commands must be ran on the full node.
{% endhint %}

```bash
mkdir -p ~/.secretd/.node
secretd configure-secret node-master-key.txt $SEED
```

### **Optimization**

In order to be able to handle NFT minting and other Secret Contract-heavy operations, it's recommended to update your SGX memory enclave cache:

```bash
sed -i.bak -e "s/^contract-memory-enclave-cache-size *=.*/contract-memory-enclave-cache-size = \"15\"/" ~/.secretd/config/app.toml
```

Also checkout [this document](https://gist.github.com/blockpane/40bc6b64caa48fdaff3b0760acb51eaa) by `block pane` for fine tuning your machine for better uptime.

#### **Set `minimum-gas-price` Parameter**

We recommend `0.1uscrt` per gas unit:

```bash
perl -i -pe 's/^minimum-gas-prices = .+?$/minimum-gas-prices = "0.1uscrt"/' ~/.secretd/config/app.toml
```

Your node will not accept transactions that specify `--fees` lower than the `minimun-gas-price` you set here.

#### Set IAVL-disable-fastnode

IAVL fast node **must** be disabled, otherwise the daemon will attempt to upgrade the database whil state sync is occuring.

```
sed -i.bak -e "s/^iavl-disable-fastnode *=.*/iavl-disable-fastnode = true/" $HOME/.secretd/config/app.toml
```

### **Enable `secret-node`:**

{% hint style="info" %}
Note that the `secret-node` system file is created when installing sgx.
{% endhint %}

```bash
sudo systemctl enable secret-node 
```

You are now a now ready to finally sync the full node. 🎉.

Go to [state-sync](https://docs.scrt.network/secret-network-documentation/infrastructure/running-a-node-validator/setting-up-a-node-validator/node-setup/state-sync "mention") or [snapshot](https://docs.scrt.network/secret-network-documentation/infrastructure/running-a-node-validator/setting-up-a-node-validator/node-setup/snapshot "mention") to continue.

### **Snapshot**

To sync to head quickly, please see [snapshot](https://docs.scrt.network/secret-network-documentation/infrastructure/running-a-node-validator/setting-up-a-node-validator/node-setup/snapshot "mention").

### **State Sync**

You can skip syncing from scratch or download a snapshot by [state-sync](https://docs.scrt.network/secret-network-documentation/infrastructure/running-a-node-validator/setting-up-a-node-validator/node-setup/state-sync "mention") to the current block.

### Get Node ID <a href="#id-21-get-your-node-id-with" id="id-21-get-your-node-id-with"></a>

`secretd tendermint show-node-id`

And publish yourself as a node with this ID:

```
<your-node-id>@<your-public-ip>:26656
```

Be sure to point your CLI to your running node instead of the bootstrap node

`secretcli config node tcp://localhost:26657`

If someone wants to add you as a peer, have them add the above address to their persistent\_peers in their \~/.secretd/config/config.toml.

And if someone wants to use your node from their secretcli then have them run:

```
secretcli config set client chain-id secret-4
secretcli config set client output json
secretcli config set client indent true
secretcli config set client node tcp://<your-public-ip>:26657
```

### **Optional: Become a Validator**

To turn your full node into a validator, see [Joining Mainnet as a Validator](https://docs.scrt.network/docs/node-runners/node-setup/becoming-a-validator).
