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 KV |
---|---|
Memory | 32 GB RAM |
CPU | 8 cores |
Disk | Size matches the KV streams it maintains |
Bandwidth | - |
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 the source code
Section titled “4. Download the source code”rm -rf 0g-storage-kvgit clone -b v1.4.0 https://github.com/0glabs/0g-storage-kv.git
5. Build the source code
Section titled “5. Build the source code”cd 0g-storage-kvgit submodule update --init --recursivecargo build --release
6. Copy the config_example.toml to config.toml and update the parameters
Section titled “6. Copy the config_example.toml to config.toml and update the parameters”cp ~/0g-storage-kv/run/config_example.toml ~/0g-storage-kv/run/config.tomlnano ~/0g-storage-kv/run/config.toml
Paste this content:
########################################################################## Key-Value Stream Options ##########################################################################
# Streams to monitor.stream_ids = ["000000000000000000000000000000000000000000000000000000000000f2bd", "000000000000000000000000000000000000000000000000000000000000f009", "0000000000000000000000000000000000000000000000000000000000016879", "0000000000000000000000000000000000000000000000000000000000002e3d"]
########################################################################## DB Config Options ##########################################################################
# Directory to store data.db_dir = "db"# Directory to store KV Metadata.kv_db_dir = "kv.DB"
########################################################################## Log Sync Config Options ##########################################################################
blockchain_rpc_endpoint = "BLOCKCHAIN_RPC_ENDPOINT" #rpc endpoint, see testnet informationlog_contract_address = "LOG_CONTRACT_ADDRESS" #flow contract address, see testnet information# log_sync_start_block_number should be earlier than the block number of the first transaction that writes to the stream being monitored.log_sync_start_block_number = 0
########################################################################## RPC Config Options ##########################################################################
# Whether to provide RPC service.rpc_enabled = true
# HTTP server address to bind for public RPC.rpc_listen_address = "0.0.0.0:6789"
# Zerog storage nodes to download data from.zgs_node_urls = "http://127.0.0.1:5678,http://127.0.0.1:5679"
########################################################################## Misc Config Options ##########################################################################
log_config_file = "log_config"
7. Creat service
Section titled “7. Creat service”sudo tee /etc/systemd/system/0gkv.service > /dev/null <<EOF[Unit]Description=0G-KV NodeAfter=network.target
[Service]User=rootWorkingDirectory=/root/0g-storage-kv/runExecStart=/root/0g-storage-kv/target/release/zgs_kv --config /root/0g-storage-kv/run/config.tomlRestart=alwaysRestartSec=10LimitNOFILE=65535StandardOutput=journalStandardError=journalSyslogIdentifier=zgs_kv
[Install]WantedBy=multi-user.targetEOF
8. Start service
Section titled “8. Start service”sudo systemctl daemon-reload && \sudo systemctl enable 0gkv && \sudo systemctl start 0gkv && \sudo systemctl status 0gkv
Check log:
sudo journalctl -u 0gkv -f -o cat
Stop & Remove node
Section titled “Stop & Remove node”sudo systemctl stop 0gkv
sudo systemctl disable 0gkvsudo rm /etc/systemd/system/0gkv.servicerm -rf $HOME/0g-storage-kv