☑️0G Storage Node

Recommended Hardware: 4 Cores, 16GB RAM, 1TB of storage (NVME)

System updates, installation of required dependencies

sudo apt-get update
sudo apt-get install clang cmake build-essential pkg-config libssl-dev
sudo apt install cargo

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

Install rust

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

When prompted choice of 1,2 and 3 just hit enter to continue

Build zgs_node binary from source with rust

cd $HOME
git clone https://github.com/0glabs/0g-storage-node.git
cd $HOME/0g-storage-node
git tag -d v0.4.1
git checkout 302aa88e2fde448c7f80e42ad8d8f1fce1cafc2c
git submodule update --init
cargo build --release

copy config.toml

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

edit config.toml

nano $HOME/0g-storage-node/run/config.toml

Set config.toml

log_contract_address : 0xbD2C3F0E65eDF5582141C35969d66e34629cC768
mine_contract_address : 0x6815F41019255e00D6F34aAB8397a6Af5b6D806f
reward_contract_address : 0x51998C4d486F406a788B766d93510980ae1f9360
Deployed Block Number: 595059
confirmation_block_count = 6
network_boot_nodes = ["/ip4/54.219.26.22/udp/1234/p2p/16Uiu2HAmTVDGNhkHD98zDnJxQWu3i1FL1aFYeh9wiQTNu4pDCgps","/ip4/52.52.127.117/udp/1234/p2p/16Uiu2HAkzRjxK2gorngB1Xq84qDrT4hSVznYDHj6BkbaE4SGx9oS","/ip4/18.162.65.205/udp/1234/p2p/16Uiu2HAm2k6ua2mGgvZ8rTMV8GhpW71aVzkQWy7D37TTDuLCpgmX"]

Create zgs service (storage node) for your node to run in the background

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 Storage node

sudo systemctl daemon-reload && \
sudo systemctl enable zgs && \
sudo systemctl restart zgs

Show logs by date

  • full logs command

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

tail -f ~/0g-storage-node/run/log/zgs.log.$(TZ=UTC date +%Y-%m-%d) | grep tx_seq:
  • minimized-logs command

tail -f ~/0g-storage-node/run/log/zgs.log.$(TZ=UTC date +%Y-%m-%d) | grep -v "discv5\|network\|connect\|16U\|nounce"
  • check your storage node 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

Test Stoarge Node with storage CLI

Build Storage CLI with source code

git clone -b v0.5.1 https://github.com/0glabs/0g-storage-client.git
cd $HOME/0g-storage-client
git stash
git fetch --all --tags
git checkout e283cdbfef2f3e5c94f97ef4c1815b464851f399 
git submodule update --init
go build

Create upload.sh

nano $HOME/upload.sh
# Generate the file
  size=$(shuf -i 10240-51200 -n 1)
  filename=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 10).md
  /root/0g-storage-client/./0g-storage-client gen --size $size --file ${filename}

# Upload the file
  /root/0g-storage-client/./0g-storage-client upload \
  --url http://127.0.0.1:8545 \
  --contract "" \
  --key "" \
  --node http://127.0.0.1:5678 \
  --file ./${filename} \
  --tags 0x

# Remove the file
  rm ./${filename}
done

Create upload service for your node to run in the background

sudo tee /etc/systemd/system/upload.service > /dev/null <<EOF
[Unit]
Description=station track service
After=network-online.target
[Service]
User=root
WorkingDirectory=/root/
ExecStart=sh ./upload.sh
Restart=always
RestartSec=3
LimitNOFILE=65535
[Install]
WantedBy=multi-user.target
EOF

Start upload

sudo systemctl daemon-reload && \
sudo systemctl enable upload && \
sudo systemctl restart upload

check log

sudo journalctl -u upload -f

If you see this result, the test was successful

Last updated