Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Manual script for setting up a GSNv1 relayer

Manual setup for a GSN relayer

⚠️ This setup is only good for GSNv1. Head over to https://docs.opengsn.org for the latest setup for GSNv2.

Install nginx and certbot

sudo add-apt-repository universe
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install nginx software-properties-common certbot python-certbot-nginx

Create app folder

sudo mkdir -p /app/bin
sudo mkdir -p /app/data
sudo chown -R ubuntu:ubuntu /app

Download relayer bin

curl 'https://github.com/OpenZeppelin/openzeppelin-gsn-helpers/releases/download/v0.1.4/gsn-relay-linux-amd64' -o /app/bin/RelayHttpServer -L -s
chmod a+x /app/bin/RelayHttpServer

Get certificate and cron it

sudo certbot certonly --nginx
sudo echo "/usr/bin/certbot renew --quiet" > /etc/cron.monthly/certbot

Config nginx

cd /etc/nginx
sudo rm sites-enabled/default

/etc/nginx/sites-available/relayer

log_format postdata escape=json '$remote_addr - $remote_user [$time_local] '
                        '"$request" $status $bytes_sent '
                        '"$http_referer" "$http_user_agent" "$request_body"';

server {
  listen 80;
  server_name example.com;
  
  location ~ /.well-known {
    root /var/www/html;
    allow all;
  }

  location / {
    return 301 https://$server_name$request_uri;
  } 
}

server {
  listen 443 ssl;
  server_name example.com;

  ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

  location / {
    access_log /var/log/nginx/access.log postdata;

    proxy_pass http://localhost:8091;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_cache_bypass $http_upgrade;
  }
}

Enable new site

cd sites-enabled
sudo ln -ns ../sites-available/relayer
sudo nginx -s reload

Setup environment

/app/env

URL=https://example.com
LOCAL_PORT=8091
WORKDIR=/app/data
NODE_URL=https://NETWORK.infura.io/v3/INFURATOKEN
RELAY_HUB=RELAY_HUB_ADDRESS
GAS_PRICE_PERCENT=0

Configure service on systemd

/etc/sytemd/system/relayer.service

[Unit]
Description=GSN relayer
StartLimitIntervalSec=300

[Service]
User=ubuntu
Group=ubuntu
Type=simple
WorkingDirectory=/app/
EnvironmentFile=/app/env
ExecStart=/app/bin/RelayHttpServer -Url ${URL} -Port ${LOCAL_PORT} -Workdir ${WORKDIR} -EthereumNodeUrl ${NODE_URL} -RelayHubAddress ${RELAY_HUB} -GasPricePercent ${GAS_PRICE_PERCENT}
StandardOutput=journal
StandardError=journal
Restart=on-failure
RestartSec=30
StartLimitBurst=5

[Install]
WantedBy=default.target

Start service

sudo systemctl daemon-reload
sudo systemctl enable relayer
sudo systemctl start relayer

Test it (from local workstation)

curl 'https://example.com/getaddr'

Fund it (from local workstation)

./scripts/fundrelay.js RELAY_HUB_ADDRESS 'https://example.com' 0 PROVIDER_URL
@ClarenceL

This comment has been minimized.

Copy link

@ClarenceL ClarenceL commented Mar 30, 2020

Thanks for this, only issue is I'm stuck trying to change the /app/env variables, after changing it how do I get systemctl to accept the new ones?

@spalladino

This comment has been minimized.

Copy link
Owner Author

@spalladino spalladino commented Mar 30, 2020

@ClarenceL if my memory serves me well, just by restarting the service with sudo systemctl restart relayer you should get the new ones. If it does not work, or if you need to reload a change in the config, I'd throw in an extra sudo systemctl daemon-reload before that, or even a full stop and start of the relayer service instead of a restart.

@ClarenceL

This comment has been minimized.

Copy link

@ClarenceL ClarenceL commented Apr 9, 2020

Does something occur where the gas price increases cumulatively as a percentage?

I set the GAS_PRICE_PERCENT to 2, most of my tests pass with a 1.02 Gwei gas price (I am using 1 Gwei as the base gas price), but suddenly somehow I am getting an error:

requires a minimum gas price of 1040400000 which is over this transaction gas price (1020000000)

Did it just do a cumulative 2% on top of 2%? How would this occur? Did I miss something in the docs?

Looking at the logs it goes from

Apr 09 17:30:17 ip-172-31-37-60 RelayHttpServer[1585]: 2020/04/09 17:30:17 RelayHttpServer.go:323: Relay funded. Balance: 3183087823550000000
Apr 09 17:30:17 ip-172-31-37-60 RelayHttpServer[1585]: 2020/04/09 17:30:17 RelayHttpServer.go:278: GasPrice: 1020000000
Apr 09 17:31:05 ip-172-31-37-60 RelayHttpServer[1585]: 2020/04/09 17:31:05 RelayHttpServer.go:107: Relay received gasPrice:: 1020000000
Apr 09 17:31:17 ip-172-31-37-60 RelayHttpServer[1585]: 2020/04/09 17:31:17 RelayHttpServer.go:323: Relay funded. Balance: 3182669993810000000
Apr 09 17:31:17 ip-172-31-37-60 RelayHttpServer[1585]: 2020/04/09 17:31:17 RelayHttpServer.go:278: GasPrice: 1040400000
@drortirosh

This comment has been minimized.

Copy link

@drortirosh drortirosh commented Nov 18, 2020

Note that this script is good for GSN v1 only.
The latest relayer setup documented in https://docs.opengsn.org, and its much simpler, as it uses docker to bring it up.

@spalladino

This comment has been minimized.

Copy link
Owner Author

@spalladino spalladino commented Nov 18, 2020

Just updated the gist to mention that it's for GSNv1, thanks Dror!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment