0G (Zero Gravity) - Storage Node

Resources

Prerequisite

0G Storage and DA services interact with on-chain contracts for blob root confirmation and PoRA mining.

This step is performed after your validator has been installed and created.

For official deployed contract addresses, visit this page

Hardware requirements

4 cores

16 GB

1 TB NVME

500 MBps

Linux (Ubuntu 20.04 x64)

Installation 💾

Install dependencies

sudo apt update && sudo apt upgrade -y
sudo apt install curl git wget htop tmux build-essential jq make lz4 gcc unzip -y

Install Rust

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source $HOME/.cargo/env

cargo --version
rustc --version

Install GO 1.22.2

sudo rm -rf /usr/local/go && \
curl -L https://go.dev/dl/go1.22.2.linux-amd64.tar.gz | sudo tar -xzf - -C /usr/local && \
echo 'export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin' >> $HOME/.bash_profile && \
source .bash_profile && \
go version

Build binary from source

git clone -b v0.4.5 https://github.com/0glabs/0g-storage-node.git
cd $HOME/0g-storage-node
git stash
git fetch --all --tags
git checkout 27979c2
git submodule update --init
cargo build --release

cp $HOME/0g-storage-node/run/config-testnet-turbo.toml $HOME/0g-storage-node/run/config.toml

check zgs version

$HOME/0g-storage-node/target/release/zgs_node --version

Set vars (For SSD disks). you found more from official docs

export ZGS_LOG_DIR="$HOME/0g-storage-node/run/log"
export ZGS_LOG_CONFIG_FILE="$HOME/0g-storage-node/run/log_config"
export LOG_CONTRACT_ADDRESS="0xbD2C3F0E65eDF5582141C35969d66e34629cC768"
export MINE_CONTRACT="0x6815F41019255e00D6F34aAB8397a6Af5b6D806f"
export REWARD_CONTRACT="0x51998C4d486F406a788B766d93510980ae1f9360"
export ZGS_LOG_SYNC_BLOCK=595059

Extract Ethereum private key from your validator (we will need this key in the next step)

0gchaind keys unsafe-export-eth-key $WALLET_NAME

After entering the next command, a field will appear in which you should enter the key you received in the previous step. Note that the text you enter will not be displayed.

read -sp "Enter your extracted private key: " PRIVATE_KEY && echo

Set the miner_key in the config.toml file

sed -i 's|^miner_key = ""|miner_key = "'"$PRIVATE_KEY"'"|' $HOME/0g-storage-node/run/config.toml

Set var the Storage Node IP address

ZGS_IP=$(wget -qO- eth0.me)

Edit the storage node config

sed -i '
s|# network_dir = "network"|network_dir = "network"|g
s|# network_enr_tcp_port = 1234|network_enr_tcp_port = 1234|g
s|# network_enr_udp_port = 1234|network_enr_udp_port = 1234|g
s|# network_libp2p_port = 1234|network_libp2p_port = 1234|g
s|# network_discovery_port = 1234|network_discovery_port = 1234|g
s|# rpc_enabled = true|rpc_enabled = true|g
s|# db_dir = "db"|db_dir = "db"|g
s|# log_config_file = "log_config"|log_config_file = "log_config"|g
s|# log_directory = "log"|log_directory = "log"|g
s|# network_enr_address = ""|network_enr_address = "'"$ZGS_IP"'"|g
' $HOME/0g-storage-node/run/config.toml
sed -i '
s|^log_sync_start_block_number = .*|log_sync_start_block_number = '"$ZGS_LOG_SYNC_BLOCK"'|g
s|^log_config_file = .*|log_config_file = "'"$ZGS_LOG_CONFIG_FILE"'"|g
s|^log_directory = .*|log_directory = "'"$ZGS_LOG_DIR"'"|g
s|^mine_contract_address = .*|mine_contract_address = "'"$MINE_CONTRACT"'"|g
s|^log_contract_address = .*|log_contract_address = "'"$LOG_CONTRACT_ADDRESS"'"|g
s|^reward_contract_address = .*|reward_contract_address = "'"$REWARD_CONTRACT"'"|g
' $HOME/0g-storage-node/run/config.toml

Set blockchain_rpc_endpoint from your validator's (json-rpc endpoint). To connect your storage node to the validator.

You can use the json-rpc of your validator (which you can see in the $HOME/.0gchain/config/app.toml file) or use any available from the community.

BLOCKCHAIN_RPC_ENDPOINT="https://0grpc0x.nodecattel.xyz/"
sed -i 's|^blockchain_rpc_endpoint = ".*"|blockchain_rpc_endpoint = "'"$BLOCKCHAIN_RPC_ENDPOINT"'"|' $HOME/0g-storage-node/run/config.toml
echo "export BLOCKCHAIN_RPC_ENDPOINT=\"$BLOCKCHAIN_RPC_ENDPOINT\"" >> ~/.bash_profile

Create a service file and start

sudo tee /etc/systemd/system/zgs.service > /dev/null <<EOF
[Unit]
Description=ZGS Node
After=network.target

[Service]
User=$USER
WorkingDirectory=$HOME/0g-storage-node/run
ExecStart=$HOME/0g-storage-node/target/release/zgs_node --config $HOME/0g-storage-node/run/config.toml
Restart=on-failure
RestartSec=10
LimitNOFILE=65535

[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload && \
sudo systemctl enable zgs && \
sudo systemctl restart zgs

If the synchronization process does not start, comment out the line miner_key and restart the node.

Useful commands ⚙️

Stop the storage node

sudo systemctl stop zgs

Check list of logs

ls ~/0g-storage-node/run/log/

Check logs on a specific date. For example:

tail -f ~/0g-storage-node/run/log/zgs.log.2024-06-04

Check the latest logs file

tail -f ~/0g-storage-node/run/log/zgs.log.$(TZ=UTC date +%Y-%m-%d)

Check sync status

curl -X POST http://localhost:5678 -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"zgs_getStatus","params":[],"id":1}'  | jq

Delete node 🗑️

sudo systemctl stop zgs && sudo systemctl disable zgs
sudo rm -rf /etc/systemd/system/zgs.service
sudo rm $(which zgs)
sudo rm -rf $HOME/0g-storage-node

Last updated