Polygon Node Setup Instructions

Configure Hetzner AX101 server

Put server into RescueMode from https://robot.hetzner.com/server

  • Click server link then “Rescue”
  • Note down the new password
    • Will need to update bitwarden with new password
  • Go to “Reset” then select “Execute an automatic hardware reset”
    • Now you can access the server with username=root and the password from step b.


Install Ubuntu on machine using Hetzner installimage utility

  • Type installimage in RescueMode CLI then press enter
  • Select Ubuntu then select Ubuntu-2204-jammy-amd64-base.tar.gz
  • From within the config file:
    • Update SWRAIDLEVEL to 0
    • Update HOSTNAME to Polygon-Node
    • Update RAID configs as follows:
      • PART swap swap 8G
      • PART /boot ext3 512M
      • PART / ext4 all
  • Type F10 > select Save changes
  • After install is complete, reboot the device
  • Ssh into the server and verify that available space is greater than 7 terabytes
    • df -h --total



Install prerequisites

apt update && apt upgrade
sudo apt install -y build-essential bsdmainutils aria2 golang dtrx screen clang cmake curl httpie jq nano wget
go install github.com/a8m/envsubst/cmd/envsubst@latest
sudo apt install docker.io docker-compose



Download Erigon snapshot

screen -S erigon
ERIGON_HOME=$HOME/.local/share/erigon/datadir
mkdir -p ${ERIGON_HOME}
SNAPSHOT_URL=https://matic-blockchain-snapshots.s3-accelerate.amazonaws.com/matic-mainnet/erigon-archive-snapshot-2023-01-12.tar.gz
wget --tries=0 -O - "${SNAPSHOT_URL}" | tar -xz -C ${ERIGON_HOME} && touch ${ERIGON_HOME}/bootstrapped
screen -X detach 



Download Heimdall snapshot

screen -S heimdall
HEIMDALL_HOME=$HOME/.local/share/heimdall/data
mkdir -p ${HEIMDALL_HOME}
SNAPSHOT_URL=https://matic-blockchain-snapshots.s3-accelerate.amazonaws.com/matic-mainnet/heimdall-snapshot-2023-01-17.tar.gz
wget --tries=0 -O - "${SNAPSHOT_URL}" | tar -xz -C ${HEIMDALL_HOME} && touch ${HEIMDALL_HOME}/bootstrapped
screen -X detach 



Clone Erigon and install

git clone -b v0.0.5 https://github.com/maticnetwork/erigon
cd erigon
make



Clone Heimdall and install

cd ~
git clone -b v0.3.0 https://github.com/maticnetwork/heimdall
cd heimdall
make build network=mainnet



Configure Heimdall

cd ~
/root/heimdall/build/heimdalld init --home /root/.local/share/heimdall/
wget -O /root/.local/share/heimdall/config/genesis.json https://raw.githubusercontent.com/maticnetwork/launch/master/mainnet-v1/without-sentry/heimdall/config/genesis.json
sed -i '/^seeds/c\seeds = "f4f605d60b8ffaaf15240564e58a81103510631c@159.203.9.164:26656,4fb1bc820088764a564d4f66bba1963d47d82329@44.232.55.71:26656,2eadba4be3ce47ac8db0a3538cb923b57b41c927@35.199.4.13:26656,3b23b20017a6f348d329c102ddc0088f0a10a444@35.221.13.28:26656,25f5f65a09c56e9f1d2d90618aa70cd358aa68da@35.230.116.151:26656"' /root/.local/share/heimdall/config/config.toml
sed -i "s#^cors_allowed_origins.*#cors_allowed_origins = [\"*\"]#" /root/.local/share/heimdall/config/config.toml



Create systemd files for Erigon, Heimdalld and Heimdallr

Erigon service file

#erigon service file
sudo echo "[Unit]
Description=Erigon Polygon Service
After=network.target
StartLimitIntervalSec=60
StartLimitBurst=3

[Service]
Type=simple
Restart=on-failure
RestartSec=5
TimeoutSec=900
User=root
Nice=0
LimitNOFILE=200000
WorkingDirectory=/root/.local/share/erigon/
ExecStart=/root/erigon/build/bin/erigon --chain="bor-mainnet" --datadir="/root/.local/share/erigon/datadir" --ethash.dagdir="/root/.local/share/erigon/datadir/ethash" --snapshots="true" --bor.heimdall="http://localhost:1317" --http --http.addr="0.0.0.0" --http.port="8545" --http.compression --http.vhosts="*" --http.corsdomain="*" --http.api="eth,debug,net,trace,web3,erigon,bor" --ws --ws.compression --rpc.gascap="300000000" --metrics --metrics.addr="0.0.0.0" --metrics.port="6969"
KillSignal=SIGHUP

[Install]
WantedBy=multi-user.target" >> /etc/systemd/system/erigon.service


Heimdalld service file

#heimdalld service file
sudo echo "[Unit]
Description=Heimdalld
After=network.target
StartLimitIntervalSec=60
StartLimitBurst=3

[Service]
Type=simple
Restart=on-failure
RestartSec=5
TimeoutSec=900
User=root
Nice=0
LimitNOFILE=200000
WorkingDirectory=/root/.local/share/heimdall/
ExecStart=/root/heimdall/build/heimdalld --home /root/.local/share/heimdall/ start
KillSignal=SIGHUP

[Install]
WantedBy=multi-user.target" >> /etc/systemd/system/heimdalld.service


Heimdallr service file

#heimdallr service file
sudo echo "[Unit]
Description=Heimdallr
After=network.target
StartLimitIntervalSec=60
StartLimitBurst=3

[Service]
Type=simple
Restart=on-failure
RestartSec=5
TimeoutSec=900
User=root
Nice=0
LimitNOFILE=200000
WorkingDirectory=/root/.local/share/heimdall/
ExecStart=/root/heimdall/build/heimdalld --home /root/.local/share/heimdall/ rest-server --chain-id=137
KillSignal=SIGHUP

[Install]
WantedBy=multi-user.target" >> /etc/systemd/system/heimdallr.service



Start heimdalld and heimdallr services

sudo systemctl daemon-reload
sudo systemctl enable heimdalld 
sudo systemctl enable heimdallr
sudo systemctl start heimdalld heimdallr



Check Heimdall status

sudo journalctl -fu heimdalld
#for logs
curl http://localhost:26657/status
#You should see "network": "heimdall-137" in the output, if you don’t something went wrong with the init and replacing the genesis.json file… anyway wait for it to say "catching_up": false



Start Erigon

#ONLY AFTER heimdall caught up to the chainhead, i.e. "catching_up": false in `curl http://localhost:26657/status` response
sudo systemctl enable erigon
sudo systemctl start erigon



Check Erigon status

sudo journalctl -fu erigon



Setup firewall

sudo apt install ufw
sudo ufw allow ssh && ufw enable
curl https://ipecho.net/plain ; echo
sudo ufw allow from <public_ip> to any port 8545



Setup monitoring

git clone https://github.com/StakeSquid/host-monitoring-docker
sudo ufw allow from <erigon_public_ip> to any port 6969
cd host-monitoring-docker
#edit .env file with your variables
nano .env
sudo bash start



Resources