Skip to content

Setup

This document serves as instructions for setting up a Webb Relayer at a publicly accessible endpoint. It will fulfill the requirements for listing your relayer on app.webb.tools. In order to integrate your relayer to app.webb.tools, please submit a PR. - Connections available via https and wss on your domain.

Instructions

These instructions will assume the user has created a cloud server on Ubuntu 20.04, and is logged into a user with sudo permissions.

By the end of these instructions, the relayer will be running and accessible via your endpoint with nginx behind a reverse proxy.

Basic Environment Setup

### Setup the machine's environment ###

# Update ubuntu packages
sudo apt update && sudo apt upgrade

# Update snap packages
sudo snap install core; sudo snap refresh core

# Install dependencies
sudo apt install gcc cmake pkg-config libssl-dev git clang libclang-dev
sudo apt install build-essential

# Install rust
curl https://sh.rustup.rs -sSf | sh -s -- -y
export PATH=~/.cargo/bin:$PATH
source ~/.cargo/env

# Install certbot
sudo snap install --classic certbot && sudo ln -s /snap/bin/certbot /usr/bin/certbot

Relayer setup

  1. Get the relayer code: git clone https://github.com/webb-tools/relayer.git

  2. Follow the README to create your config.toml for the networks you wish to support.

    Harmony example configuration
    port = 9955
    
    [evm.harmonytestnet1]
    http-endpoint = "https://api.s1.b.hmny.io"
    ws-endpoint = "wss://ws.s1.b.hmny.io"
    private-key = <PRIVATE_KEY_AS_HEX_STRING>
    chain-id = 1666700001
    
    [[evm.harmonytestnet1.contracts]]
    contract = "Anchor"
    address = "0x7cd1F52e5EEdf753e99D945276a725CE533AaD1a"
    deployed-at = 12040000
    size = 100
    events-watcher = { enabled = true, polling-interval = 3000 }
    withdraw-fee-percentage = 0.05
    withdraw-gaslimit = "0x350000"
    
    [[evm.harmonytestnet1.contracts]]
    contract = "Anchor"
    address = "0xD7f9BB9957100310aD397D2bA31771D939BD4731"
    deployed-at = 12892487
    size = 1000
    events-watcher = { enabled = true, polling-interval = 3000 }
    withdraw-fee-percentage = 0.03
    withdraw-gaslimit = "0x350000"
    
    [[evm.harmonytestnet1.contracts]]
    contract = "Anchor"
    address = "0xeE2eB8F142e48e5D1bDD34e0924Ed3B4aa0d4222"
    deployed-at = 12892648
    size = 10000
    events-watcher = { enabled = true, polling-interval = 3000 }
    withdraw-fee-percentage = 0.02
    withdraw-gaslimit = "0x350000"
    
    Full support example configuration
    port = 9955
    [substrate.webb]
    suri = "//Alice"
    
    [evm.beresheet]
    http-endpoint = "https://beresheet.edgewa.re/evm"
    ws-endpoint = "wss://beresheet1.edgewa.re"
    private-key = <PRIVATE_KEY_AS_HEX_STRING>
    chain-id = 2022
    
    [[evm.beresheet.contracts]]
    contract = "Anchor"
    address = "0xf0EA8Fa17daCF79434d10C51941D8Fc24515AbE3"
    deployed-at = 299740
    size = 10
    events-watcher = { enabled = true, polling-interval = 7000}
    withdraw-fee-percentage = 0.05
    withdraw-gaslimit = "0x350000"
    
    [[evm.beresheet.contracts]]
    contract = "Anchor"
    address = "0xc0d863EE313636F067dCF89e6ea904AD5f8DEC65"
    deployed-at = 299740
    size = 100
    events-watcher = { enabled = true, polling-interval = 7000}
    withdraw-fee-percentage = 0.05
    withdraw-gaslimit = "0x350000"
    
    [[evm.beresheet.contracts]]
    contract = "Anchor"
    address = "0xc7c6152214d0Db4e161Fa67fB62811Be7326834A"
    deployed-at = 299740
    size = 1000
    events-watcher = { enabled = true, polling-interval = 7000}
    withdraw-fee-percentage = 0.05
    withdraw-gaslimit = "0x350000"
    
    [[evm.beresheet.contracts]]
    contract = "Anchor"
    address = "0xf0290d80880E3c59512e454E303FcD48f431acA3"
    deployed-at = 299740
    size = 10000
    events-watcher = { enabled = true, polling-interval = 7000}
    withdraw-fee-percentage = 0.05
    withdraw-gaslimit = "0x350000"
    
    [evm.harmony]
    http-endpoint = "https://api.s1.b.hmny.io"
    ws-endpoint = "wss://ws.s1.b.hmny.io"
    private-key = <PRIVATE_KEY_AS_HEX_STRING>
    chain-id = 1666700001
    
    [[evm.harmony.contracts]]
    contract = "Anchor"
    address = "0x4c37863bf2642Ba4e8De7e746500C700540119E8"
    deployed-at = 13600000
    size = 0.0000000001
    events-watcher = { enabled = true, polling-interval = 3000 }
    withdraw-fee-percentage = 0.05
    withdraw-gaslimit = "0x350000"
    
    [[evm.harmony.contracts]]
    contract = "Anchor"
    address = "0x7cd1F52e5EEdf753e99D945276a725CE533AaD1a"
    deployed-at = 12040000
    size = 100
    events-watcher = { enabled = true, polling-interval = 3000 }
    withdraw-fee-percentage = 0.05
    withdraw-gaslimit = "0x350000"
    
    [[evm.harmony.contracts]]
    contract = "Anchor"
    address = "0xD7f9BB9957100310aD397D2bA31771D939BD4731"
    deployed-at = 12892487
    size = 1000
    events-watcher = { enabled = true, polling-interval = 3000 }
    withdraw-fee-percentage = 0.05
    withdraw-gaslimit = "0x350000"
    
    [[evm.harmony.contracts]]
    contract = "Anchor"
    address = "0xeE2eB8F142e48e5D1bDD34e0924Ed3B4aa0d4222"
    deployed-at = 12892648
    size = 10000
    events-watcher = { enabled = true, polling-interval = 3000 }
    withdraw-fee-percentage = 0.05
    withdraw-gaslimit = "0x350000"
    
    [evm.rinkeby]
    http-endpoint = "https://rinkeby.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161"
    ws-endpoint = "wss://rinkeby.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161"
    private-key = <PRIVATE_KEY_AS_HEX_STRING>
    chain-id = 4
    
    [[evm.rinkeby.contracts]]
    contract = "Anchor"
    address = "0x626FEc5Ffa7Bf1EE8CEd7daBdE545630473E3ABb"
    deployed-at = 8896800
    size = 0.1
    events-watcher = { enabled = true, polling-interval = 15000 }
    withdraw-fee-percentage = 0.05
    withdraw-gaslimit = "0x350000"
    
    [[evm.rinkeby.contracts]]
    contract = "Anchor"
    address = "0x979cBd4917e81447983ef87591B9E1ab21727a61"
    deployed-at = 8896800
    size = 1
    events-watcher = { enabled = true, polling-interval = 15000 }
    withdraw-fee-percentage = 0.05
    withdraw-gaslimit = "0x350000"
    
  3. Setup the relayer as a system service:

    # Create the service file
    sudo touch /etc/systemd/system/webb-relayer.service
    
    # This assumes a config.toml file has been setup in a config/ directory
    # and the repo has been cloned in the home directory of the user
    # Paste the following into the service file, and replace the <user>:
    
    [Unit]
    Description=WebbRelayer
    [Service]
    Type=exec
    WorkingDirectory=/home/<user>/relayer
    ExecStart=/home/<user>/relayer/target/release/webb-relayer -c /home/<user>/relayer/config/config.toml -vvv
    [Install]
    WantedBy=multi-user.target
    
  4. Kick off the system service:

    sudo systemctl enable webb-relayer && sudo systemctl start webb-relayer

Nginx Setup

  1. Configure your registered domain name with your cloud service provider.

  2. Install nginx if it isn't already on your machine: sudo apt install nginx

First, we will configure the endpoint linked to your at port 80 for certificate generation

  1. Create nginx site files for your domain: cd /etc/nginx/sites-available && sudo cp default <domain name> && sudo ln -s /etc/nginx/sites-available/<domain name> /etc/nginx/sites-enabled/

  2. Modify the nginx sites-available file to:

    server {
        listen 80;
        listen [::]:80;
    
        root /var/www/<domain name>/html;
        index index.html index.htm index.nginx-debian.html;
    
        server_name <domain name>;
    
        location / {
                try_files $uri $uri/ =404;
        }
    }
    
  3. Check the nginx configuration sudo nginx -t

  4. If no issues exist, restart the nginx service sudo systemctl restart nginx

Next we will create the self-signed certificate and reconfigure for https and wss support

  1. Create the self-signed certificate: sudo certbot certonly --nginx

  2. Modify the nginx site file:

    map $http_upgrade $connection_upgrade {
        default upgrade;
        '' close;
    }
    
    server {
    
        # SSL configuration
        #
        listen 443 ssl;
        listen [::]:443 ssl;
    
        root /var/www/<domain name>/html;
    
        server_name <domain name>;
        ssl_certificate /etc/letsencrypt/live/<domain name>/cert.pem;
        ssl_certificate_key /etc/letsencrypt/live/<domain name>/privkey.pem;
        ssl_session_timeout 5m;
        ssl_protocols SSLv2 SSLv3 TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers   HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers on;
    
        location / {
            proxy_pass http://127.0.0.1:9955;
            proxy_pass_request_headers on;
            proxy_http_version 1.1;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
        }
    }
    
  3. Check nginx configuration and restart.

Monitoring Setup

Relayers will want to setup monitoring to ensure maximum uptime and automatic restarts when things go awry.

  1. sudo apt install -y monit

  2. modify the monitrc file at: /etc/monit/monitrc

    set httpd port 2812 and
    use address localhost
    allow localhost
    
    set daemon 10
    set log /var/log/monit.log
    set idfile /var/lib/monit/id
    set statefile /var/lib/monit/state
    set eventqueue
      basedir /var/lib/monit/events
      slots 100
    
    check process webb-relayer matching target/release/webb-relayer
      start program = "/bin/systemctl restart webb-relayer"
      stop program = "/bin/systemctl kill webb-relayer"
      if cpu > 90% for 20 cycles then exec "/bin/systemctl stop webb-relayer" and repeat every 10 cycles
      if cpu > 90% for 64 cycles then exec "/bin/systemctl kill webb-relayer" and repeat every 10 cycles
      if cpu > 90% for 64 cycles then alert
      if does not exist for 1 cycles then start
    
  3. restart monit and validate: sudo monit reload && sudo monit validate