> ## Documentation Index
> Fetch the complete documentation index at: https://docs.qu.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Run A Node

> How to start and run a Quai Network node.

<Warning>
  Running go-quai on Windows or WSL2 is not currently supported.
</Warning>

### Requirements

To run a Quai Network node, the following specifications are suggested:

<CardGroup cols={2}>
  <Card icon="microchip" title="Fast CPU with 8+ cores" />

  <Card icon="usb-drive" title="16GB+ RAM" />

  <Card icon="server" title="Fast SSD with at least 1TB free space" />

  <Card icon="signal-stream" title="10+ MBit/sec download Internet service" />
</CardGroup>

## Install Dependencies

<Steps>
  <Step title="Go v1.23.0+">
    <Tabs>
      <Tab title="Linux Snap Install">
        *Snap is not default installed on all Linux distros*

        ```bash theme={null}
          # install snapd if you don't have it already
          sudo apt install snapd

          # install go
          sudo snap install go --classic
        ```
      </Tab>

      <Tab title="MacOS Install">
        Before installing go, make sure you have [homebrew](https://brew.sh/) installed as it is not installed by default on MacOS.

        ```bash theme={null}
        brew install go
        ```
      </Tab>
    </Tabs>

    If you're not on Ubuntu or MacOS, instructions on how to install go directly can be found on the [golang installation page](https://go.dev/doc/install).
  </Step>

  <Step title="Git, Make, and G++">
    <Tabs>
      <Tab title="Linux Install">
        Install git, make, and g++ with the following command:

        ```bash theme={null}
        # install git and make
        sudo apt install git make g++
        ```
      </Tab>

      <Tab title="MacOS Install">
        Install git and make with the following command:

        <Info>
          MacOS machines already have g++ installed.
        </Info>

        ```bash theme={null}
        # install git and make
        brew install git make
        ```
      </Tab>
    </Tabs>
  </Step>
</Steps>

## Node Configuration

### Start

<AccordionGroup defaultIndex="0">
  <Accordion title="Mainnet (Colosseum)">
    ```bash theme={null}
    # Clone go-quai and checkout latest release
    git clone https://github.com/dominant-strategies/go-quai
    cd go-quai
    git checkout <latest-tag>
    make go-quai

    # Start node
    ./build/bin/go-quai start \
    --node.slices '[0 0]' \
    --node.quai-coinbases '0x0000000000000000000000000000000000000001' \
    --node.qi-coinbases '0x0080000000000000000000000000000000000001' \
    ```
  </Accordion>

  <Accordion title="Mainnet Testnet (Orchard)">
    <Warning>
      The Orchard testnet requires using the `orchard` branch of go-quai. Using any other branch or tag will result in sync issues or genesis incompatibility.
    </Warning>

    ```bash theme={null}
    # Clone go-quai and checkout orchard branch
    git clone https://github.com/dominant-strategies/go-quai
    cd go-quai
    git checkout orchard
    make go-quai

    # Start node
    ./build/bin/go-quai start \
    --node.slices '[0 0]' \
    --node.genesis-nonce 62242624366553750196964614682162313 \
    --node.environment "orchard" \
    --node.quai-coinbases '0x0000000000000000000000000000000000000001' \
    --node.qi-coinbases '0x0080000000000000000000000000000000000001' \
    ```
  </Accordion>

  <Accordion title="Local Developer Network">
    ```bash theme={null}
    # Clone go-quai and checkout latest release
    git clone https://github.com/dominant-strategies/go-quai
    cd go-quai
    git checkout <latest-tag>
    make go-quai # make debug is also available for line by line debugging


    # Start node
    ./build/bin/go-quai start \
    --node.slices '[0 0]' \
    --node.environment "local" \
    --node.quai-coinbases '0x0000000000000000000000000000000000000001' \
    --node.qi-coinbases '0x0080000000000000000000000000000000000001' \
    ```
  </Accordion>
</AccordionGroup>

<Warning>
  The coinbase values above are set to dummy values. If you do not replace them
  with your own addresses, you will not receive block rewards.
</Warning>

This will spin up a node using the values of the `node.slices`, `node.quai-coinbases`, `node.qi-coinbases` flags in your command. Logs should begin printing to the terminal.

### Stop

Stopping your node should be done any time you make changes to your config file or prior to shutting your machine down. A node instance can terminated using `CTRL+C`.

<Note>
  If you're running a miner, `CTRL+C` may not work. You must kill the miner
  process prior to stopping the node.
</Note>

### Environment Variables

There are a few key variables required to run a Quai node. **They will be passed as arguments in the [start command](#start)**.

* `quai-coinbases` and `qi-coinbases`: the addresses in each ledger that block rewards and miner tips are paid to.
* `miner-preference`: the percentage of block rewards that should be paid out on average in Quai or Qi tokens.
* `slices`: the slices of the network that the node will run.

<Note>
  There are a number of more advanced parameters that can be passed as arguments
  that *will not be covered* in this article.
</Note>

<Steps>
  <Step title="Configure Mining Addresses">
    Coinbases will be passed to the `start` command similar to below, with your own addresses for the chains that you intend to mine. You can generate addresses for each shard and ledger easily with [Pelagus Wallet](https://chromewebstore.google.com/detail/pelagus/nhccebmfjcbhghphpclcfdkkekheegop).

    You must generate **unique Quai and Qi addresses** for each shard your node is running and **pass them as coinbase flags to the run command**. There is a unique coinbases flag for each ledger:

    * `quai-coinbases`: Coinbases for Quai ledger
    * `qi-coinbases`: Coinbases for Qi ledger

    ```bash theme={null}
    # single slice node running cyprus1, one quai address + one qi address
    --node.quai-coinbases '0x0000000000000000000000000000000000000000'
    --node.qi-coinbases '0x0080000000000000000000000000000000000000'
    ```

    <Note>
      The Qi mining address starts with a "0x00...", this is not to be confused with the Qi payment address. You can find the Qi mining address in the settings of the Pelagus Wallet.
    </Note>
  </Step>

  <Step title="Block Reward Prefernce">
    The Quai protocol can payout block rewards and miner tips in either [Quai](/learn/tokenomics/quai-emissions) or [Qi](/learn/tokenomics/qi-emissions) tokens. While miners have no ability to determine what token their miner tips are paid out in, the do have the ability to set their block reward payout token preference to either Quai or Qi.

    Block reward token preference can be set using the `miner-preference` flag. The `miner-preference` flag is a percentage scale that can be set to values between 0 and 1, indicating the proportion of block rewards that should be paid out in Quai or Qi tokens.

    Some examples:

    * `0`: 100% Quai preference, all block rewards are paid out in Quai
    * `0.25`: 3/1 Quai preference
    * `0.5`: Even split, on average block rewards are paid out equally in Quai and Qi
    * `0.75`: 3/1 Qi preference
    * `1`: 100% Qi preference, all block rewards are paid out in Qi

    Pass the `miner-preference` flag in the `start` command with a value between 0 and 1 like below:

    ```bash theme={null}
    # no preference (default)
    --node.miner-preference 0.5
    ```

    ```bash theme={null}
    # 100% Quai preference
    --node.miner-preference 0
    ```

    ```bash theme={null}
    # 100% Qi preference
    --node.miner-preference 1
    ```
  </Step>

  <Step title="Reward Lockup Period">
    The Quai protocol immediately pays out block rewards as blocks are mined, but are subject to a lockup period.

    * Quai Block rewards are sent to the coinbase of the miner after the lockup period has elapsed.
    * Qi Block reward tokens are sent to the coinbase of the miner and register as balance, but are deemed "not spendable" until they are unlocked.

    The lockup period is configurable by miners using the `--node.coinbase-lockup` flag. The protocol provides additional incentives for miners to lock up their block rewards for a longer period of time.

    The available values for `--node.coinbase-lockup` and their corresponding period and reward boost are:

    | Lock Byte | Period (blocks) | Period (days) | Year 1 | Year 2 | Year 3 | Year 4 | Year 5+ |
    | --------- | --------------- | ------------- | ------ | ------ | ------ | ------ | ------- |
    | `0*`      | 241,920         | 2 weeks       | 0%     | 0%     | 0%     | 0%     | 0%      |
    | `1`       | 1,555,200       | 3 months      | 3.50%  | 2.68%  | 1.86%  | 1.04%  | 0.22%   |
    | `2`       | 3,110,400       | 6 months      | 10.00% | 7.66%  | 5.31%  | 2.97%  | 0.63%   |
    | `3`       | 6,220,800       | 12 months     | 25.00% | 19.14% | 13.28% | 7.42%  | 1.56%   |

    <sub>\*Base maturity period</sub>

    <Note>The reward percentage decreases linearly between each year shown in the table.</Note>

    Pass the `--node.coinbase-lockup` flag in the `start` command like below:

    ```bash theme={null}
    # minimum lockup (default)
    --node.coinbase-lockup 0
    ```

    ```bash theme={null}
    # maximum lockup
    --node.coinbase-lockup 3
    ```
  </Step>

  <Step title="Slices">
    Set the `node.slices` flag in your run command to whichever slices of the network you would like to run.

    In the codebase, a slice is identified by its [region and zone index](/client/node#networking-and-conventions). Region and zone indices are 0-indexed and range from 0-2.

    <Tip>The Colosseum Mainnet and Orchard Testnet only support the `[0 0]` slice.</Tip>

    ```bash theme={null}
    # single slice node running cyprus1
    --node.slices '[0 0]'
    ```
  </Step>

  <Step title="Network Environment & Genesis Nonce">
    To connect to Quai, you must have the correct genesis nonce for the intended network. The nonce acts as a password that allows your node to correctly compute the first canonical block in the chain.

    You'll pass the genesis nonce to your node on start-up using the `--node.genesis-nonce` flag.

    ```bash theme={null}
    # Orchard Testnet geneis nonce
    --node.genesis-nonce 62242624366553750196964614682162313
    --node.environment "orchard"
    ```

    Options for `--node.environment` are: `"colosseum"` (mainnet), `"orchard"` (mainnet testnet), `"garden"` (mainnet devnet), and `"local"`.

    | Environment | Description       | Genesis Nonce                       |
    | ----------- | ----------------- | ----------------------------------- |
    | `colosseum` | Mainnet           | 23621466532946281564673705261963422 |
    | `orchard`   | Mainnet testnet   | 62242624366553750196964614682162313 |
    | `local`     | Local development | N/A                                 |
  </Step>

  <Step title="Run an Index Node">
    To provide UTXO data to external clients your node will need to index all UTXO address information. To enable this you'll pass the following flag to your client upon startup. Keep in mind this will consume more storage than running without it.

    ```bash theme={null}
    # Index UTXO address information
    --node.index-address-utxos "true"
    ```

    <Tip>When starting your node with this flag you must sync from an official [snapshot](/guides/client/node#download-and-sync-from-snapshot). If you disable and re-enable this flag in the future you will need to re-sync from an official [snapshot](/guides/client/node#download-and-sync-from-snapshot).</Tip>
  </Step>
</Steps>

## Check Log Output

Starting a node will run all instances of go-quai in the foreground and also create a directory named nodelogs to store more specific logs from the node. Outputs from the node will be piped to a context specific `.log` file inside of the nodelogs directory. To view the log output for a specific location, use:

```bash theme={null}
# view global logs (recommended)
tail -f nodelogs/global.log

# view specific region or zone logs
tail -f nodelogs/region-0.log
# OR
tail -f nodelogs/zone-0-0.log
```

Checking the node logs output is the best way to *verify that your full node is running correctly*. You can also easily view node logs in your favorite IDE or text editor.

The outputs of a node that has **started correctly** should look similar to below.

```log theme={null}
INFO   [10-02|19:42:12.077] Loading config from file: /root/.config/go-quai/config.toml
INFO   [10-02|19:42:12.108] Loading config from environment variables with prefix: 'GO_QUAI_'
INFO   [10-02|19:42:12.109] Global logger started                         fields.level=info path=./nodelogs/global.log
INFO   [10-02|19:42:12.137] Starting v0.19.0-pre on the lighthouse network
INFO   [10-02|19:42:12.137] node version                                  commit= date=
INFO   [10-02|19:42:12.867] node created: 12D3KooWKQgbSobfca6KnB55XZtMyntSaCNXTaTdoisPGzrgKFjA
INFO   [10-02|19:42:13.182] Coinbase Addresses: map[cyprus1:0x0000000000000000000000000000000000000000]
INFO   [10-02|19:42:13.469] Finished connecting miner endpoints
INFO   [10-02|19:42:14.576] Finished connecting miner endpoints
INFO   [10-02|19:42:14.577] starting P2P node...
INFO   [10-02|19:42:14.577] Starting metrics
INFO   [10-02|19:42:14.578] Event: 'Local address updated': /ip4/127.0.0.1/tcp/4001/p2p/12D3KooWKQgbSobfca6KnB55XZtMyntSaCNXTaTdoisPGzrgKFjA
```

**To stop log outputs to the terminal, you can use CTRL+C.**

<Warning>Depending on what your node is currently doing, your logs may not look **exactly** the same as above.</Warning>

## Checking Sync Progress

If your node has started correctly, it will begin syncing chain state from peers. There are a few ways to check the progress of the sync.

From the **command line**, we can run the following command(s) to print the list of blocks that have been appended. **Replace** `location-to-print-here.log` **with the file name of the logs you'd like to print**.

```bash theme={null}
# Print all appended blocks
cat nodelogs/location-to-print-here.log | grep Appended

# Continuously print new appended blocks
tail -f nodelogs/location-to-print-here.log | grep Appended

# Continuously print appended blocks across all chains
tail -f nodelogs/* | grep Appended
```

The output should look similar to below:

```bash theme={null}
INFO   [09-18|10:18:17.273] Appended new block                       number=[102 1934 40392] hash=0x0000067368b679ce7994dbd6e3dfe93a5e5fe16642a6083604fd405556836cbe difficulty=405369 uncles=0 txs=0 etxs=0 gas=0 gasLimit=5000000 root=0x7df4c77d1463a5e4c7d5f5446476e34df01cf14b6226b7d83ccab072bc302edc order=2 location=[0 0] elapsed=2.019ms
INFO   [09-18|10:18:17.736] Appended new block                       number=[102 1934 40393] hash=0x0000285b7ffa020c8f9f5f8832381593170d1d7618ad2fae8202350a0d81acac difficulty=405875 uncles=0 txs=0 etxs=0 gas=0 gasLimit=5000000 root=0x81954cf5d93a979890641acffe7496965ff4602ad2b24d24ab5356ba52072c39 order=2 location=[0 0] elapsed=1.933ms
INFO   [09-18|10:18:17.803] Appended new block                       number=[102 1934 40394] hash=0x00000d6f0d100a8d254088090876a6ab911720af7e7bc6454f5d1a01417f786f difficulty=406382 uncles=0 txs=0 etxs=0 gas=0 gasLimit=5000000 root=0x8eb0b430e2df8f91a180b6f29fea46430c9014ccde42fa538df62bf3251dff03 order=2 location=[0 0] elapsed=2.005ms
INFO   [09-18|10:18:18.511] Appended new block                       number=[102 1934 40395] hash=0x00001211f391c0a162701ad0dcbdef47f4efe96b3fb5f77e1f0b75b6ff439312 difficulty=406889 uncles=0 txs=0 etxs=0 gas=0 gasLimit=5000000 root=0xc810b3d05f9a9b7f4fee3da271d3544cba26b6368f84ee5e5e885cbe4fd11cab order=2 location=[0 0] elapsed=2.147ms
```

**To check the progress of your node's sync, compare the number of the latest block output from the above command to the current height of the chain you're running on the** [**Quai node stats page**](https://stats.quai.network/).

<Warning>
  If your node temporarily stops appending during sync, do not stop it. Allow it to continue running, and only reach out for support if the
  node has not appended a block for over 1 hour.
</Warning>

## Update Your Node

<Warning>
  Initiating the node update process while the node or manager are currently running could cause issues. Make sure to stop all processes before updating.
</Warning>

To update a node, first **make sure to stop all instances of go-quai** before proceeding.

After stopping the node, you should pull any updated code using:

```bash theme={null}
git fetch --all
```

Checkout the [latest release of go-quai](https://github.com/dominant-strategies/go-quai/tags):

```bash theme={null}
git checkout put-latest-release-here
```

Finally, rebuild the source using:

```bash theme={null}
make go-quai
```

After pulling any new code and rebuilding the source, you can safely restart the node and continue running.

## Reset and Clear

<Warning>
  Resetting your node and clearing your database will remove any state you have synced. This is a non-reversible action and any commands noted below should be utilized with caution.
</Warning>

Developers and node runners may find that situations arise where they need to completely clear your node of synced state or do a full reset in the case of an issue or bug. A full reset of a node involves stopping the node, clearing the current nodelogs, and removing all synced state.

**Reminder, resetting your node is non-reversible and should only be done if you understand the implications of removing all synced state.**

<Tabs>
  <Tab title="Linux">
    For **Linux Machines**, we'll remove the `nodelogs` directory and the base `~/.local/share/go-quai` directory which contains all synced state. To do this, run the following command:

    ```bash theme={null}
    rm -rf nodelogs ~/.local/share/go-quai
    ```
  </Tab>

  <Tab title="MacOS">
    For **MacOS machines**, we'll use a different command to remove the same directories:

    ```bash theme={null}
    rm -rf nodelogs ~/Library/Application\ Support/go-quai
    ```
  </Tab>
</Tabs>

After running the above command, the node has been fully reset and is ready to be restarted.

## Create Backup/Snapshot

You can create your own backup or snapshot to:

* Store for later.
* Move to another machine.

1. Shut down the node cleanly. You can use `ctrl+c`.
2. Remove the peer db. It is stored in the genesis hash folder.

   <Tabs>
     <Tab title="Mainnet">
       ```bash theme={null}
       # Linux
       rm -rf ~/.local/share/go-quai/0xd0c4fae4dc06d3558c7631f6665cca93931cfc8891729fe1bdaa1024b0db9c98

       # MacOS
       rm -rf ~/Library/Application\ Support/go-quai/0xd0c4fae4dc06d3558c7631f6665cca93931cfc8891729fe1bdaa1024b0db9c98
       ```
     </Tab>

     <Tab title="Orchard">
       ```bash theme={null}
       # Linux
       rm -rf ~/.local/share/go-quai/0x0a66d053d111b0f8321aa82904a75b0a74768f8c14d783edf8b5929c33d44df2

       # MacOS
       rm -rf ~/Library/Application\ Support/go-quai/0x0a66d053d111b0f8321aa82904a75b0a74768f8c14d783edf8b5929c33d44df2
       ```
     </Tab>
   </Tabs>
3. Compress the database for smaller storage and faster transfers.

   <Tabs>
     <Tab title="Linux">
       ```bash theme={null}
       tar -I zstd -cvf mainnet-snapshot.tar.zst ~/.local/share/go-quai
       ```
     </Tab>

     <Tab title="MacOS">
       Ensure that zstd is installed in your version of MacOS. You can run:

       ```bash theme={null}
       brew install zstd
       tar --use-compress-program=zstd -cvf mainnet-snapshot.tar.zst ~/Library/Application\ Support/go-quai
       ```
     </Tab>
   </Tabs>

## Download and Sync from Snapshot

Common reasons for syncing from a snapshot include:

* Reducing syncing times
* Restarting a node on a new machine/drive

<Warning>
  Please be aware that when you are syncing from a snapshot, you are trusting the contents of the snapshot. For your node to fully verify the network, you must sync from genesis.
</Warning>

To restore your node's database from a snapshot you'll first need to **stop your node**. You can then download the latest official snapshot from the official snapshot link or from the CLI by running the command below. The link will be added and periodically updated here once the first snapshot for Quai Mainnet is taken.

<Tabs>
  <Tab title="Mainnet">
    ```bash theme={null}
    wget https://snapshot.qu.ai/mainnet-snapshot.tar.zst
    ```

    <Tabs>
      <Tab title="Linux">
        To restore your database from a snapshot, use:

        ```bash theme={null}
          # Remove current db
          # This command will permanently delete all state that you have synced thus far
          rm -rf ~/.local/share/go-quai

          # Expand compressed db
          tar -I 'zstd -T0' -xvf mainnet-snapshot.tar.zst

          # Copy db into db directory
          cp -r mainnet-snapshot ~/.local/share/go-quai
        ```
      </Tab>

      <Tab title="MacOS">
        To restore your database from a snapshot, use:

        ```bash theme={null}
          # Remove current db
          # This command will permanently delete all state that you have synced thus far
          rm -rf ~/Library/Application\ Support/go-quai

          # Expand compressed db
          tar --use-compress-program='zstd -T0' -xvf mainnet-snapshot.tar.zst

          # Copy db into db directory
          cp -r mainnet-snapshot ~/Library/Application\ Support/go-quai
        ```
      </Tab>
    </Tabs>
  </Tab>

  <Tab title="Orchard Testnet">
    ```bash theme={null}
    wget https://snapshot.qu.ai/orchard-snapshot.tar.zst
    ```

    <Tabs>
      <Tab title="Linux">
        To restore your database from a snapshot, use:

        ```bash theme={null}
          # Remove current db
          # This command will permanently delete all state that you have synced thus far
          rm -rf ~/.local/share/go-quai

          # Expand compressed db
          tar -I 'zstd -T0' -xvf orchard-snapshot.tar.zst

          # Copy db into db directory
          cp -r orchard-snapshot ~/.local/share/go-quai
        ```
      </Tab>

      <Tab title="MacOS">
        To restore your database from a snapshot, use:

        ```bash theme={null}
          # Remove current db
          # This command will permanently delete all state that you have synced thus far
          rm -rf ~/Library/Application\ Support/go-quai

          # Expand compressed db
          tar --use-compress-program='zstd -T0' -xvf orchard-snapshot.tar.zst

          # Copy db into db directory
          cp -r orchard-snapshot ~/Library/Application\ Support/go-quai
        ```
      </Tab>
    </Tabs>
  </Tab>
</Tabs>
