# State sync

‘[State Sync](https://docs.tendermint.com/v0.34/tendermint-core/state-sync.html#state-sync)’ feature was included in the recent release of the tendermint core v0.34 update.\
The feature allows users to look up information on the most recent credible block height instead of having to look up all block information from the past. The ‘state sync’ feature reduces the time required to synchronize the network to a matter of minutes.

### State syncing a node

FirmaChain is structured to create a status sync snapshot of a portion of its nodes to allow a new node to join the network using the ‘State Sync’ feature. In order to join the network through ‘State Sync’ the following information must be retrieved in advance.

* At least 2 available RPC servers.
* A trusted height.
* The block ID hash of the trusted height.

### List of networks provided

Please refer to the genesis file, the seed and the github link according to your choice of network.

<table data-header-hidden><thead><tr><th width="131"></th><th width="157"></th><th width="149"></th><th width="144"></th><th></th></tr></thead><tbody><tr><td><strong>Network</strong></td><td><strong>chain-id</strong></td><td><strong>genesis.json</strong></td><td><strong>seeds</strong></td><td><strong>github</strong></td></tr><tr><td>Mainnet</td><td>colosseum-1</td><td><a href="https://github.com/FirmaChain/mainnet/blob/main/colosseum-1/genesis.json">Link</a></td><td><a href="https://github.com/firmachain/mainnet#seed-nodes">Link</a></td><td><a href="https://github.com/firmachain/mainnet">Link</a></td></tr><tr><td>Testnet</td><td>imperium-4</td><td><a href="https://github.com/FirmaChain/testnet/blob/master/imperium-4/genesis.json">Link</a></td><td><a href="https://github.com/FirmaChain/testnet/tree/master/imperium-4#seed-node">Link</a></td><td><a href="https://github.com/FirmaChain/testnet/tree/master/imperium-4">Link</a></td></tr></tbody></table>

### Initialize the firmachain

Initialize the node and designate the name of the moniker.

```bash
firmachaind init <moniker-name> --chain-id <chain-id>
```

### Rename the moniker

Before activating the chain, you can modify the name of the node using the moniker field at \~/.firmachain/config/config.toml.

```bash
vim .firmachain/config/config.toml

# A custom human readable name for this node
moniker = "<moniker-name>"
```

### Setup minimum gas prices

Modify minimum gas fee.

```bash
sed -i -E 's/minimum-gas-prices = ".*"/minimum-gas-prices = "0.01ufct"/' ~/.firmachain/config/app.toml
```

### Set seeds

FirmaChain discloses information on seed nodes for the purpose of P2P connection.

```bash
# Mainnet
sed -i.bak -e "s/^seeds *=.*/seeds = \"f89dcc15241e30323ae6f491011779d53f9a5487@mainnet-seed1.firmachain.dev:26656,04cce0da4cf5ceb5ffc04d158faddfc5dc419154@mainnet-seed2.firmachain.dev:26656,940977bdc070422b3a62e4985f2fe79b7ee737f7@mainnet-seed3.firmachain.dev:26656\"/" ~/.firmachain/config/config.toml
```

```bash
# Testnet
sed -i.bak -e "s/^seeds *=.*/seeds = \"583717da6ee75478aea4e6717aff03e0faab4370@testnet-seed1.firmachain.dev:26656,d1619ff4762037484017e3c48c7c40c1f94bca47@testnet-seed2.firmachain.dev:26656\"/" ~/.firmachain/config/config.toml
```

### Download genesis.json file

After downloading the genesis.json file of the network you are planning to join, please swap the file with \~/.firmachain/config/genesis.json.

```bash
# Mainnet genesis.json
wget https://raw.githubusercontent.com/FirmaChain/mainnet/main/colosseum-1/genesis.json -O ~/.firmachain/config/genesis.json
```

```bash
# Testnet genesis.json
wget https://raw.githubusercontent.com/FirmaChain/testnet/master/imperium-4/genesis.json -O ~/.firmachain/config/genesis.json
```

### **Set trust datas**

If you do not have a jq package, please install the jq package.

```
sudo apt install jq -y
```

By running the command below, you will be able to retrieve data on the ‘trust height’ and ‘trust\_hash’ via RPC.

```bash
# Mainnet
SNAP_RPC="https://lcd-mainnet.firmachain.dev:26657"
BLOCK_HEIGHT=$(curl -s $SNAP_RPC/block | jq -r .result.block.header.height | awk '{print $1 - ($1 % 10000-1)}') &&
TRUST_HASH=$(curl -s "$SNAP_RPC/block?height=$BLOCK_HEIGHT" | jq -r .result.block_id.hash)

echo $BLOCK_HEIGHT $TRUST_HASH

# Expected return data
18520001 7623BBA5B341DA3C9FC716103A56AAD3ABA2D4FC4BC57F786B3474F5F631DEE8
```

```bash
# Testnet
SNAP_RPC="https://lcd-testnet.firmachain.dev:26657"
BLOCK_HEIGHT=$(curl -s $SNAP_RPC/block | jq -r .result.block.header.height | awk '{print $1 - ($1 % 10000-1)}') &&
TRUST_HASH=$(curl -s "$SNAP_RPC/block?height=$BLOCK_HEIGHT" | jq -r .result.block_id.hash)

echo $BLOCK_HEIGHT $TRUST_HASH

# Expected return data
3500001 C4D994F9BDEF1A49EBEAF3552B9BD5BCF2E887CDA318816E6A70C69E0EEADD99
```

#### A method other than JQ

Use this method if you don't want to use a Docker image or install JQ.

```bash
SNAP_RPC= # Mainnet or Testnet PRC address
BLOCK_HEIGHT=$(curl -s $SNAP_RPC/block | grep -o '"height":"[0-9]\+"' | head -n1 | grep -o '[0-9]\+' | awk '{print $1 - ($1 % 10000 - 1)}')
TRUST_HASH=$(curl -s "$SNAP_RPC/block?height=$BLOCK_HEIGHT" \
  | grep -o '"hash":"[A-F0-9]\+"' \
  | head -n1 \
  | sed 's/"hash":"//;s/"//')

echo $BLOCK_HEIGHT $TRUST_HASH
```

Please set the chain to allow ‘State Sync’ feature and put in the retrieved data in the config.toml file.

```bash
# Mainnet
sed -i -e 's/enable = false/enable = true/g' ~/.firmachain/config/config.toml
sed -i -e 's/rpc_servers = ""/rpc_servers = "mainnet-seed1.firmachain.dev:26657,mainnet-seed2.firmachain.dev:26657,mainnet-seed3.firmachain.dev:26657"/g' ~/.firmachain/config/config.toml
sed -i -e 's/trust_height = 0/trust_height = 18520001/g' ~/.firmachain/config/config.toml
sed -i -e 's/trust_hash = ""/trust_hash = "7623BBA5B341DA3C9FC716103A56AAD3ABA2D4FC4BC57F786B3474F5F631DEE8"/g' ~/.firmachain/config/config.toml
sed -i -e 's/trust_period = "168h0m0s"/trust_period = "336h0m0s"/g' ~/.firmachain/config/config.toml
```

```bash
# Testnet
sed -i -e 's/enable = false/enable = true/g' ~/.firmachain/config/config.toml
sed -i -e 's/rpc_servers = ""/rpc_servers = "testnet-seed1.firmachain.dev:26657,testnet-seed2.firmachain.dev:26657"/g' ~/.firmachain/config/config.toml
sed -i -e 's/trust_height = 0/trust_height = 1337168/g' ~/.firmachain/config/config.toml
sed -i -e 's/trust_hash = ""/trust_hash = "C826D099BD2F4E941597140115F4871067B293563A9019A9E788FF434EF3771B"/g' ~/.firmachain/config/config.toml
sed -i -e 's/trust_period = "168h0m0s"/trust_period = "336h0m0s"/g' ~/.firmachain/config/config.toml
```

Now we are all set. Please start the chain. \
Once you start the chain, it will automatically search and restore the status sync snapshot from the network. (This process takes approximately 2 to 5 minutes.)

```
firmachaind start

Discovering snapshots for 15s
Discovered new snapshot        height=3000 format=1 hash=0F14A473
Discovered new snapshot        height=2000 format=1 hash=C6209AF7
```

### Option

You can start firmachain using Cosmovisor or System Daemon.

* [How to set Cosmovisor](/master/node-and-validators-guide/run-a-full-node/run-a-cosmovisor.md)
* [How to set System Demon](/master/node-and-validators-guide/run-a-full-node/run-a-system-deamon.md)


---

# 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.firmachain.org/master/node-and-validators-guide/run-a-full-node/join-a-firmachain-network/state-sync.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.
