ZeroGravity: validator/consensus node setup guide
Official ZeroGravity installation docs could be found here
network | chain_id | node version | commit hash |
---|---|---|---|
testnet | zgtendermint_16600-2 | v0.4.0 | 840deea660500f3948300ea3e9a1cba878ed682b |
Hardware Requirements
- Memory: 64 GB
- CPU: 8 cores
- Disk: 1 TB NVME SSD
- Bandwidth: 100 MBps for Download / Upload
We use OS Ubuntu, version 22.04 and higher
Environment preparation
Go installation
Download the Go installer
wget https://go.dev/dl/go1.22.6.linux-amd64.tar.gz
Extract the archive
sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.22.6.linux-amd64.tar.gz
Add /usr/local/go/bin to the PATH environment variable by adding the following line to your profile
echo export PATH='$PATH':/usr/local/go/bin >> $HOME/.bash_profile
source $HOME/.bash_profile
Build binary from sources
Create directory for used binary add it to PATH
mkdir $HOME/bin
echo export PATH='$PATH':$HOME/bin >> $HOME/.bash_profile
source $HOME/.bash_profile
Clone OG repo and build
cd ~
git clone https://github.com/0glabs/0g-chain.git
cd 0g-chain
git checkout v0.4.0
make build
Copy binary to our dir bin
cp $HOME/0g-chain/out/linux/0gchaind $HOME/bin
Check 0gchaind version, expected: v0.4.0
0gchaind version
Chain init and connection
set some variables
NODE_NAME=<Your_node_name>
CHAIN_ID=zgtendermint_16600-2
Initialize node configuration, this command will create the .0gchain directory with some config files
0gchaind init $NODE_NAME --chain-id $CHAIN_ID
Download genesis file
rm $HOME/.0gchain/config/genesis.json
wget -P $HOME/.0gchain/config https://github.com/0glabs/0g-chain/releases/download/v0.2.3/genesis.json
Check node ports
If other services that use network connections are running on the server you are using, you should check for port conflicts. The ports used are set in the configuration files: $HOME/.0gchain/config/config.toml and $HOME/.0gchain/config/app.toml
When using a firewall, it is necessary to open access to the p2p port (by default 26656 in config.toml)
sudo ufw allow 26656
Connection to the network
We offer two options for quick synchronization: stata-sync or snapshot.
Use State-Sync
Set variables
COS_HOME_PATH="$HOME/.0gchain"
SNAP_RPC=https://rpc.0g.testnet.node75.org:443
SEEDS="86bd5cb6e762f673f1706e5889e039d5406b4b90@seed.0g.testnet.node75.org:20256"
PEERS="50024d0572a5f102493987a0401c5221f8bf9442@65.108.141.228:26956,50024d0572a5f102493987a0401c5221f8bf9442@65.108.141.228:26956"
Apply seeds and peers configuration to config.toml
sed -i -e "s/^seeds *=.*/seeds = \"$SEEDS\"/" ${COS_HOME_PATH}/config/config.toml
sed -i -e "s/^persistent_peers *=.*/persistent_peers = \"$PEERS\"/" ${COS_HOME_PATH}/config/config.toml
Get chain data from rpc
LATEST_HEIGHT=$(curl -s $SNAP_RPC/block | jq -r .result.block.header.height); \
BLOCK_HEIGHT=$((LATEST_HEIGHT - 2000)); \
TRUST_HASH=$(curl -s "$SNAP_RPC/block?height=$BLOCK_HEIGHT" | jq -r .result.block_id.hash)
echo $LATEST_HEIGHT $BLOCK_HEIGHT $TRUST_HASH
Update statesync configuration
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\"| ; \
s|^(seeds[[:space:]]+=[[:space:]]+).*$|\1\"\"|" ${COS_HOME_PATH}/config/config.toml
Download and unpack wasm
curl https://snap.0g.testnet.node75.org/zgtendermint_16600-2_wasm.tar.lz4 | lz4 -dc - | tar -xf - -C $HOME/.0gchain
Use Snapshots
Select the appropriate snapshot file here.
For example https://snap.0g.testnet.node75.org/zgtendermint_16600-2_960216_2024-09-06.tar.lz4
Delete existing database and load snapshot (with validtaor state backup)
cp $HOME/.0gchain/data/priv_validator_state.json $HOME/.0gchain/priv_validator_state.json
rm -rf $HOME/.0gchain/data
curl https://snap.0g.testnet.node75.org/zgtendermint_16600-2_960216_2024-09-06.tar.lz4 | lz4 -dc - | tar -xf - -C $HOME/.0gchain
mv $HOME/.0gchain/priv_validator_state.json $HOME/.0gchain/data/priv_validator_state.json
Run node
You can run node (for test purpose) in terminal with command:
0gchaind start --log_output_console
Run node as service
Create service file:
tee $HOME/zg_chain.service > /dev/null <<EOF
[Unit]
Description=Zero Gravity Validator Node
After=network.target
[Service]
User=$USER
Type=simple
WorkingDirectory=$HOME/.0gchain
ExecStart=$(which 0gchaind) start --home $HOME/.0gchain --log_output_console
Restart=always
RestartSec=10
LimitNOFILE=65535
[Install]
WantedBy=multi-user.target
EOF
Init daemon with simlink
sudo ln -s $HOME/zg_chain.service /etc/systemd/system
sudo systemctl daemon-reload
sudo systemctl enable zg_chain
Start daemon
sudo systemctl start zg_chain
Check daemon status:
sudo systemctl status zg_chain
Check node logs:
journalctl -u zg_chain -o cat -f
Check sync status
Show node status (change rpc port if you use custom value):
RPC_PORT=26657
curl -s localhost:${RPC_PORT}/status | jq .
check latest_block_time
and catching_up
catching_up
should be false
latest_block_time
should be as close as possible to the current UTC time
Generate keys
Generate new keys for validator (key name will be validator_key)
KEY_NAME=validator_key
0gchaind keys add $KEY_NAME --eth
Enter keyring password (and keep it secure)
The public key address (bech32 format) and mnemonics will be returned. The mnemonics must be kept secure!
To see the key address in EVM format. This public key was used for EVM transactions, chain faucet take this address format
echo "0x$(0gchaind debug addr $(0gchaind keys show $KEY_NAME -a) | grep hex | awk '{print $3}')"
For export private key, use command (this may be needed in the future to configure other types of nodes):
0gchaind keys unsafe-export-eth-key $KEY_NAME
⚠️ Always keep passwords, mnemonics, private keys in a safe place inaccessible to others. The security of your funds is determined by the security of your keys
Create validator
Using the address in evm format, get test tokens from https://faucet.0g.ai
Set variables:
MONIKER=<your-validator-moniker>
CHAIN_ID=zgtendermint_16600-2
WALLET=validator_key
PORT_RPC=26657
Creation command:
0gchaind tx staking create-validator \
--amount=1000000ua0gi \
--pubkey=$(0gchaind tendermint show-validator) \
--moniker=$MONIKER \
--chain-id=$CHAIN_ID \
--commission-rate="0.10" \
--commission-max-rate="0.20" \
--commission-max-change-rate="0.01" \
--min-self-delegation="1" \
--from=$WALLET \
--gas=auto \
--gas-adjustment=1.4 \
--node tcp://localhost:$PORT_RPC
this command has more options, see:
0gchaind tx staking create-validator help
check validator info:
VALOPER=<your-valiator-key>
0gchaind query staking validator $VALOPER --node "tcp://localhost:${PORT_RPC}"
Best regards and Good luck with your node installation!❤️👍
Pro-Nodes75 team📡🗻