Skip to content

Instantly share code, notes, and snippets.

@nodeasy
Created March 23, 2022 03:20
Show Gist options
  • Save nodeasy/4fcc3fd47b1f6792a70c3d0c3b5e1061 to your computer and use it in GitHub Desktop.
Save nodeasy/4fcc3fd47b1f6792a70c3d0c3b5e1061 to your computer and use it in GitHub Desktop.

Agoric RPC node setup

1. Official websites

Related websites are listed here to save search time during node establishment

# Explorer
https://main.explorer.agoric.net/

# Docs
https://github.com/Agoric/agoric-sdk/wiki/Validator-Guide#agoric-mainnet-phase-0

# Archive url
no

# Other related websites
https://agoric.com/
https://commonwealth.im/agoric
https://validate.agoric.com/
https://agoric.com/discord

2. Setup RPC nodes

Here is a brief summary of the official document, which only involves RPC node setup

After setup finished, rpc port ip:26657

### Prerequisites
# Go Programming Language
# Newest version refers to: https://golang.org/dl/
name=go1.17.7.linux-amd64.tar.gz
wget https://dl.google.com/go/$name
tar -C /usr/local -xzf $name
rm -f $name
cat << EOF >> ~/.profile
# go
export GOPATH=/root/go
export PATH=/usr/local/go/bin:/root/go/bin:$PATH
EOF
source ~/.profile

# dasel (A software to quickly modify files, which will be used later)
curl -sSLf "$(curl -sSLf https://api.github.com/repos/tomwright/dasel/releases/latest | grep browser_download_url | grep linux_amd64 | cut -d\" -f 4)" -L -o dasel && chmod +x dasel
mv ./dasel /usr/local/bin/dasel

# Other prerequisites
apt-get update
apt-get install git make curl build-essential pkg-config


### Compiled source code
# There is no official bin file available, you can only compile it yourself
# Here is newest version
git clone https://github.com/Agoric/ag0.git -b  agoric-upgrade-5
cd ag0
make install
# After compiling, the executable file is at /root/go/bin/ag0, mopve it to /usr/local/bin/ag0
mv /root/go/bin/ag0 /usr/local/bin/ag0

### InitDir
# Download the configuration file, write the official current network information and seeds to the configuration file. Download the configuration file first to prepare for later  
curl https://main.agoric.net/network-config > chain.json
chainName=`jq -r .chainName < chain.json`
echo $chainName

# Configure the default chain-id first. No need to add the chain-id parameter in future transactions
ag0 config chain-id $chainName

# Initialize the configuration file, the default directory is /root/.agoric
ag0 init --chain-id $chainName Nodeasy.com-RPC
# Download official genesis file and replace
curl https://main.agoric.net/genesis.json > /root/.agoric/config/genesis.json 
# Edit the configuration file
echo $(jq '.peers | join(",")' < chain.json)
echo $(jq '.seeds | join(",")' < chain.json)
# Setup the name of the current node
dasel put string -f /node/full/agoric/config/config.toml "moniker" "name"
dasel put string -f /node/full/agoric/config/config.toml "log_level" "info"
# Change the RPC monitoring address to 0.0.0.0
dasel put string -f /node/full/agoric/config/config.toml "rpc.laddr" "tcp://0.0.0.0:26657"
dasel put string -f /node/full/agoric/config/config.toml "p2p.seeds" ""
# Add linked nodes, persistent_peers
dasel put string -f /node/full/agoric/config/config.toml "p2p.persistent_peers" "a26158a5cbb1df581dd6843ac427191af76d6d5d@104.154.240.50:26656,6e26a1b4afa6889f841d7957e8c2b5d50d32d485@95.216.53.26:26656"
# Set transaction fees accepted by nodes. Increasing base fees to reduce spam transactions helps network health  
dasel put string -f /node/full/agoric/config/app.toml "minimum-gas-prices" "0.000ubld"
dasel put string -f /node/full/agoric/config/app.toml "api.enable" false
# Enable the GRPC function and use the default port
dasel put string -f /node/full/agoric/config/app.toml "grpc.enable" true
dasel put string -f /node/full/agoric/config/app.toml "grpc-web.enable" false


# Use systemd to manage, add a Configuration File
# set the variable --x-crisis-skip-assert-invariants, to helps fast startup of servers with low hardware configurations
cat > /etc/systemd/system/agoric.service << EOF
[Unit]
Description=daemon
After=network-online.target

[Service]
User=root
ExecStart=/usr/local/bin/ag0 start --home /node/full/agoric/ --x-crisis-skip-assert-invariants
Restart=on-failure
RestartSec=5
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target
EOF

# Set startup to automatically start the service after the server restarts
systemctl enable agoric

# Start the service
systemctl start agoric


# Check service status, when catching_up is false, it means syncing is finished
ag0 status |jq ."SyncInfo.catching_up

3. Alarming configuration

In this case, Python is used to request the status of the local node to determine whether the status and block height are correct. The email alarm function can be extended later

Alternatively, enable Prometheus of Agoric and use Prometheus to monitor service status

#!/usr/bin/python3
import requests
import sys

# global
statusUrl = 'http://127.0.0.1:26657/status'

info = requests.get(url=statusUrl)
if info.status_code != 200:
    print('api_error')
    sys.exit()

status = info.json()
# check node status
if status['result']['sync_info']['catching_up'] != False:
    print('sync_error')
    sys.exit()

if status['result']['validator_info']['voting_power'] == "0":
    print('jailed')
    sys.exit()

print('0')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment