State sync
‘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.
| Network | chain-id | genesis.json | seeds | github |
|---|---|---|---|---|
| Mainnet | colosseum-1 | Link | Link | Link |
| Testnet | imperium-4 | Link | Link | Link |
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.tomlSet 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\"/" ~/.firmachain/config/config.tomlbash
# Testnet
sed -i.bak -e "s/^seeds *=.*/seeds = \"583717da6ee75478aea4e6717aff03e0faab4370@testnet-seed1.firmachain.dev:26656,d1619ff4762037484017e3c48c7c40c1f94bca47@testnet-seed2.firmachain.dev:26656\"/" ~/.firmachain/config/config.tomlDownload 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.jsonbash
# Testnet genesis.json
wget https://raw.githubusercontent.com/FirmaChain/testnet/master/imperium-4/genesis.json -O ~/.firmachain/config/genesis.jsonSet trust datas
If you do not have a jq package, please install the jq package.
sudo apt install jq -yBy 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"
LATEST_HEIGHT=$(curl -fsS "$SNAP_RPC/status" | jq -er '.result.sync_info.latest_block_height | tonumber') &&
BLOCK_HEIGHT=$((LATEST_HEIGHT - 10)) &&
[ "$BLOCK_HEIGHT" -gt 0 ] &&
TRUST_HASH=$(curl -fsS "$SNAP_RPC/block?height=$BLOCK_HEIGHT" | jq -er '.result.block_id.hash | select(length > 0)')
echo "$BLOCK_HEIGHT $TRUST_HASH"
# Values change with the chain height. Use the values retrieved in this shell below.bash
# Testnet
SNAP_RPC="https://testnet-rpc.firmachain.dev"
LATEST_HEIGHT=$(curl -fsS "$SNAP_RPC/status" | jq -er '.result.sync_info.latest_block_height | tonumber') &&
BLOCK_HEIGHT=$((LATEST_HEIGHT - 10)) &&
[ "$BLOCK_HEIGHT" -gt 0 ] &&
TRUST_HASH=$(curl -fsS "$SNAP_RPC/block?height=$BLOCK_HEIGHT" | jq -er '.result.block_id.hash | select(length > 0)')
echo "$BLOCK_HEIGHT $TRUST_HASH"
# Values change with the chain height. Use the values retrieved in this shell below.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_HASHPlease set the chain to allow ‘State Sync’ feature and put in the retrieved data in the config.toml file. Run the configuration commands in the same shell where you retrieved BLOCK_HEIGHT and TRUST_HASH.
bash
# Mainnet
CONFIG_FILE="$HOME/.firmachain/config/config.toml"
sed -i.bak \
-e '/^\[statesync\]/,/^\[/ s|^enable *=.*|enable = true|' \
-e '/^\[statesync\]/,/^\[/ s|^rpc_servers *=.*|rpc_servers = "mainnet-seed1.firmachain.dev:26657,mainnet-seed2.firmachain.dev:26657"|' \
-e "/^\[statesync\]/,/^\[/ s|^trust_height *=.*|trust_height = ${BLOCK_HEIGHT:?Retrieve the trust height first}|" \
-e "/^\[statesync\]/,/^\[/ s|^trust_hash *=.*|trust_hash = \"${TRUST_HASH:?Retrieve the trust hash first}\"|" \
-e '/^\[statesync\]/,/^\[/ s|^trust_period *=.*|trust_period = "336h0m0s"|' \
"$CONFIG_FILE"For Testnet, both entries below use the same foundation-operated public RPC endpoint. They are not two independent RPC providers. Run this in the same shell where you retrieved BLOCK_HEIGHT and TRUST_HASH.
bash
# Testnet
CONFIG_FILE="$HOME/.firmachain/config/config.toml"
sed -i.bak \
-e '/^\[statesync\]/,/^\[/ s|^enable *=.*|enable = true|' \
-e '/^\[statesync\]/,/^\[/ s|^rpc_servers *=.*|rpc_servers = "https://testnet-rpc.firmachain.dev,https://testnet-rpc.firmachain.dev"|' \
-e "/^\[statesync\]/,/^\[/ s|^trust_height *=.*|trust_height = ${BLOCK_HEIGHT:?Retrieve the trust height first}|" \
-e "/^\[statesync\]/,/^\[/ s|^trust_hash *=.*|trust_hash = \"${TRUST_HASH:?Retrieve the trust hash first}\"|" \
-e '/^\[statesync\]/,/^\[/ s|^trust_period *=.*|trust_period = "336h0m0s"|' \
"$CONFIG_FILE"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=C6209AF7Option
You can start firmachain using a System Daemon.
