Storage Node
In the 0G network, storage nodes play a vital role in maintaining the system’s decentralized storage layer. They are responsible for storing and serving data, ensuring data availability and reliability across the network. By running a storage node, you actively contribute to the network and earn rewards for your participation. This guide details the process of running a storage node, including hardware specifications and interaction with on-chain contracts.
Hardware Requirements
Section titled “Hardware Requirements”Component | Storage Node |
---|---|
Memory | 32 GB RAM |
CPU | 8 cores |
Disk | 500GB / 1TB NVMe SSD |
Bandwidth | 100 MBps for Download / Upload |
1. Install Dependencies for Building from Source
Section titled “1. Install Dependencies for Building from Source”sudo apt-get updatesudo apt-get install clang cmake build-essential openssl pkg-config libssl-dev
2. Install Go
Section titled “2. Install Go”cd $HOME && ver="1.22.0" && 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" >> ~/.bash_profile && source ~/.bash_profile && go version
3. Install Rust
Section titled “3. Install Rust”curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
. "$HOME/.cargo/env"
4. Download and Install Binary
Section titled “4. Download and Install Binary”If you want to remove the node and install from scratch:
cd $HOMErm -rf 0g-storage-nodegit clone https://github.com/0glabs/0g-storage-node.gitcd 0g-storage-nodegit checkout v0.8.7git submodule update --init
Build:
cargo build --release
5. Config
Section titled “5. Config”You can download the sample config:
# Peer nodes: A list of peer nodes to help your node join the network. Check inside 0g-storage/run directory for suggested configurations.network_boot_nodes = []
# Contract addresseslog_contract_address = "CONTRACT_ADDRESS" #flow contract address, see testnet informationmine_contract_address = "CONTRACT_ADDRESS" #Address of the smart contract on the host blockchain that manages mining.
# L1 host blockchain RPC endpoint URL. See testnet information page for RPC endpointsblockchain_rpc_endpoint = "RPC_ENDPOINT"
# Start sync block number: The block number from which your node should start synchronizing the log data.log_sync_start_block_number = BLOCK_NUMBER
# 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.miner_key = "YOUR_PRIVATE_KEY"
# Max chunk entries in db (affects storage size): The maximum number of chunk entries (each 256 bytes) to store in the database. This effectively limits the database size.db_max_num_chunks = MAX_CHUNKS
# ENR address: Your node's public IP address, essential for other nodes to discover and connect to you. Currently automatically set by the node.# network_enr_address = ""
6. Set Your Miner Key
Section titled “6. Set Your Miner Key”Define variable:
printf '\033[34mEnter your private key: \033[0m' && read -s PRIVATE_KEY
Set miner_key
:
sed -i 's|^\s*#\?\s*miner_key\s*=.*|miner_key = "'"$PRIVATE_KEY"'"|' $HOME/0g-storage-node/run/config-testnet-turbo.toml && echo -e "\033[32mPrivate key has been successfully added to the config file.\033[0m"
7. Verifying Configuration Changes
Section titled “7. Verifying Configuration Changes”grep -E "^(network_dir|network_enr_address|network_enr_tcp_port|network_enr_udp_port|network_libp2p_port|network_discovery_port|rpc_listen_address|rpc_enabled|db_dir|log_config_file|log_contract_address|mine_contract_address|reward_contract_address|log_sync_start_block_number|blockchain_rpc_endpoint|auto_sync_enabled|find_peer_timeout)" $HOME/0g-storage-node/run/config-testnet-turbo.toml
8. Create systemd Service
Section titled “8. Create systemd Service”sudo tee /etc/systemd/system/zgs.service > /dev/null <<EOF[Unit]Description=ZGS NodeAfter=network.target
[Service]User=$USERWorkingDirectory=$HOME/0g-storage-node/runExecStart=$HOME/0g-storage-node/target/release/zgs_node --config $HOME/0g-storage-node/run/config-testnet-turbo.tomlRestart=on-failureRestartSec=10LimitNOFILE=65535
[Install]WantedBy=multi-user.targetEOF
9. Start Node
Section titled “9. Start Node”sudo systemctl daemon-reload && sudo systemctl enable zgs && sudo systemctl restart zgs && sudo systemctl status zgs
10. Check Log
Section titled “10. Check Log”Full log:
tail -f ~/0g-storage-node/run/log/zgs.log.$(TZ=UTC date +%Y-%m-%d)
tx_seq
log:
tail -f ~/0g-storage-node/run/log/zgs.log.$(TZ=UTC date +%Y-%m-%d) | grep tx_seq
Monitoring 0g-storage-node Logs Without Network and Peer Messages
Section titled “Monitoring 0g-storage-node Logs Without Network and Peer Messages”tail -f ~/0g-storage-node/run/log/zgs.log.$(date +%Y-%m-%d) | grep -v "discv5\|network\|router\|Peer"
logSync
& Peers Through RPC
Section titled “logSync & Peers Through RPC”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
Stop & Delete Node
Section titled “Stop & Delete Node”sudo systemctl stop zgs
sudo systemctl disable zgssudo rm /etc/systemd/system/zgs.servicerm -rf $HOME/0g-storage-node