Initia: How to setup/move the node to PebbleDB

Initia  guide  installation  pebbledb  cosmossdk 

The Initia node standard installation guide

Official Initia installation docs could be found here. By default initia node uses the Goleveldb.

Alternative Data Base Storage (PebbleDB)

Why PebbleDB

According to this article pebbledb has a few pros over classic goleveldb, such as:

  • Lower disk usage
  • faster block synchronization rate
  • Less duration for RPC API requests

For more detailed information we recommend you to visit original repo.

Initia is the "fast" blockchain with 2-3s block time. Which means a high load on the disks and longer synchronization time. Besides that, Initia implements latest cometbft and cometbft-db, which already has a built-in implementation of pebbledb (tendermint-db hasn't). That makes easier to maintain the node.

With all this in mind, usage of pebbledb seems to be a reasonable choice to run the Initia node.

Full installation guide for Pebbledb

Dependencies

cd $HOME
ver="1.22.3"
wget "https://golang.org/dl/go$ver.linux-amd64.tar.gz"
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf "go$ver.linux-amd64.tar.gz"
rm "go$ver.linux-amd64.tar.gz"
echo "export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin" >> $HOME/.bash_profile
source $HOME/.bash_profile
go version

Build with Pebbledb

find out the current node version. At this moment the latest version is:

vers="v0.2.23-stage-2" 

Clone Initia repo

git clone https://github.com/initia-labs/initia.git
cd $HOME/initia;
git pull;
git fetch;
git reset --hard;

Select and check branch

git checkout ${vers}
git log -1 --pretty=oneline ;
>2f01bedf12e0fa2be0a21a6f183aadf6ac0cddb7 (HEAD, tag: v0.2.23-stage-2, origin/initiation-stage-2) update swagger

Replace cometbft-db

go mod edit -replace github.com/cometbft/cometbft-db=github.com/cometbft/cometbft-db@v0.12.0
go mod tidy

Binary installation

go install -ldflags "-w -s -X github.com/cosmos/cosmos-sdk/types.DBBackend=pebbledb \
 -X github.com/cosmos/cosmos-sdk/version.Version=${vers}-pebble \
 -X github.com/cosmos/cosmos-sdk/version.Commit=$(git log -1 --format='%H') \
 -X github.com/cosmos/cosmos-sdk/version.ServerName=initiad \
 -X github.com/cosmos/cosmos-sdk/version.ClientName=initiad \
 -X github.com/cosmos/cosmos-sdk/version.Name=initia \
 -X github.com/cosmos/cosmos-sdk/version.AppName=initia" -tags pebbledb ./...

Set or find out current binary path

bin_path=$(which initiad) && echo ${bin_path}
# example of the output
>~/go/bin/initiad

# OR
bin_path=$HOME/go/bin/

Init node

INITIA_HOME="$HOME/.initia"
echo "export INITIA_HOME=${INITIA_HOME}" >> $HOME/.bash_profile
source $HOME/.bash_profile

initiad init node --chain-id initiation-1 --home $INITIA_HOME


# genesis
wget -O genesis.json https://snapshots.polkachu.com/testnet-genesis/initia/genesis.json --inet4-only;
mv genesis.json $INITIA_HOME/config/

initiad cometbft unsafe-reset-all --home $INITIA_HOME

Config

initiad config set client chain-id ${INIT_CHAIN};

# seeds and peers
seeds="ade4d8bc8cbe014af6ebdf3cb7b1e9ad36f412c0@testnet-seeds.polkachu.com:25756,86bd5cb6e762f673f1706e5889e039d5406b4b90@seed.initia.testnet.node75.org:20456"
sed -i "s/^seeds *=.*/seeds = \"$seeds\"/" $INITIA_HOME/config/config.toml

peers=""
sed -i "s/^persistent_peers *=.*/persistent_peers = \"$peers\"/" $INITIA_HOME/config/config.toml

# min-gas
min_gas_price="0.002uinit,0.002move\/944f8dd8dc49f96c25fea9849f16436dcfa6d564eec802f3ef7f8b3ea85368ff"
sed -i "s/^minimum-gas-prices *=.*/minimum-gas-prices = \"$min_gas_price\"/" $INITIA_HOME/config/app.toml

# prunning application state
pruning="custom"
pruning_keep_recent="137"
pruning_interval="27"

sed -i "s/^pruning *=.*/pruning = \"$pruning\"/" $INITIA_HOME/config/app.toml
sed -i "s/^pruning-keep-recent *=.*/pruning-keep-recent = \"$pruning_keep_recent\"/" $INITIA_HOME/config/app.toml
sed -i "s/^pruning-interval *=.*/pruning-interval = \"$pruning_interval\"/" $INITIA_HOME/config/app.toml

blocks=30000;
sed -i -e "s/^min-retain-blocks *=.*/min-retain-blocks = $blocks/" ${INITIA_HOME}/config/app.toml;


# snapshots
sed -i 's/snapshot-interval *=.*/snapshot-interval = 0/' $INITIA_HOME/config/app.toml

# set pebbledb
db_backend="pebbledb"
sed -i "s/^db_backend *=.*/db_backend = \"$db_backend\"/" $INITIA_HOME/config/config.toml
sed -i "s/^app-db-backend *=.*/app-db-backend = \"$db_backend\"/" $INITIA_HOME/config/app.toml

chunks=1;
sed -i.bak -e "s/^chunk_fetchers *=.*/chunk_fetchers = \"${chunks}\"/" ${INITIA_HOME}/config/config.toml;

# set up new "Consensus Options"
timeout_propose_new="3s";
timeout_propose_delta_new="500ms";
timeout_prevote_new="1s";
timeout_prevote_delta_new="500ms";
timeout_precommit_new="1s";
timeout_precommit_delta_new="500ms";
timeout_commit_new="1s";
client_timeout_new="300ms";

sed -i "s/^timeout_propose *=.*/timeout_propose = \"$timeout_propose_new\"/" $INITIA_HOME/config/config.toml;
sed -i "s/^timeout_propose_delta *=.*/timeout_propose_delta = \"$timeout_propose_delta_new\"/" $INITIA_HOME/config/config.toml;
sed -i "s/^timeout_prevote *=.*/timeout_prevote = \"$timeout_prevote_new\"/" $INITIA_HOME/config/config.toml;
sed -i "s/^timeout_prevote_delta *=.*/timeout_prevote_delta = \"$timeout_prevote_delta_new\"/" $INITIA_HOME/config/config.toml;
sed -i "s/^timeout_precommit *=.*/timeout_precommit = \"$timeout_precommit_new\"/" $INITIA_HOME/config/config.toml;
sed -i "s/^timeout_precommit_delta *=.*/timeout_precommit_delta = \"$timeout_precommit_delta_new\"/" $INITIA_HOME/config/config.toml;
sed -i "s/^timeout_commit *=.*/timeout_commit = \"$timeout_commit_new\"/" $INITIA_HOME/config/config.toml;
sed -i "s/^client_timeout *=.*/client_timeout = \"$client_timeout_new\"/" $INITIA_HOME/config/app.toml;

# change "module-cache-capacity"
sed -i "s/^module-cache-capacity *=.*/module-cache-capacity = \"512MiB\"/" $INITIA_HOME/config/app.toml;

Systemd service setup

tee $HOME/initiad.service > /dev/null <<EOF
[Unit]
Description=Initia node Service
After=network.target
[Service]
Type=simple
User=$USER
ExecStart=$(which initiad) start --home ${INITIA_HOME}
Restart=on-failure
RestartSec=10
LimitNOFILE=65535
[Install]
WantedBy=multi-user.target
EOF

sudo ln -s $HOME/initiad.service /etc/systemd/system
sudo systemctl daemon-reload
sudo systemctl enable initiad

Start from state-sync

## IMPORTANT NOTE
# Сurrent snapshot contain more than 1000 chunks. Full synchronization time is about 10h, but db size will be about 30Gb
# Our node creates state-sync snapshot every 7-8h.

SNAP_RPC="https://rpc.initia.testnet.node75.org:443"

LATEST_HEIGHT=$(curl -s $SNAP_RPC/block | jq -r .result.block.header.height); \
BLOCK_HEIGHT=$((LATEST_HEIGHT - 20000)); \
TRUST_HASH=$(curl -s "$SNAP_RPC/block?height=$BLOCK_HEIGHT" | jq -r .result.block_id.hash)

echo $LATEST_HEIGHT $BLOCK_HEIGHT $TRUST_HASH

# save current persistent_peers:
current_peers=$(cat "$HOME/.initia/config/config.toml" | grep "persistent_peers =" | cut -d "=" -f2 | sed 's/\"//g');
echo $current_peers

# State-sync snapshot peer
peer="e63365e09d02dcf13a8f1e8de563bbcd5848a4fc@peer.initia.testnet.node75.org:48816"

# add peers into config
sed -i.bak -e "s/^persistent_peers *=.*/persistent_peers = \"$peer,$current_peers\"/" $HOME/.initia/config/config.toml;
cat "$HOME/.initia/config/config.toml" | grep persistent_peers;

# stop service
sudo systemctl stop initiad

# delete old db
initiad cometbft unsafe-reset-all --home $INITIA_HOME --keep-addr-book

sed -i -E "s|^(enable[[:space:]]+=[[:space:]]+).*$|\1true| ; \
s|^(rpc_servers[[:space:]]+=[[:space:]]+).*$|\1\"$SNAP_RPC,$SNAP_RPC\"| ; \
s|^(trust_height[[:space:]]+=[[:space:]]+).*$|\1$BLOCK_HEIGHT| ; \
s|^(trust_hash[[:space:]]+=[[:space:]]+).*$|\1\"$TRUST_HASH\"|" $INITIA_HOME/config/config.toml

sudo systemctl restart initiad && journalctl -u initiad -f -o cat

# to check snapshot starting progress use:
journalctl -u initiad -f -o cat -n 10000 | grep snapshot

IMPORTANT NOTES !!!

If the node has started correct with pebbledb then extension of the database should be *.sst you can check it in data folder:

~/.initia/data/blockstore.db/xxxx.sst

Besides we recommend to perform restart of the initiad service once in a two days. It will significantly prune application.db folder:

sudo systemctl restart initiad

You could find the link to the Initia' full (not the State-Sync) Pebbledb snapshots here.

Snapshot is taken on daily basis at 7.00 UTC !!!

Start the node using full pebbledb snapshot


name="initia_testnet_snap"

# backup state
cp "$HOME/.initia/data/priv_validator_state.json" $HOME

# check backup
cat $HOME/priv_validator_state.json

# Example: URL to the Pebbledb Snapshot:
#URL="https://services.node75.org/snapshots/initia-testnet/initiation-1_pebble_1334248_2024-06-17.tar.lz4" 

#to use our snapshot:
snap_array=($(curl -s https://services.node75.org/snapshots/initia-testnet | egrep -o ">initiation-1_pebble*.*lz4" | tr -d ">" | sort -gr));
snap_name=${snap_array[0]};
URL="https://services.node75.org/snapshots/initia-testnet/${snap_name}" 

# download the pebbledb snapshot
wget -O $HOME/${name}.tar.lz4 ${URL} --inet4-only

# stop the initiad service
sudo systemctl stop initiad; sudo systemctl status initiad

# clear the current DB
initiad comet unsafe-reset-all --home $HOME/.initia --keep-addr-book


# unpuck the snapshot
home_dir="$HOME/.initia"  && echo ${home_dir} 
lz4 -c -d $HOME/${name}.tar.lz4  | tar -x -C ${home_dir}

# if unpacking was successful, then delete the snapshot (optional)
rm -v $HOME/${name}.tar.lz4


# get fresh addrbook
wget -O $HOME/addrbook.json https://snapshots.polkachu.com/testnet-addrbook/initia/addrbook.json --inet4-only
mv $HOME/addrbook.json $HOME/.initia/config/

# restore validator' state
cp $HOME/priv_validator_state.json "$HOME/.initia/data/priv_validator_state.json"

# check state
cat $HOME/.initia/data/priv_validator_state.json

# restart the service
sudo systemctl restart initiad; journalctl -u initiad -f -o cat

Best regards and Good luck with your initia node installation!❤️👍

Pro-Nodes75 team📡🗻