0G 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 v1.0.0 https://github.com/0glabs/0g-storage-node.git
cd $HOME/0g-storage-node
git stash
git fetch --all --tags
git checkout 347cd3e
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. 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="0xbD75117F80b4E22698D0Cd7612d92BDb8eaff628"
export MINE_CONTRACT="0x3A0d1d67497Ad770d6f72e7f4B8F0BAbaa2A649C"
export REWARD_CONTRACT="0xd3D4D91125D76112AE256327410Dd0414Ee08Cb4"
export ZGS_LOG_SYNC_BLOCK=326165
Set Ethereum private key. Your private key (64 chars, no '0x' prefix, include leading zeros): Your private key (without the 0x
prefix) if you want to participate in PoRA mining and earn rewards.
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
Update boot nodes addresses
sed -i 's|^network_boot_nodes = .*|network_boot_nodes = ["/ip4/47.251.117.133/udp/1234/p2p/16Uiu2HAmTVDGNhkHD98zDnJxQWu3i1FL1aFYeh9wiQTNu4pDCgps","/ip4/47.76.61.226/udp/1234/p2p/16Uiu2HAm2k6ua2mGgvZ8rTMV8GhpW71aVzkQWy7D37TTDuLCpgmX"]|g' ~/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.
Official 0g rpc endpoint:
BLOCKCHAIN_RPC_ENDPOINT="https://evmrpc-testnet.0g.ai"
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
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
Start the node
sudo systemctl daemon-reload && sudo systemctl enable zgs && sudo systemctl restart zgs
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
while true; do
response=$(curl -s -X POST http://localhost:5678 -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"zgs_getStatus","params":[],"id":1}')
logSyncHeight=$(echo $response | jq '.result.logSyncHeight')
connectedPeers=$(echo $response | jq '.result.connectedPeers')
echo -e "logSyncHeight: \033[32m$logSyncHeight\033[0m, connectedPeers: \033[34m$connectedPeers\033[0m"
sleep 5;
done
Check version
cd $HOME/0g-storage-node && git log --decorate=short --oneline | grep "tag: v" | head -n 1 && git log -1 --pretty=oneline
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